//startingDate:02-03-2020

var FractionTypes = {};
var Utils = {};
Utils.Path = '';
Utils.mobileDeviceFlag = false;

FractionTypes.questionCtr = 0;
FractionTypes.questionArr = [];
var questionId = 0, startTime = 0, scoredMarks = 0, totalMarks = 10, resId = 0, level = 1, label = '';

$(document).ready(function () {
	$(".se-pre-con").fadeOut("slow");
	if((navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) && !(window.location.href.includes('http')))
        Utils.mobileDeviceFlag = true;
	else
		Utils.mobileDeviceFlag=false;
	/* if(navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))
		Utils.mobileDeviceFlag = true;	*/
	/* if(Utils.mobileDeviceFlag) 
		Utils.Path=Android.getMediaPath("FractionTypes");  */
	setTimeout(function () {
		FractionTypes.init();
	}, 100);
});

FractionTypes.init = function () {
	$("#coverPage").show();
	$("#homeImage").hide();
	$("#gamePage").hide();
	$("#endPage").hide();
	document.title = FractionTypes.hardCodedData.NameOfGame;
	document.body.style.backgroundImage = "url('images/skin/coverPage.jpg')";
	FractionTypes.createAcknowledgementDivs();
	FractionTypes.createOptionDiv();
	FractionTypes.initializeVariables();
	FractionTypes.setAllImages();
}

FractionTypes.initializeVariables = function ()
{
    FractionTypes.correctCtr = 0;
	FractionTypes.randQuestion = 0;
	FractionTypes.ansArr = [];
	FractionTypes.corrArr = [];
    FractionTypes.wrongArr = [];
	FractionTypes.optionArr = [];
	FractionTypes.likeOptionArr = [];
	FractionTypes.unlikeOptionArr = [];
    FractionTypes.scoreFlag = false;
    FractionTypes.attemptFlag = false;
    FractionTypes.firstAttemptFlag = true;
	FractionTypes.mixedFractionFlag = false;
	FractionTypes.likeFractionFlag = false;
	FractionTypes.unlikeFractionFlag = false;
	FractionTypes.correctQueTimer = null;
	FractionTypes.wrongQuestionTimer = null;
}

FractionTypes.setAllImages = function () {
	document.getElementById("homeImage").src = Utils.Path + "images/skin/Home.png";
	document.getElementById("logoImage").src = Utils.Path + "images/skin/logo.png";
	document.getElementById("playImage").src = Utils.Path + "images/skin/Play.png";
	document.getElementById("soundImage").src = Utils.Path + "images/skin/sound.png";
	document.getElementById("nextImage").src = Utils.Path + "images/skin/Next.png";
	document.getElementById("creditImg").src = Utils.Path + "images/skin/credits.png";
	document.getElementById("playAgainImage").src = Utils.Path + "images/skin/Replay.png";
	document.getElementById("boardImg").src = Utils.Path + "images/skin/board.png";
	document.getElementById("gameOverTextDiv").innerHTML = FractionTypes.hardCodedData.gameOver;
}

FractionTypes.playGame = function () {
	$("#coverPage").hide();
	$("#homeImage").show();
	$("#gamePage").show();
	document.body.style.backgroundImage = "url('images/skin/BG.png')";
	FractionTypes.callSound();
	FractionTypes.setQuestion();
}

FractionTypes.setQuestion = function () 
{
	var rno = 0, num, optionFlag = false, tempArr = [], optionArray = [], wholeNoArr = [];
	FractionTypes.questionCtr++;
	document.getElementById("henImg").src = Utils.Path + "images/skin/Hen.png";
	d = new Date();
	startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();

	FractionTypes.randQuestion = Math.floor(Math.random() * FractionTypes.questions.length);
	while (FractionTypes.questionArr.includes(FractionTypes.randQuestion))
		FractionTypes.randQuestion = Math.floor(Math.random() * FractionTypes.questions.length);
	FractionTypes.questionArr.push(FractionTypes.randQuestion);
	//console.log(FractionTypes.questionArr);
	document.getElementById("questionDiv").innerHTML = FractionTypes.questions[FractionTypes.randQuestion].hindi;

	rno = 1;									//For only one correct option
	//rno = Math.ceil(Math.random() * 3);		//For random no of correct option
	//FractionTypes.randQuestion = 5;
	switch (FractionTypes.randQuestion) {
		//Unit Fractions
		case 0: {
			num2Arr = [];
			for (i = 0; i < rno; i++) {			//For Correct option.
				num1 = 1;
				num2 = (Math.floor(Math.random() * 9) + 1);
				while (num2Arr.includes(num2) || num2 == 1)
					num2 = (Math.floor(Math.random() * 9) + 1);
				num = (num1 + "/" + num2);
				num2Arr.push(num2);
				optionArray.push(num1);
				optionArray.push(num2);
				FractionTypes.corrArr.push(num);
				FractionTypes.ansArr.push(num);
				FractionTypes.optionArr.push(optionArray);
				optionArray = [];
			}
			for (i = 0; i < (4 - rno); i++) {		//For Wrong option.
				wrongNum1 = Math.floor(Math.random() * 9) + 1;
				wrongNum2 = Math.floor(Math.random() * 9) + 1;
				wrongNum = (wrongNum1 + "/" + wrongNum2);
				while (FractionTypes.wrongArr.includes(wrongNum) || wrongNum1 == 1 || wrongNum2 == 1) {
					wrongNum1 = Math.floor(Math.random() * 9) + 1;
					wrongNum2 = Math.floor(Math.random() * 9) + 1;
					wrongNum = (wrongNum1 + "/" + wrongNum2);
				}
				optionArray.push(wrongNum1);
				optionArray.push(wrongNum2);
				FractionTypes.wrongArr.push(wrongNum);
				FractionTypes.ansArr.push(wrongNum);
				FractionTypes.optionArr.push(optionArray);
				optionArray = [];
			}
			FractionTypes.shuffleArray(FractionTypes.optionArr);
		} break;
		//Proper Fractions
		case 1: {
			num2Arr = [];
			corrFlag = false;
			wrongFlag = false;
			for (i = 0; i < rno; i++)	//For correct fraction.
			{
				num1 = (Math.floor(Math.random() * 8) + 1);		// 8: If num1==9 then 9! >= num2.
				num2 = (Math.floor(Math.random() * 9) + 1);
				if(num1 >= num2){
					optionFlag = true;
					num = (num2 + "/" + num1); 
				}	
				else	
					num = (num1 + "/" + num2);
				while(FractionTypes.corrArr.includes(num))
				{
					num1 = (Math.floor(Math.random() * 8) + 1);		// 8: If num1==9 then 9! >= num2.
					num2 = (Math.floor(Math.random() * 9) + 1);
					if(num1 >= num2){
						optionFlag = true;
						num = (num2 + "/" + num1);
					}	
					else	
						num = (num1 + "/" + num2);
				}	
				num2Arr.push(num2);
				corrFlag = true;
				if(optionFlag){
					optionArray.push(num2);
					optionArray.push(num1);
				}
				else{
					optionArray.push(num1);
					optionArray.push(num2);
				}
				FractionTypes.corrArr.push(num);
				FractionTypes.ansArr.push(num);
				FractionTypes.optionArr.push(optionArray);
				optionFlag = false;
				optionArray = [];
			}	
			for (i = 0; i < (4-rno); i++)	//For wrong fraction.
			{
				wrongNum1 = (Math.floor(Math.random() * 8) + 2);
				wrongNum2 = (Math.floor(Math.random() * 9) + 2);
				wrongNum = (wrongNum1 + "/" + wrongNum2);
				while (FractionTypes.wrongArr.includes(wrongNum) || FractionTypes.corrArr.includes(wrongNum) || wrongNum1 <= wrongNum2)
				{
					wrongNum1 = (Math.floor(Math.random() * 8) + 2);
					wrongNum2 = (Math.floor(Math.random() * 9) + 2);
					wrongNum = (wrongNum1 + "/" + wrongNum2);
				}
				wrongFlag = true;
				optionArray.push(wrongNum1);
				optionArray.push(wrongNum2);
				FractionTypes.wrongArr.push(wrongNum);
				FractionTypes.ansArr.push(wrongNum);
				FractionTypes.optionArr.push(optionArray);
				optionArray = [];
			}	
		/* 	if (FractionTypes.randQuestion == 2) {		//For Improper fraction.
				tempArr = FractionTypes.corrArr.slice(0);
				FractionTypes.corrArr = FractionTypes.wrongArr.slice(0);
				FractionTypes.wrongArr = tempArr.slice(0);
			} */
			FractionTypes.shuffleArray(FractionTypes.optionArr);
		} break;
		//Improper Fractions
		case 2: {
			num2Arr = [];
			corrFlag = false;
			wrongFlag = false;
			for (i = 0; i < (4-rno); i++)	//For wrong fraction.
			{
				num1 = (Math.floor(Math.random() * 8) + 1);		//8: If num1==9 then 9! >= num2.
				num2 = (Math.floor(Math.random() * 9) + 1);
				if(num1 >= num2){
					optionFlag = true;
					num = (num2 + "/" + num1);
				}	
				else	
					num = (num1 + "/" + num2);
				while(FractionTypes.wrongArr.includes(num))
				{
					num1 = (Math.floor(Math.random() * 8) + 1);	//8: If num1==9 then 9! >= num2.
					num2 = (Math.floor(Math.random() * 9) + 1);
					if(num1 >= num2){
						optionFlag = true;
						num = (num2 + "/" + num1);
					}	
					else	
						num = (num1 + "/" + num2);
				}	
				num2Arr.push(num2);
				corrFlag = true;
				if(optionFlag){
					optionArray.push(num2);
					optionArray.push(num1);
				}
				else{
					optionArray.push(num1);
					optionArray.push(num2);
				}
				FractionTypes.wrongArr.push(num);
				FractionTypes.ansArr.push(num);
				FractionTypes.optionArr.push(optionArray);
				optionFlag = false;
				optionArray = [];
			}	
			for (i = 0; i < (rno); i++)		//For correct fraction.
			{
				wrongNum1 = (Math.floor(Math.random() * 8) + 2);
				wrongNum2 = (Math.floor(Math.random() * 9) + 2);
				wrongNum = (wrongNum1 + "/" + wrongNum2);
				while (FractionTypes.wrongArr.includes(wrongNum) || FractionTypes.corrArr.includes(wrongNum) || wrongNum1 <= wrongNum2)
				{
					wrongNum1 = (Math.floor(Math.random() * 8) + 2);
					wrongNum2 = (Math.floor(Math.random() * 9) + 2);
					wrongNum = (wrongNum1 + "/" + wrongNum2);
				}
				wrongFlag = true;
				optionArray.push(wrongNum1);
				optionArray.push(wrongNum2);
				FractionTypes.corrArr.push(wrongNum);
				FractionTypes.ansArr.push(wrongNum);
				FractionTypes.optionArr.push(optionArray);
				optionArray = [];
			}	
			FractionTypes.shuffleArray(FractionTypes.optionArr);	
		} break;
		//Mixed Fractions
		case 3: {
			num2Arr = [];
			corrFlag = false;
			wrongFlag = false;
			FractionTypes.mixedFractionFlag = true;
			for (i = 0; i < rno; i++)	//For correct fraction.
			{
				wholeNo = (Math.floor(Math.random() * 9) + 1);
				num1 = (Math.floor(Math.random() * 8) + 1);		// 8: If num1==9 then 9! >= num2.
				num2 = (Math.floor(Math.random() * 9) + 1);
				while(num1 == num2){
					num1 = (Math.floor(Math.random() * 8) + 1);		// 8: If num1==9 then 9! >= num2.
					num2 = (Math.floor(Math.random() * 9) + 1);
				}
				if(num1 > num2){
					optionFlag = true;
					num = wholeNo+" "+(num2 + "/" + num1);
				}	
				else	
					num = wholeNo+" "+(num1 + "/" + num2);
				/* while(FractionTypes.corrArr.includes(num))		//For more than one correct option
				{
					num1 = (Math.floor(Math.random() * 8) + 1);		// 8: If num1==9 then 9! >= num2.
					num2 = (Math.floor(Math.random() * 9) + 1);
					if(num1 >= num2){
						optionFlag = true;
						num = (num2 + "/" + num1);
					}	
					else	
						num = (num1 + "/" + num2);
				} */
				num2Arr.push(num2);
				corrFlag = true;
				if(optionFlag){
					optionArray.push(num2);
					optionArray.push(num1);
				}
				else{
					optionArray.push(num1);
					optionArray.push(num2);
				}
				wholeNoArr.push(wholeNo);
				FractionTypes.corrArr.push(num);
				FractionTypes.ansArr.push(num);
				FractionTypes.optionArr.push(optionArray);
				optionFlag = false;
				optionArray = [];
			}	
			for (i = 0; i < (4-rno); i++)	//For wrong fraction.
			{
				//wholeNo = (Math.floor(Math.random() * 9) + 1);
				wrongNum1 = (Math.floor(Math.random() * 8) + 2);
				wrongNum2 = (Math.floor(Math.random() * 9) + 2);
				//wrongNum = wholeNo+" "+(wrongNum1 + "/" + wrongNum2);
				wrongNum = wrongNum1 + "/" + wrongNum2;
				while (FractionTypes.wrongArr.includes(wrongNum) || FractionTypes.corrArr.includes(wrongNum) || wrongNum1 <= wrongNum2)
				{
					wrongNum1 = (Math.floor(Math.random() * 8) + 2);
					wrongNum2 = (Math.floor(Math.random() * 9) + 2);
					//wrongNum = wholeNo+" "+(wrongNum1 + "/" + wrongNum2);
					wrongNum = wrongNum1 + "/" + wrongNum2;
				}
				wrongFlag = true;
				//wholeNoArr.push(wholeNo);
				optionArray.push(wrongNum1);
				optionArray.push(wrongNum2);
				FractionTypes.wrongArr.push(wrongNum);
				FractionTypes.ansArr.push(wrongNum);
				FractionTypes.optionArr.push(optionArray);
				optionArray = [];
			}
			//FractionTypes.shuffleArray(FractionTypes.optionArr);		//Don't shuffle this fraction array bcoz pairs will get shuffled & it will give wrong answer
		}break;	
		//For like Fractions
		case 4:{
			num1Arr = [];
			num2Arr = [];
			likeNum1Arr = [];
			likeOptionArray = [];
			corrFlag = false;
			wrongFlag = false;
			FractionTypes.likeFractionFlag = true;
			//rno = Math.ceil(Math.random() * 2) + 1;		//rno != 1
 			//console.log(rno);	
			num2 = (Math.floor(Math.random() * 9) + 1);
			if(num2 == 1)
				num2 = num2 + 1;
			for (i = 0; i < rno; i++)	//For correct like fraction.
			{
				num1 = (Math.floor(Math.random() * 9) + 1);
				while (num1Arr.includes(num1) || num1 == num2)
					num1 = (Math.floor(Math.random() * 9) + 1);
				num1Arr.push(num1);		
				//num = (num1 + "/" + num2);
				corrFlag = true;
				num2Arr.push(num2);
				optionArray.push(num1);
				optionArray.push(num2);
				FractionTypes.optionArr.push(optionArray);
				
				optionArray = [];
				likeNum1 = (Math.floor(Math.random() * 9) + 1);
				while (likeNum1Arr.includes(likeNum1) || likeNum1 == num2)
					likeNum1 = (Math.floor(Math.random() * 9) + 1);
				likeNum1Arr.push(likeNum1);	
				num = (num1 + "/" + num2)+" "+(likeNum1 + "/" + num2);
				optionArray.push(likeNum1);
				optionArray.push(num2);
				FractionTypes.optionArr.push(optionArray);
				FractionTypes.corrArr.push(num);
				FractionTypes.ansArr.push(num);
				FractionTypes.likeOptionArr.push(FractionTypes.optionArr);
				
				optionArray = [];
				FractionTypes.optionArr = [];
			}	
			for (i = 0; i < (4-rno); i++)	//For wrong like fraction.
			{
				wrongFlag = true;
				wrongNum1 = (Math.floor(Math.random() * 9) + 1);
				wrongNum2 = (Math.floor(Math.random() * 8) + 2);
				while (num2Arr.includes(wrongNum2))
					wrongNum2 = (Math.floor(Math.random() * 8) + 2);
				wrongNum = (wrongNum1 + "/" + wrongNum2);
				num2Arr.push(wrongNum2);
				optionArray.push(wrongNum1);
				optionArray.push(wrongNum2);
				FractionTypes.optionArr.push(optionArray);
				
				optionArray = [];
				likeWrongNum1 = (Math.floor(Math.random() * 9) + 1);		//For second wrong number (3/4).
				likeWrongNum2 = (Math.floor(Math.random() * 8) + 2);
				while (num2Arr.includes(likeWrongNum2))
					likeWrongNum2 = (Math.floor(Math.random() * 8) + 2);
				num2Arr.push(likeWrongNum2);

				wrongNum = (wrongNum1 + "/" + wrongNum2)+" "+(likeWrongNum1 + "/" + likeWrongNum2);
				optionArray.push(likeNum1);
				optionArray.push(num2);
				FractionTypes.optionArr.push(optionArray);
				FractionTypes.wrongArr.push(wrongNum);
				FractionTypes.ansArr.push(wrongNum);
				FractionTypes.likeOptionArr.push(FractionTypes.optionArr);
				
				optionArray = [];
				FractionTypes.optionArr = [];
			}	
			FractionTypes.shuffleArray(FractionTypes.likeOptionArr);		
		}break;	
		//For Unlike Fraction
		case 5:{
			num1Arr = [];
			num2Arr = [];
			unlikeNum1Arr = [];
			corrFlag = false;
			wrongFlag = false;
			FractionTypes.unlikeFractionFlag = true;
			//rno = Math.ceil(Math.random() * 2) + 1;		//rno != 1
 			//console.log(rno);	
			num2 = (Math.floor(Math.random() * 9) + 1);
			if(num2 == 1)
				num2 = num2 + 1;
			for (i = 0; i < (4-rno); i++)	//For wrong Unlike fraction.
			{
				num1 = (Math.floor(Math.random() * 9) + 1);
				while (num1Arr.includes(num1) || num1 == num2)
					num1 = (Math.floor(Math.random() * 9) + 1);
				num1Arr.push(num1);		
				//num = (num1 + "/" + num2);
				corrFlag = true;
				num2Arr.push(num2);
				optionArray.push(num1);
				optionArray.push(num2);
				FractionTypes.optionArr.push(optionArray);

				optionArray = [];
				unlikeNum1 = (Math.floor(Math.random() * 9) + 1);
				while (unlikeNum1Arr.includes(unlikeNum1) || unlikeNum1 == num2)
					unlikeNum1 = (Math.floor(Math.random() * 9) + 1);
				unlikeNum1Arr.push(unlikeNum1);	
				//num = (num1 + "/" + num2);
				num = (num1 + "/" + num2)+" "+(unlikeNum1 + "/" + num2);
				optionArray.push(unlikeNum1);
				optionArray.push(num2);
				FractionTypes.optionArr.push(optionArray);
				FractionTypes.corrArr.push(num);
				FractionTypes.ansArr.push(num);
				FractionTypes.unlikeOptionArr.push(FractionTypes.optionArr);

				optionArray = [];
				FractionTypes.optionArr = [];
			}	
			for (i = 0; i < rno; i++)	//For correct Unlike fraction.
			{
				wrongFlag = true;									//For first wrong number (1/2)
				wrongNum1 = (Math.floor(Math.random() * 9) + 1);
				wrongNum2 = (Math.floor(Math.random() * 8) + 2);
				while (num2Arr.includes(wrongNum2))
					wrongNum2 = (Math.floor(Math.random() * 8) + 2);
				//wrongNum = (wrongNum1 + "/" + wrongNum2);
				num2Arr.push(wrongNum2);
				optionArray.push(wrongNum1);
				optionArray.push(wrongNum2);
				FractionTypes.optionArr.push(optionArray);

				optionArray = [];
				unlikeWrongNum1 = (Math.floor(Math.random() * 9) + 1);		//For second wrong number (3/4).
				unlikeWrongNum2 = (Math.floor(Math.random() * 8) + 2);
				while (num2Arr.includes(unlikeWrongNum2))
					unlikeWrongNum2 = (Math.floor(Math.random() * 8) + 2);
				num2Arr.push(unlikeWrongNum2);

				wrongNum = (wrongNum1 + "/" + wrongNum2)+" "+(unlikeWrongNum1 + "/" + unlikeWrongNum2);
				optionArray.push(unlikeWrongNum1);
				optionArray.push(unlikeWrongNum2);
				FractionTypes.optionArr.push(optionArray);
				FractionTypes.wrongArr.push(wrongNum);
				FractionTypes.ansArr.push(wrongNum);
				FractionTypes.unlikeOptionArr.push(FractionTypes.optionArr);

				optionArray = [];
				FractionTypes.optionArr = [];
			}	
			if (FractionTypes.randQuestion == 5) {		//For Unlike fraction.
				tempArr = FractionTypes.corrArr.slice(0);
				FractionTypes.corrArr = FractionTypes.wrongArr.slice(0);
				FractionTypes.wrongArr = tempArr.slice(0);
			} 
			FractionTypes.shuffleArray(FractionTypes.unlikeOptionArr);
	}break;
	}
	console.log('FractionTypes.corrArr');
	console.log(FractionTypes.corrArr);
	console.log('FractionTypes.wrongArr');
	console.log(FractionTypes.wrongArr);
	console.log('FractionTypes.ansArr');
	console.log(FractionTypes.ansArr);
	console.log("FractionTypes.optionArr");
	console.log(FractionTypes.optionArr); 
	console.log('FractionTypes.likeOptionArr');
	console.log(FractionTypes.likeOptionArr);
	console.log('FractionTypes.unlikeOptionArr');
	console.log(FractionTypes.unlikeOptionArr); 
	for (var i = 1; i <= 4; i++) 
	{
		if(wholeNoArr.length != 0){							//For Mixed Fraction.
			document.getElementById('wholeNoDiv'+i).innerHTML = wholeNoArr[0];
			wholeNoArr.splice(0,1);
			/* console.log('wholeNoArr');	
			console.log(wholeNoArr); */
			document.getElementById('numerator'+i).innerHTML = FractionTypes.optionArr[i-1][0];
			document.getElementById('denominator'+i).innerHTML = FractionTypes.optionArr[i-1][1]; 
		}
		else if(FractionTypes.likeOptionArr.length != 0){		//For like Fraction.
			document.getElementById('coumaDiv'+i).innerHTML = FractionTypes.hardCodedData.unlikeCouma;
			document.getElementById('numerator'+i).innerHTML = FractionTypes.likeOptionArr[i-1][0][0];
			document.getElementById('denominator'+i).innerHTML = FractionTypes.likeOptionArr[i-1][0][1];
			document.getElementById('unlikeNumerator'+i).innerHTML = FractionTypes.likeOptionArr[i-1][1][0];
			document.getElementById('unlikeDenominator'+i).innerHTML = FractionTypes.likeOptionArr[i-1][1][1];
			document.getElementById('numerator'+i).classList.add('unlikeFractionNum1');
			document.getElementById('denominator'+i).classList.add('unlikeFractionNum1');
			document.getElementById('unlikeNumerator'+i).classList.add('borderBottom');
			document.getElementById('unlikeNumerator'+i).style.color = "black";
			document.getElementById('unlikeDenominator'+i).style.color = "black";
		}
		else if(FractionTypes.unlikeOptionArr.length != 0){		//For Unlike Fraction.
			document.getElementById('coumaDiv'+i).innerHTML = FractionTypes.hardCodedData.unlikeCouma;
			document.getElementById('numerator'+i).innerHTML = FractionTypes.unlikeOptionArr[i-1][0][0];
			document.getElementById('denominator'+i).innerHTML = FractionTypes.unlikeOptionArr[i-1][0][1];
			document.getElementById('unlikeNumerator'+i).innerHTML = FractionTypes.unlikeOptionArr[i-1][1][0];
			document.getElementById('unlikeDenominator'+i).innerHTML = FractionTypes.unlikeOptionArr[i-1][1][1];
			document.getElementById('numerator'+i).classList.add('unlikeFractionNum1');
			document.getElementById('denominator'+i).classList.add('unlikeFractionNum1');
			document.getElementById('unlikeNumerator'+i).classList.add('borderBottom');
			document.getElementById('unlikeNumerator'+i).style.color = "black";
			document.getElementById('unlikeDenominator'+i).style.color = "black";
		}
		else{
			document.getElementById('numerator'+i).innerHTML = FractionTypes.optionArr[i-1][0];
			document.getElementById('denominator'+i).innerHTML = FractionTypes.optionArr[i-1][1]; 
		}
		document.getElementById('numerator'+i).style.color = "black";
		document.getElementById('denominator'+i).style.color = "black";
	}
	$(".EggCss").css("pointer-events", "auto");
}

FractionTypes.createOptionDiv = function()			//Create option Div according to answer.
{
	var i=0, j=0, k=1, parentDiv, numeratorDiv, denominatorDiv;
	for(i=1; i<=2; i++)
	{
		parentDiv = document.getElementById('optionInnerDiv'+i);
		for(j=1; j<=2; j++){
			div = document.createElement('div');
			$(div).prop('id','Egg'+k);
			$(div).prop('class','nopadding EggCss col-sm-5 col-md-5 col-lg-5 col-sm-5');
			div.setAttribute('onclick',"FractionTypes.checkAnswer(this.id);");
			parentDiv.appendChild(div);
			document.getElementById('Egg'+k).style.backgroundImage = "url('images/skin/Egg.png')";	
			k++;
		}
	}	
	for(i=1; i<=4; i++)
	{
		parentDiv = document.getElementById('Egg'+i);	
		
		optionDiv = document.createElement('div');
		$(optionDiv).prop('id','optionDiv'+i);
		$(optionDiv).prop('class','nopadding option col-xs-3 col-md-3 col-lg-3 col-sm-3 col-xs-offset-5 col-md-offset-5 col-lg-offset-5 col-sm-offset-5');
		parentDiv.appendChild(optionDiv);
	
		wholeNoDiv = document.createElement("div");			//For Mixed fraction.
		$(wholeNoDiv).prop("id",'wholeNoDiv'+i);
		$(wholeNoDiv).prop('class','nopadding wholeNoDivCss col-xs-1 col-md-1 col-lg-1 col-sm-1');
		optionDiv.appendChild(wholeNoDiv);

		outerDivNum1 = document.createElement("div");
		$(outerDivNum1).prop("id",'outerDivNum1'+i);
		$(outerDivNum1).prop('class','nopadding outerDivCss col-xs-5 col-md-5 col-lg-5 col-sm-5');
		optionDiv.appendChild(outerDivNum1);
		
		numeratorDiv = document.createElement("div");		//numerator1
		$(numeratorDiv).prop("id",'numerator'+i);
		$(numeratorDiv).prop('class','nopadding borderBottom col-xs-12 col-md-12 col-lg-12 col-sm-12');
		outerDivNum1.appendChild(numeratorDiv);
		
		denominatorDiv = document.createElement('div');		//denominator1
		$(denominatorDiv).prop('id','denominator'+i);
		$(denominatorDiv).prop('class','nopadding col-xs-12 col-md-12 col-lg-12 col-sm-12');
		outerDivNum1.appendChild(denominatorDiv);

		coumaDiv = document.createElement("div");	//Couma for Unlike & like fraction.
		$(coumaDiv).prop("id",'coumaDiv'+i);
		$(coumaDiv).prop('class','nopadding coumaDivCss col-xs-1 col-md-1 col-lg-1 col-sm-1');
		optionDiv.appendChild(coumaDiv);

		outerDivNum2 = document.createElement("div");	//For like & Unlike Fraction.
		$(outerDivNum2).prop("id",'outerDivNum2'+i);
		$(outerDivNum2).prop('class','nopadding col-xs-5 col-md-5 col-lg-5 col-sm-5');
		optionDiv.appendChild(outerDivNum2);

		numeratorDiv = document.createElement("div");	//For like &  Unlike Fraction numerator2.
		$(numeratorDiv).prop("id",'unlikeNumerator'+i);
		$(numeratorDiv).prop('class','nopadding unlikeFraction col-xs-12 col-md-12 col-lg-12 col-sm-12');
		outerDivNum2.appendChild(numeratorDiv);
		
		denominatorDiv = document.createElement('div');	//For like &  Unlike Fraction denominator2.
		$(denominatorDiv).prop('id','unlikeDenominator'+i);
		$(denominatorDiv).prop('class','nopadding unlikeFraction col-xs-12 col-md-12 col-lg-12 col-sm-12');
		outerDivNum2.appendChild(denominatorDiv);
	}
}

FractionTypes.shuffleArray = function(ansArray)
{
	var tempvalue, shuffle_no;
	var currentIndex = (ansArray.length)-1;
	
	while(currentIndex != 0)	
	{	
		shuffle_no = Math.floor(Math.random() * ansArray.length);
		
		tempvalue = ansArray[currentIndex];
		ansArray[currentIndex] = ansArray[shuffle_no];
		ansArray[shuffle_no] = tempvalue;
		currentIndex-=1;
	} 
}
 
FractionTypes.checkAnswer = function (divId) 
{
	var randomHenImg = '';
	FractionTypes.attemptFlag = true;

	if(FractionTypes.mixedFractionFlag){				//For Mixed Fraction.
		var number1 = document.getElementById(divId).children[0].children[0].innerHTML;					//divId = Egg + optionDiv + wholeNo
		var number2 = document.getElementById(divId).children[0].children[1].children[0].innerHTML;		//divId = Egg + optionDiv + (numerator/denominator)
		var number3 = document.getElementById(divId).children[0].children[1].children[1].innerHTML;
		number = number1+" "+(number2 + "/" +number3);
	}
	if(FractionTypes.unlikeFractionFlag || FractionTypes.likeFractionFlag){				//For Unlike Fraciton.
		var number1 = document.getElementById(divId).children[0].children[1].children[0].innerHTML;
		var number2 = document.getElementById(divId).children[0].children[1].children[1].innerHTML;
		var number3 = document.getElementById(divId).children[0].children[3].children[0].innerHTML;
		var number4 = document.getElementById(divId).children[0].children[3].children[1].innerHTML;
		number = (number1 + "/" + number2)+" "+(number3 + "/" + number4);
	}
	if(!FractionTypes.mixedFractionFlag && !FractionTypes.unlikeFractionFlag && !FractionTypes.likeFractionFlag)	//For Other Fraction.
	{
		var number2 = document.getElementById(divId).children[0].children[1].children[0].innerHTML;
		var number3 = document.getElementById(divId).children[0].children[1].children[1].innerHTML;
		number = number2 + "/" +number3;
	}
	if (FractionTypes.corrArr.includes(number)) 			//For correct answer.
	{
		FractionTypes.correctCtr++;
		document.getElementById(divId).classList.add('flash');
		document.getElementById(divId).style.pointerEvents = "none";
		/* if(FractionTypes.correctCtr <= FractionTypes.corrArr.length-1){		//For multiple correct options.
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/Buzzercorrect.mp3";
			document.getElementById("playSound").play();
		} */
		if (FractionTypes.correctCtr == FractionTypes.corrArr.length) 
		{
			$(".EggCss").css("pointer-events", "none");
			$("#soundImage").css("pointer-events", "none");	
			randomHenImg = Math.floor(Math.random() * FractionTypes.correctImgs.length);
			document.getElementById("henImg").src = Utils.Path + "images/skin/"+FractionTypes.correctImgs[randomHenImg];
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/thats_right.mp3";
			document.getElementById("playSound").play();
			if (FractionTypes.firstAttemptFlag){
				scoredMarks = 10;
			}
			if(FractionTypes.correctQueTimer){
				clearTimeout(FractionTypes.correctQueTimer);
				FractionTypes.correctQueTimer = null;
			} 
			FractionTypes.correctQueTimer = setTimeout(function () {
				$("#soundImage").css("pointer-events", "auto");
				document.getElementById(divId).classList.remove("flash");
				document.getElementById("henImg").src = Utils.Path + "images/skin/Hen.png";	
				FractionTypes.nextQuestion();
			},1500);
		}
	}
	else {					//For wrong answer.
		scoredMarks = 0;				
		FractionTypes.firstAttemptFlag = false;
		$("#soundImage").css("pointer-events", "none");	
		document.getElementById(divId).classList.add('shake');
		randomHenImg = Math.floor(Math.random() * FractionTypes.wrongImgs.length);
		document.getElementById("henImg").src = Utils.Path + "images/skin/"+FractionTypes.wrongImgs[randomHenImg];
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/wrongSound.mp3";
		document.getElementById("playSound").play();
		if(FractionTypes.wrongQuestionTimer){
			clearTimeout(FractionTypes.wrongQuestionTimer);
			FractionTypes.wrongQuestionTimer = null; 
		} 
		FractionTypes.wrongQuestionTimer = setTimeout(function () {
			document.getElementById("henImg").src = Utils.Path + "images/skin/Hen.png";
			document.getElementById(divId).classList.remove('shake');
			$("#soundImage").css("pointer-events", "auto");	
		},500);
	}
}

FractionTypes.callNext = function () {
	if (!(FractionTypes.attemptFlag))
		scoredMarks = -1;
	FractionTypes.nextQuestion();
}

FractionTypes.nextQuestion = function () 
{
	FractionTypes.resetVariable();
	console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	if (Utils.mobileDeviceFlag)
		Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	if (FractionTypes.questionCtr < 5) {
		FractionTypes.initializeVariables();
		FractionTypes.setQuestion();
	}
	else {
		$("#gamePage").hide();
		$("#endPage").show();
	}
}

FractionTypes.resetVariable = function() 
{
	clearTimeout(FractionTypes.correctQueTimer);
	clearTimeout(FractionTypes.wrongQuestionTimer);
	document.getElementById("playSound").pause();
	for (var i = 1; i <= 4; i++) {
		document.getElementById('Egg'+i).classList.remove('shake');
		document.getElementById('Egg'+i).classList.remove('flash');
		document.getElementById('numerator'+i).classList.remove('unlikeFractionNum1');	//For like & unlike fraction
		document.getElementById('denominator'+i).classList.remove('unlikeFractionNum1');
		document.getElementById('unlikeNumerator'+i).classList.remove('borderBottom');
		document.getElementById('wholeNoDiv'+i).innerHTML = '';
		document.getElementById('coumaDiv'+i).innerHTML = '';
		document.getElementById('unlikeNumerator'+i).innerHTML = '';
		document.getElementById('unlikeDenominator'+i).innerHTML = '';
	}
	FractionTypes.scoreFlag = false;
	FractionTypes.attemptFlag = false;
	FractionTypes.firstAttemptFlag = true;
}

FractionTypes.playAgain = function () {
	FractionTypes.questionArr = [];
	$("#acknowledgementDiv").hide();
	$("#endPage").hide();
	$("#gamePage").show();
	FractionTypes.questionCtr = 0;
	FractionTypes.initializeVariables();
	FractionTypes.setQuestion();
}

FractionTypes.callHome = function () {
	if (FractionTypes.attemptFlag && Utils.mobileDeviceFlag) {
		console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
		//if (Utils.mobileDeviceFlag)
			Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	}
	location.reload();
}

FractionTypes.callSound = function(){
    document.getElementById("playSound").src = Utils.Path + "sounds/instructions/chooseOption_Hindi.mp3";
    document.getElementById("playSound").play();    
}

FractionTypes.createAcknowledgementDivs = function () {
	var i = 0, div;
	for (i = 0; i < Object.keys(FractionTypes.AcknowledgementPageData).length; i++) {
		div = document.createElement('div');
		div.className = "nopadding fontClass firstLetter col-xs-12 col-sm-12 col-md-12 col-lg-12";
		div.innerHTML = Object.keys(FractionTypes.AcknowledgementPageData)[i] + " : " + Object.values(FractionTypes.AcknowledgementPageData)[i];
		acknowledgementDiv.appendChild(div);
	}
	div = document.createElement('div');
	div.className = "nopadding fontClass firstLetter col-xs-12 col-sm-12 col-md-12 col-lg-12";
	div.innerHTML = FractionTypes.hardCodedData.createdOn;
	div.style.marginBottom = "2vh";
	acknowledgementDiv.appendChild(div);
}

FractionTypes.showAcknowledgement = function () {
	$("#acknowledgementDiv").show();
}