//22 March 2019
var ProffessionGame={};
var Utils={};
Utils.Path='';
Utils.mobileDeviceFlag=false;
ProffessionGame.uniqueArray=[]
ProffessionGame.questionArray=[];

var questionId=0,startTime=0,scoredMarks=0,totalMarks=10,resId=0,label='',firstQuestionTime=0;
$(document).ready(function()
{
	$(".se-pre-con").fadeOut("slow");
	if(navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))
		Utils.mobileDeviceFlag=true;
	
	/*   if(Utils.mobileDeviceFlag)
		Utils.Path=Android.getMediaPath("Text To Image");   */
	
	setTimeout(function()
	{
		/* if(ProffessionGame.hardcodedData['languageFont']!=null)
			setFontFamilyForLang("fonts/"+ProffessionGame.hardcodedData['languageFont']); */
		document.body.style.backgroundImage="url("+Utils.Path+"images/"+ProffessionGame.hardcodedData.coverImage+")";
		document.getElementById('coverpage').style.display="block";
		document.getElementById('gamepage').style.display="none";
		document.getElementById('soundDiv').style.visibility="hidden";
		document.getElementById('endpage').style.display='none';
		ProffessionGame.setImage();
		
	},200);
});
/* setFontFamilyForLang=function(fontFilePath){
  var newStyle = "<style>"+
            "@font-face {  "+
              "font-family: 'CustomFontFamily';"  +
                "src: url('"+fontFilePath+"') format('truetype');"+
                "}  </style>";
    $("head").append(newStyle);
    $("body").css("font-family","CustomFontFamily"); 
} */

ProffessionGame.playGame=function()
{
	//ProffessionGame.jsonAraay=ProffessionGame.gameData.slice();
	document.body.style.backgroundImage="url("+Utils.Path+"images/"+ProffessionGame.hardcodedData.bgImage+")";
	document.getElementById('playGame').style.display='none';
	document.getElementById('gamepage').style.display="block";
	document.getElementById('homeDiv').style.visibility="visible";
	document.getElementById('textDiv').style.visibility="visible";
	document.getElementById('imagePart').style.visibility="visible";
	document.getElementById('soundDiv').style.visibility="visible";
	document.getElementById('playAgain').src=Utils.Path+"images/replay.png";
	document.getElementById('credit').src=Utils.Path+"images/credits.png";
	ProffessionGame.jsonAraay=ProffessionGame.gameData.slice();
	//ProffessionGame.shuffleArray(ProffessionGame.jsonAraay);
	ProffessionGame.questionArray=ProffessionGame.gameData.slice();
shuffle(ProffessionGame.questionArray);
	ProffessionGame.getWord();
}
// set Images//
ProffessionGame.setImage=function()
{
	document.getElementById('logo').src=Utils.Path+"images/logo.png";
	document.getElementById('home').src=Utils.Path+"images/home.png";
	document.getElementById('play').src=Utils.Path+"images/play.png";
	document.getElementById('nextImg').src=Utils.Path+"images/Next.png";
	document.getElementById('soundImg').src=Utils.Path+"images/sound.png";
}
// get random 3 nodes //
ProffessionGame.getWord=function()
{
	var randomNumber=0;
	randomNumber=Math.floor(Math.random() * ProffessionGame.questionArray.length);
	ProffessionGame.uniqueArray.push(ProffessionGame.questionArray[randomNumber]);
	console.log(randomNumber)
	console.log(ProffessionGame.questionArray);
	ProffessionGame.questionArray.splice(randomNumber,1);
	for(var i=0;i<2;)
	{	
		randomNumber=Math.floor(Math.random() *ProffessionGame.gameData.length);
		while($.inArray(ProffessionGame.gameData[randomNumber],ProffessionGame.uniqueArray)!=-1)
		{
			randomNumber=Math.floor(Math.random() *ProffessionGame.gameData.length);
		}
		ProffessionGame.uniqueArray.push(ProffessionGame.gameData[randomNumber]);
		i++;
	}
	ProffessionGame.setText();
}
// set Quesion //

ProffessionGame.setText=function()
{
	var d=new Date();
	startTime=d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
	if(ProffessionGame.questionCnt == 1)
	firstQuestionTime=startTime;
	document.getElementById('paraDiv').innerHTML=ProffessionGame.uniqueArray[0].Use_text;
	document.getElementById('paraDiv').setAttribute('data',ProffessionGame.uniqueArray[0].Englishname);
	questionId=ProffessionGame.uniqueArray[0].questionId;
	ProffessionGame.soundString=ProffessionGame.uniqueArray[0].Use_audio;
	ProffessionGame.playSound();
	shuffle(ProffessionGame.uniqueArray);
	ProffessionGame.setOptions();
}
//play Sound Again
ProffessionGame.playSound=function()
{
	/* document.getElementById('playSound').src=Utils.Path+"sounds/"+ProffessionGame.soundString;
	document.getElementById('playSound').play(); */
}
// set Option
ProffessionGame.setOptions=function()
{
	for(var i=0;i<3;i++)
	{
		document.getElementById('imgOpt'+(i+1)).src=Utils.Path+"images/"+ProffessionGame.uniqueArray[i].imgName;
		document.getElementById('imgOpt'+(i+1)).setAttribute('optionData',ProffessionGame.uniqueArray[i].Englishname);
	}
	return 0;
}
//check Answer//
ProffessionGame.checkAns=function(obj)
{
	var clickedData,questionData;
//	document.getElementById('playSound').pause();
	ProffessionGame.attemptedCnt++;
	clickedData=document.getElementById(obj.id).getAttribute('optionData');
	questionData=document.getElementById('paraDiv').getAttribute('data');
	
	if(questionData == clickedData)
	{
		$(".pointerClass").css("pointer-events","none");
		document.getElementById('resultImg').src=Utils.Path+"images/correctImg.png";
		document.getElementById('resultDiv').style.display='block';
		ProffessionGame.nextQuestionTimeOut=setTimeout(function()
		{
			ProffessionGame.nextQuestion();
		},1800);
	}
	else
	{
		document.getElementById('resultDiv').style.display='block';
		document.getElementById('resultImg').src=Utils.Path+"images/wrong.png";
		$(obj).css("pointer-events","none");
	}
	
	imageTimeout=setTimeout(function()
	{
		document.getElementById('resultDiv').style.display='none';
	},800);
	
}
// show next Question //
ProffessionGame.nextQuestion=function()
{
	
	document.getElementById('resultDiv').style.display='none';
	$(".pointerClass").css("pointer-events","auto");
	$('#imagePart').removeClass('pointerCls');
	document.getElementById('playSound').pause();
	document.getElementById('resultDiv').style.display='none';
	if(ProffessionGame.nextQuestionTimeOut)
	{
		clearTimeout(ProffessionGame.nextQuestionTimeOut);
		ProffessionGame.nextQuestionTimeOut=null;
	}
	ProffessionGame.uniqueArray.length=0;
	ProffessionGame.getWord();
	
}