var MakeTheWords={};
var Utils={};
Utils.path="";
var questionId=0,startTime=0,scoredMarks=0,totalMarks=0,resId=0,mobileDeviceFlag=false,label,scoreFlag=false;
var alphaFillCnt=0;
$(document).ready(function()
{
	if ((navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) && !(window.location.href.includes('http')))
        Utils.mobileDeviceFlag = true;
	/* if(Utils.mobileDeviceFlag)
	{
		Utils.Path=Android.getMediaPath('makeRhymeWord');
	} */
	$(".se-pre-con").fadeOut("slow");
	setTimeout(function()
	{
		MakeTheWords.onloadFunction();
	},100);
},200);
MakeTheWords.onloadFunction=function()
{
	document.getElementById("gamePage").style.display="none";
	document.getElementById("finalPage").style.display="none";
	MakeTheWords.initializeVariables();
	MakeTheWords.setImageSource();
	if(MakeTheWords.hardcodedData.languageFont!=null)
        setFontFamilyForLang(MakeTheWords.hardcodedData.languageFont);
}
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");
}
MakeTheWords.setImageSource=function()		//set source to images 
{
	document.body.style.backgroundImage=Utils.path+"url('images/MakeRhymingWords.png')";
	document.getElementById("quePage").style.backgroundImage=Utils.path+"url('images/bg.png')";
	document.getElementById("que").style.backgroundImage=Utils.path+"url('images/Display_text.png')";
	document.getElementById("logo").src=Utils.path+"images/logo.png";
	document.getElementById("playbutton").src=Utils.path+"images/Play.png";
	document.getElementById("nextButton").src=Utils.path+"images/Skip.png";		//skip Button
	document.getElementById("sound").src=Utils.path+"images/Sound.png";
	document.getElementById("creditbtn").src=Utils.path+"images/Next.png";
}
MakeTheWords.initializeVariables=function()
{
	MakeTheWords.randomNo;
	MakeTheWords.optionCnt=0;			//Play 3 continue sounds
	MakeTheWords.alphabetsArray=[];		//Alphabets in grid
	MakeTheWords.selectedAlphabet;		// alphabet select from grid	
	MakeTheWords.timeset;				//setTimeout variable in timer fun for display next Que
	MakeTheWords.QueArray=[];			//store 3 random words (populateRandomQue fun)
	MakeTheWords.totalQueArray=[];		//select 5 Que for vowel selection(last 5 Ques)
	MakeTheWords.index=0;				//to display index of next que
	MakeTheWords.nextcount=0;
	MakeTheWords.attempQue=0;
	MakeTheWords.temp=false;
	MakeTheWords.flag=true;				//for display que type i.e. vowel selection or consonant selection 
	MakeTheWords.soundFlag = false;		//to Play 3 continue sounds
	MakeTheWords.vowelCounter=0;
	MakeTheWords.consonantCounter=0;
	MakeTheWords.correctCounter=0;
	MakeTheWords.total_No_of_Questions=10;
	MakeTheWords.gameTypeArray=[true,false];
	MakeTheWords.noResponseTimer=0;
	MakeTheWords.seconds=0;
}

MakeTheWords.gamePageFun=function()
{
	document.body.style.backgroundImage=Utils.path+"url('images/Bg-desk.png')";
	MakeTheWords.initializeVariables();
	document.getElementById("alphabets").innerHTML="";
	document.getElementById("ansDiv").innerHTML="";
	document.getElementById("gamePage").style.display="block";
	document.getElementById("playbutton").style.display="none";
	document.getElementById("finalPage").style.display="none";
	document.getElementById("readWordPage").style.display="none";
	MakeTheWords.populateRandomQue();
	MakeTheWords.createAlphabetsDiv();
	MakeTheWords.showQue();
}
MakeTheWords.populateRandomQue=function() 				//select random word from json
{
	var vowelNo=0;
	var letterNo=0;
	letterNoArray=[];
	for(j=0;j<5;j++)
	{
		letterNo=Math.floor(Math.random()*5);
		while(letterNoArray.includes(letterNo))
		{
			letterNo=Math.floor(Math.random()*5);
		}
		letterNoArray.push(letterNo);
		vowelNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[letterNo].vowel.length);
		for(var i=0;i<2;i++)
		{
			MakeTheWords.randomNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[letterNo].vowel[vowelNo].list.length); 
			while(MakeTheWords.QueArray.includes(MakeTheWords.wordsData.letters[letterNo].vowel[vowelNo].list[MakeTheWords.randomNo]))
			{
				MakeTheWords.randomNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[letterNo].vowel[vowelNo].list.length);
			}
			MakeTheWords.QueArray.push(MakeTheWords.wordsData.letters[letterNo].vowel[vowelNo].list[MakeTheWords.randomNo]);
		}
		MakeTheWords.totalQueArray.push(MakeTheWords.wordsData.letters[letterNo].vowel[vowelNo].list[MakeTheWords.randomNo]);
		MakeTheWords.shuffle(MakeTheWords.totalQueArray);
	}
}
MakeTheWords.shuffle=function(alphaArray)	//suffle the letterArray
{
	for( var i=0;i<alphaArray.length;i++)
	{
		var j=Math.floor(Math.random()*(alphaArray.length-1));
		var temp=alphaArray[i];
		alphaArray[i]=alphaArray[j];
		alphaArray[j]=temp;
	}
	return alphaArray;
}
MakeTheWords.createAlphabetsDiv=function()		//display 12 alphabets
{
	if(MakeTheWords.flag==true)
	{
		for(var i=0;i<12;i++)
		{
			var division = document.createElement("div");
			division.setAttribute("id","div"+(i+1));
			division.setAttribute("class","pointer nopadding alphabetDiv selectEffect letters col-sm-2 col-lg-2 col-md-2 col-xs-2 col-sm-offset-1 col-lg-offset-1 col-md-offset-1 col-xs-offset-1 ");
			document.getElementById('alphabets').appendChild(division);
			division.setAttribute("onclick","MakeTheWords.getAlphabet(this)");
		} 
	}
	else if(MakeTheWords.flag==false)
	{
		for(var i=0;i<5;i++)
		{
			var division = document.createElement("div");
			division.setAttribute("id","div"+(i+1));
			division.setAttribute("class","pointer nopadding alphabetDiv flag letters col-sm-1 col-lg-1 col-md-1 col-xs-1 col-sm-offset-1 col-lg-offset-1 col-md-offset-1 col-xs-offset-1 ");
			document.getElementById('alphabets').appendChild(division);
			division.setAttribute("onclick","MakeTheWords.getAlphabet(this)");
		}
		document.getElementById("div1").style.marginLeft = "20vw";
		document.getElementById("div3").style.marginLeft = "20vw";
		document.getElementById("div5").style.marginLeft = "27vw";
	}
}
MakeTheWords.showQue=function()
{
	MakeTheWords.startTimer();
	for(var i=0;i<$("#ansDiv").children().length-1;i++)
		document.getElementById("wordsdiv"+(i)).style.backgroundColor ="whitesmoke";
	var i=Math.floor(Math.random() *MakeTheWords.gameTypeArray.length);
	MakeTheWords.flag=MakeTheWords.gameTypeArray[i];
	scoredMarks=0;
	scoreFlag=false;
	document.getElementById("nextButton").style.pointerEvents='auto';
	d=new Date();
	startTime=d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
	document.getElementById("alphabets").innerHTML="";
	MakeTheWords.createAlphabetsDiv();
	MakeTheWords.temp=true;
		document.getElementById("que").innerHTML=MakeTheWords.QueArray[MakeTheWords.index].langWord;
		document.getElementById("audio").src=Utils.path+'sounds/'+MakeTheWords.QueArray[MakeTheWords.index].sound;
	MakeTheWords.playSound();
	MakeTheWords.dynamicQueDiv();
	MakeTheWords.findRandomAlphabets();
	if(MakeTheWords.flag==true)
	{
		for(var i=0;i<12;i++)
		{
		var letter=MakeTheWords.alphabetsArray[i].word;
		var subLetter=MakeTheWords.alphabetsArray[i].langWord;
		var soundNo=MakeTheWords.alphabetsArray[i].sound;
		subLetter=subLetter.sub();
		document.getElementById("div"+(i+1)).innerHTML=letter+" "+subLetter;
		document.getElementById("div"+(i+1)).setAttribute("data",letter);
		document.getElementById("div"+(i+1)).setAttribute("soundData",soundNo);
		}
	}
	else
	{
		for(var i=0;i<5;i++)
		{
		var letter=MakeTheWords.alphabetsArray[i].word;
		var subLetter=MakeTheWords.alphabetsArray[i].langWord;
		var soundNo=MakeTheWords.alphabetsArray[i].sound;
		subLetter=subLetter.sub();
		document.getElementById("div"+(i+1)).innerHTML=letter+" "+subLetter;
		document.getElementById("div"+(i+1)).setAttribute("data",letter);
		document.getElementById("div"+(i+1)).setAttribute("soundData",soundNo);
		}
	}
	document.getElementById("checkid").style.pointerEvents="none";
} 
MakeTheWords.dynamicQueDiv=function()		//create dynamic div for que
{
	var alphabet;
	var word=MakeTheWords.QueArray[MakeTheWords.index].word;
	questionId=MakeTheWords.QueArray[MakeTheWords.index].questionId;
	if(MakeTheWords.levelNum==0)
		alphabet=word.split("");
	else
	{
		alphabet=word.split("");
		for(var i=0;i<alphabet.length;i++)		/*-----------concat two letters-------*/
		{
			var concat=alphabet[i]+""+alphabet[i+1];
			for(var j=0;j<MakeTheWords.blends.length;j++)
			{
				if(MakeTheWords.blends[j].word==concat)
				{
					var str=MakeTheWords.blends[j].word;
					alphabet.splice(i,2,str);
				}
			}
		}
		for(var i=0;i<alphabet.length;i++)	/*-----------concat three letters-------*/
		{
			var concat=alphabet[i]+""+alphabet[i+1]+""+alphabet[i+2];
			for(var j=0;j<MakeTheWords.blends.length;j++)
			{
				if(MakeTheWords.blends[j].word==concat)
				{
					var str=MakeTheWords.blends[j].word;
					alphabet.splice(i,3,str);
				}
			}
		}
		for(var i=0;i<alphabet.length;i++)		/*-----------concat four letters-------*/
		{
			var concat=alphabet[i]+""+alphabet[i+1]+""+alphabet[i+2]+""+alphabet[i+3];
			for(var j=0;j<MakeTheWords.blends.length;j++)
			{
				if(MakeTheWords.blends[j].word==concat)
				{
					var str=MakeTheWords.blends[j].word;
					alphabet.splice(i,4,str);
				}
			}
		}
	}
	MakeTheWords.alphabetsArray=[];
	console.log(alphabet);
	MakeTheWords.vowelCounter=0;				//initialize counter to 0 for next question
	MakeTheWords.consonantCounter=0;
	for(var j=0;j<alphabet.length;j++)
	{
		var div= document.createElement("div");
		div.setAttribute("id","wordsdiv"+(j));
		div.setAttribute("class","bgbtn pointer nopadding words col-lg-1 col-md-1 col-sm-1 col-xs-1");
		document.getElementById('ansDiv').appendChild(div);
		div.style.backgroundColor ="whitesmoke";
		div.style.border ="2px solid black";
		document.getElementById("wordsdiv"+(j)).style.setProperty("color","transparent");
		div.setAttribute("alphabetData",alphabet[j]);
		div.setAttribute("onclick","MakeTheWords.setAlphabet(this)");
		var letter=alphabet[j];
		if(MakeTheWords.vowel.includes(letter)&& MakeTheWords.flag==true)	//show vowel
		{
			document.getElementById("wordsdiv"+(j)).innerHTML=alphabet[j];
			document.getElementById("wordsdiv"+(j)).style.setProperty("color","");
			document.getElementById("wordsdiv"+(j)).style.pointerEvents="none";
			MakeTheWords.vowelCounter++;
		}
		else if(!MakeTheWords.vowel.includes(letter) && MakeTheWords.flag==false)	//show consonants
		{
			document.getElementById("wordsdiv"+(j)).innerHTML=alphabet[j];
			document.getElementById("wordsdiv"+(j)).style.setProperty("color","");
			document.getElementById("wordsdiv"+(j)).style.pointerEvents="none";
			MakeTheWords.consonantCounter++;
		}
		for(var i=0;i<MakeTheWords.alphabets.length;i++)
		{
			if(MakeTheWords.alphabets[i].word==letter)
				MakeTheWords.alphabetsArray.push(MakeTheWords.alphabets[i]);
		}
		for(var i=0;i<MakeTheWords.blends.length;i++)
		{
			if(MakeTheWords.blends[i].word==letter)
				MakeTheWords.alphabetsArray.push(MakeTheWords.blends[i]);
		}
	}
		var buttonDiv= document.createElement("div");
		buttonDiv.setAttribute("id","checkid");
		buttonDiv.setAttribute("class"," nopadding words col-lg-1 col-md-1 col-sm-1 col-xs-1");
		buttonDiv.setAttribute("onclick","MakeTheWords.checkAns");
		document.getElementById('ansDiv').appendChild(buttonDiv);
		var img=document.createElement("img");
		img.setAttribute("id","checkButton");
		img.setAttribute("class","nopadding img-responsive col-lg-11 col-md-11 col-sm-11 col-xs-11");
		img.setAttribute("onclick","MakeTheWords.checkAns()");
		document.getElementById('checkid').appendChild(img);
		document.getElementById("checkButton").src=Utils.path+"images/Check.png";
	if(alphabet.length==2)
		document.getElementById("wordsdiv0").style.marginLeft = "30vw";
	else if(alphabet.length==3)
		document.getElementById("wordsdiv0").style.marginLeft = "24vw";
	else if(alphabet.length==4)
		document.getElementById("wordsdiv0").style.marginLeft = "18vw";
	else if(alphabet.length==5)
		document.getElementById("wordsdiv0").style.marginLeft = "12vw";
	else if(alphabet.length==6)
		document.getElementById("wordsdiv0").style.marginLeft = "6vw";
}
MakeTheWords.findRandomAlphabets=function()	//find 12 random alphabets
{
	var randomAlphabet=0;
	if(MakeTheWords.flag==true)
	{
		if(MakeTheWords.levelNum==1)	//Level 2 (with_blends)
		{
			for(var j=MakeTheWords.alphabetsArray.length;j<6;j++)
			{
				randomAlphabet=Math.floor(Math.random()*MakeTheWords.blends.length);
				while(MakeTheWords.alphabetsArray.includes(MakeTheWords.blends[randomAlphabet]))
					randomAlphabet=Math.floor(Math.random()*MakeTheWords.blends.length);
				MakeTheWords.alphabetsArray.push(MakeTheWords.blends[randomAlphabet]); 
			}
		}
		for(var j=MakeTheWords.alphabetsArray.length;j<12;j++)
		{
		randomAlphabet=Math.floor(Math.random()*MakeTheWords.alphabets.length);
			while(MakeTheWords.alphabetsArray.includes(MakeTheWords.alphabets[randomAlphabet]))
			{
				randomAlphabet=Math.floor(Math.random()*MakeTheWords.alphabets.length);
			}
			MakeTheWords.alphabetsArray.push(MakeTheWords.alphabets[randomAlphabet]); 
		}
	}
	else if(MakeTheWords.flag==false)
	{
		MakeTheWords.alphabetsArray=[];
		for(var j=0;j<5;j++)
		{
			randomAlphabet=Math.floor(Math.random()*MakeTheWords.alphabetsVowel.length);
			while(MakeTheWords.alphabetsArray.includes(MakeTheWords.alphabetsVowel[randomAlphabet]))
			{
				randomAlphabet=Math.floor(Math.random()*MakeTheWords.alphabetsVowel.length);
			}
			MakeTheWords.alphabetsArray.push(MakeTheWords.alphabetsVowel[randomAlphabet]); 
		}
	}
	MakeTheWords.shuffle(MakeTheWords.alphabetsArray);
	if(MakeTheWords.flag==true)
	{
	totalMarks=($("#ansDiv").children().length-1)-MakeTheWords.vowelCounter;
	}
	else
	{
	totalMarks=($("#ansDiv").children().length-1)-MakeTheWords.consonantCounter;	
	}
}
MakeTheWords.getAlphabet=function(object)/*..........select alphabet from grid..................*/
{
	clearInterval(MakeTheWords.noResponseTimer);
	MakeTheWords.startTimer();
	$('.alphabetDiv').css("backgroundColor","whitesmoke");
	for(var i=0;i<$("#ansDiv").children().length-1;i++)
		document.getElementById("wordsdiv"+(i)).style.backgroundColor ="whitesmoke";
	scoredMarks=0;
	MakeTheWords.selectedAlphabet=document.getElementById(object.id).getAttribute("data");
	var soundNumber=document.getElementById(object.id).getAttribute("soundData");
	document.getElementById("audio").src=Utils.path+'sounds/'+soundNumber;
	document.getElementById("audio").play();
	document.getElementById(object.id).style.backgroundColor="FF9999";
}
MakeTheWords.setAlphabet=function(object)/*...........Set selected alphabet in Answer div............*/
{
	alphaFillCnt=0;
	clearInterval(MakeTheWords.noResponseTimer);
	MakeTheWords.startTimer();
	for(var i=0;i<$("#ansDiv").children().length-1;i++)
		document.getElementById("wordsdiv"+(i)).style.backgroundColor ="whitesmoke";
 	if(MakeTheWords.selectedAlphabet)
	{
		document.getElementById(object.id).innerHTML=MakeTheWords.selectedAlphabet;
		document.getElementById(object.id).style.setProperty("color","");
		document.getElementById(object.id).style.backgroundColor="FF9999";
	}
	for(var j=0;j<$("#ansDiv").children().length-1;j++)	//check whether all ans divs filled or not
	{
		var alphabet=document.getElementById('ansDiv').children[j].innerHTML;
		if(alphabet=="")
			alphaFillCnt++;
	}
	if(alphaFillCnt==0)
	document.getElementById("checkid").style.pointerEvents="auto";
else
	document.getElementById("checkid").style.pointerEvents="none";
}
MakeTheWords.checkAns=function()	/*.....Ckeck Ans is right or wrong on click check button.....*/
{
	clearInterval(MakeTheWords.noResponseTimer);
	counter=0;
	scoredMarks=0;
	totalMarks=0;
	var k=0;									//to check all answer divs are filled or not
	var word=MakeTheWords.QueArray[MakeTheWords.index].word;
	type="word";
	var totalNos=0;
	scoreFlag=true;
	$(".pointer").css("pointer-events","none");
	for(var i=0;i<5;i++)
	{
		for(var j=0;j<MakeTheWords.wordsData.letters[i].vowel.length;j++)
			totalNos=totalNos+MakeTheWords.wordsData.letters[i].vowel[j].list.length;
	}
	/* for(var j=0;j<$("#ansDiv").children().length-1;j++)	//check whether all ans divs filled or not
	{
		var alphabet=document.getElementById('ansDiv').children[j].innerHTML;
		if(alphabet=="")
			k++;
	} */
	if(alphaFillCnt==0)						//to check all answer divs are filled or not
	{
		document.getElementById("checkid").style.pointerEvents="auto";
		document.getElementById("soundDiv").style.pointerEvents='none';
		for(var j=0;j<$("#ansDiv").children().length-1;j++)
		{
			var firstLetter=document.getElementById("wordsdiv"+j).getAttribute("alphabetdata");
			var secondLetter=document.getElementById('ansDiv').children[j].innerHTML;
			if(firstLetter==secondLetter)
				counter++;
			document.getElementById("wordsdiv"+(j)).style.backgroundColor ="whitesmoke";//remove yellow clr Que div
		}
		if(MakeTheWords.flag==true)
		{
			scoredMarks=counter-MakeTheWords.vowelCounter;
			totalMarks=($("#ansDiv").children().length-1)-MakeTheWords.vowelCounter;
			$('.alphabetDiv').css("backgroundColor","whitesmoke");
		}
		else
		{
			scoredMarks=counter-MakeTheWords.consonantCounter;
			totalMarks=($("#ansDiv").children().length-1)-MakeTheWords.consonantCounter;
			$('.alphabetDiv').css("backgroundColor","whitesmoke");
		}
		document.getElementById('ansImg').style.display='block';
		document.getElementById("checkid").style.pointerEvents="none";
		if(counter==$("#ansDiv").children().length-1)
		{
			console.log(word,totalNos,type);
			if(Utils.mobileDeviceFlag)
			{
				Android.addLearntData(word,totalNos,type);
			}
			document.getElementById("ansImg").src=Utils.path+"images/correct.png";
			document.getElementById("audio").src=Utils.path+'sounds/Instructions/Right_answer__Aditi.mp3';
			MakeTheWords.correctCounter++;
			document.getElementById("alphabets").style.pointerEvents="none";
			document.getElementById("ansDiv").style.pointerEvents="none";
			selectedAlphabet="";
		}
		else
		{
			document.getElementById("ansImg").src=Utils.path+"images/wrong.png";
			document.getElementById("audio").src=Utils.path+'sounds/Instructions/wrong_answer!_Aditi.mp3';
		}
			MakeTheWords.scoreFunction();
			MakeTheWords.setTimeToQue=setTimeout(function() 
			{
				document.getElementById('ansImg').style.display='none';
				document.getElementById("checkid").style.pointerEvents="auto";
				MakeTheWords.nextQue();
			}, 2000);
		document.getElementById("audio").play();
		MakeTheWords.attempQue++;
		MakeTheWords.QueArray.splice(MakeTheWords.index,1);
	}
	else
	{
		document.getElementById("checkid").style.pointerEvents="none";
		document.getElementById("soundDiv").style.pointerEvents='auto';
	}
}
MakeTheWords.scoreFunction=function()								//score Function
{
	console.log(resId,questionId,scoredMarks,totalMarks,1,startTime);
	if(Utils.mobileDeviceFlag)
	{
		Android.addScore(resId,questionId,scoredMarks,totalMarks,1,startTime);
	}
}
MakeTheWords.nextQue=function()		//display next question click on next button
{
	clearTimeout(MakeTheWords.timeOut);
	clearTimeout(MakeTheWords.setTimeToQue);
	clearInterval(MakeTheWords.noResponseTimer);
	document.getElementById("alphabets").style.pointerEvents="auto";
	document.getElementById("ansDiv").style.pointerEvents="auto"; 
	MakeTheWords.selectedAlphabet="";
	MakeTheWords.attempQue=0;
	document.getElementById("checkid").style.pointerEvents="auto";
	document.getElementById("soundDiv").style.pointerEvents='auto';
	$(".flag").removeClass('effect');
	if(scoreFlag!=true)
	{
		MakeTheWords.index++;
	}
	document.getElementById('ansImg').style.display='none';
	if(MakeTheWords.QueArray.length==0)
	{
		MakeTheWords.gameover();
	}
	else if(MakeTheWords.index==MakeTheWords.QueArray.length)
	{
	document.getElementById("responseBoxDiv").style.display="block";
	document.getElementById("No").innerHTML=MakeTheWords.modalData.no;
	document.getElementById("Yes").innerHTML=MakeTheWords.modalData.yes;
	document.getElementById("questionMsg").innerHTML=MakeTheWords.modalData.responseMsg;
	}
	else
	{
	document.getElementById("ansDiv").innerHTML="";
	MakeTheWords.showQue();
	}
}
MakeTheWords.showSkippedQuestions=function()
{
	document.getElementById("ansDiv").innerHTML="";
	document.getElementById("responseBoxDiv").style.display="none";
	MakeTheWords.index=0;
	MakeTheWords.showQue();
}

MakeTheWords.playSound=function()						//to play sound
{	
	document.getElementById("audio").src=Utils.path+'sounds/'+MakeTheWords.QueArray[MakeTheWords.index].sound;
	document.getElementById("audio").play(); 
} 
MakeTheWords.gameover=function()					//game over function
{
	clearInterval(MakeTheWords.noResponseTimer);
	MakeTheWords.createStars();
	MakeTheWords.giveStars();
	document.getElementById("responseBoxDiv").style.display="none";
	document.getElementById("coverPage").style.display="none";
	document.getElementById("gamePage").style.display="none";
	document.getElementById("finalPage").style.display="block";
	document.getElementById('gameOver').innerHTML=MakeTheWords.hardcodedData.message2;
}
//function which creates star divs
MakeTheWords.createStars=function()
{
	var newImage,newDiv,i,numberOfStars=5;
	for(i=1;i<=Math.floor(numberOfStars);i++)
	{
		newDiv= document.createElement("div");
		newDiv.setAttribute("id","starDiv"+i); 
		newDiv.setAttribute("class","nopadding stars col-xs-2 col-md-2 col-lg-2 col-sm-2"); 
		newImage= document.createElement("img");
		newImage.setAttribute("id","starImg"+i); 
		newImage.setAttribute("class","img-responsive nopadding col-sm-12 col-lg-12 col-md-12 col-xs-12"); 
		newImage.setAttribute("src",Utils.path+"images/star1.png");
		$(newDiv).append(newImage);
		$("#starsDiv").append(newDiv);
	}
};

MakeTheWords.giveStars=function()
{
	var fractionVar,i,numberOfStars=0,temp; 
	ans=MakeTheWords.total_No_of_Questions/5;
	temp=MakeTheWords.correctCounter/ans;
	numberOfStars=Math.floor(temp);
	temp=Math.round(temp);
	console.log(numberOfStars);
	console.log(temp);
	for(i=1;i<=Math.floor(numberOfStars);i++)
	document.getElementById("starImg"+i).setAttribute("src",Utils.path+"images/star2.png");
	/* if(temp>numberOfStars)
	document.getElementById("starImg"+i).setAttribute("src",Utils.path+"images/halfStar.png"); */
	//$("#starsDiv").css("visibility","visible");
	if(numberOfStars!=0)
	{
	document.getElementById("audio").src=Utils.path+"sounds/Instructions/"+"Star"+numberOfStars+".mp3";
	document.getElementById("audio").play();
	}
	if(Utils.mobileDeviceFlag)
	Android.StudentCertification(MakeTheWords.correctCounter,MakeTheWords.total_No_of_Questions,"8");
};

MakeTheWords.returnback=function()			//return to previous page (reload)
{	
	document.getElementById("starsDiv").innerHTML="";
	document.getElementById("audio").pause();
	clearTimeout(MakeTheWords.setTimeToQue);
	clearInterval(MakeTheWords.noResponseTimer);
	clearTimeout(MakeTheWords.timeOut);
	if(MakeTheWords.temp==true)
	{
		if(scoreFlag==true)
			MakeTheWords.scoreFunction();
		MakeTheWords.temp=false;
		document.getElementById("coverPage").style.display = "none";
		document.getElementById("gamePage").style.display = "none";
		document.getElementById("finalPage").style.display="none";
		document.getElementById("readWordPage").style.display = "none";
		document.getElementById('ansImg').style.display='none';
	}
	else
		location.reload(true);
}
MakeTheWords.goNext=function()
{
	clearInterval(MakeTheWords.skipTimer);
	if(Utils.mobileDeviceFlag)
	Android.GotoNextGame();
}
MakeTheWords.startTimer=function()
{
	if(MakeTheWords.noResponseTimer)
	{
		clearInterval(MakeTheWords.noResponseTimer);
		MakeTheWords.noResponseTimer=null;
		MakeTheWords.seconds=0;
	}	
	MakeTheWords.noResponseTimer=setInterval(function() 
	{
		MakeTheWords.seconds++;
		if(MakeTheWords.seconds>=7)
		{
			document.getElementById("audio").src=Utils.path+"sounds/instructions/please_ans_the_ques.mp3";
			document.getElementById("audio").play(); 
			clearInterval(MakeTheWords.noResponseTimer)
			if(MakeTheWords.timeOut)
			{
				clearTimeout(MakeTheWords.timeOut);
				MakeTheWords.timeOut=null;
			}
				MakeTheWords.timeOut=setTimeout(function()
			{
				MakeTheWords.seconds=0;
				MakeTheWords.startTimer();
			},2000);
		}
	},1000);
};