var MakeTheWords={};
var Utils={};
Utils.path="";
var questionId=0,startTime=0,scoredMarks=0,totalMarks=0,resId=0,mobileDeviceFlag=false,label,scoreFlag=false;
checkAlphaFlag=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);
	document.getElementById("progressBarDiv").style.visibility="hidden";
});
MakeTheWords.onloadFunction=function()
{
	document.getElementById("home").style.display="none";
	document.getElementById("gamePage").style.display="none";
	document.getElementById("finalPage").style.display="none";
	document.getElementById("readWordPage").style.display="none";
	document.getElementById("progressBarDiv").style.visibility="hidden";
	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("home").src=Utils.path+"images/Home.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/Next.png";
	document.getElementById("sound").src=Utils.path+"images/Sound.png";
	/* document.getElementById("levelImg1").src=Utils.path+"images/Level_1.png";
	document.getElementById("levelImg2").src=Utils.path+"images/Level_2.png"; */
	document.getElementById("skip").src=Utils.path+"images/Skip.png";
	document.getElementById("replatbtn").src=Utils.path+"images/replay.png";
	document.getElementById("creditbtn").src=Utils.path+"images/Credits.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.setTime;				//setInterval variable for progress bar timer
	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.selectVowel=0;			//in Populate Que select vowel
	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.practice=false;
	MakeTheWords.instructionFlag=false;
}

MakeTheWords.gamePageFun=function()
{
	if(Utils.mobileDeviceFlag)
	MakeTheWords.practice=Android.isPractice();
	if(MakeTheWords.practice)
		MakeTheWords.gameType="practice";
	else
		MakeTheWords.gameType="learn";
	document.body.style.backgroundImage=Utils.path+"url('images/Bg-desk.png')";
	MakeTheWords.initializeVariables();
	acknowledgementDiv.innerHTML='';
	document.getElementById("alphabets").innerHTML="";
	document.getElementById("ansDiv").innerHTML="";
	document.getElementById("home").style.display="block";
	document.getElementById("gamePage").style.display="block";
	document.getElementById("playbutton").style.display="none";
	document.getElementById("finalPage").style.display="none";
	if(MakeTheWords.gameType=="learn")
	{
		document.getElementById("progressBarDiv").style.visibility="hidden";
		document.getElementById("gamePage").style.display="none";
		document.getElementById("readWordPage").style.display="block";
		document.getElementById("rhymingWordDiv").innerHTML="";
		MakeTheWords.populateRandomQue();
		MakeTheWords.createWordsDiv();	//three read words divs (6 divs)
		MakeTheWords.displaywords();
	}
	else
	{
		document.getElementById("progressBarDiv").style.visibility="visible";
		MakeTheWords.populateRandomQue();
		MakeTheWords.createAlphabetsDiv();
		MakeTheWords.showQue();
	}
}
MakeTheWords.createWordsDiv=function()			//In learn section creates divs for three rhyming words
{
	for(var i=0;i<3;i++)
	{
		var rhymeDiv = document.createElement("div");
		rhymeDiv.setAttribute("id","rhymeDiv"+(i+1));
		rhymeDiv.setAttribute("class","rhymeStyle nopadding col-sm-3 col-lg-3 col-md-3 col-xs-3 col-sm-offset-1 col-lg-offset-1 col-md-offset-1 col-xs-offset-1");
		document.getElementById('rhymingWordDiv').appendChild(rhymeDiv);
		rhymeDiv.setAttribute("onclick","MakeTheWords.listenAgain(this)");
		rhymeDiv.style.backgroundImage=Utils.path+"url('images/Button_1.png')";
		for(var j=1;j<=2;j++)
		{
			var subLangDiv = document.createElement("div");
			subLangDiv.setAttribute("id","subLangDiv"+(i+1)+""+(j));
			subLangDiv.setAttribute("class","rhymeSubDivStyle nopadding col-sm-12 col-lg-12 col-md-12 col-xs-12 ");
			document.getElementById("rhymeDiv"+(i+1)).appendChild(subLangDiv);
		}
		var soundButton=document.createElement("div");
		soundButton.setAttribute("id","soundButton"+(i+1));
		soundButton.setAttribute("class","soundDivStyle nopadding col-sm-12 col-lg-12 col-md-12 col-xs-12 ");
		document.getElementById("rhymeDiv"+(i+1)).appendChild(soundButton);
		var img=document.createElement("img");
		img.setAttribute("id","soundImg"+(i+1));
		img.setAttribute("class","nopadding col-sm-2 col-lg-2 col-md-2 col-xs-2 col-sm-offset-5 col-lg-offset-5 col-md-offset-5 col-xs-offset-5");
		document.getElementById("soundButton"+(i+1)).appendChild(img);
		document.getElementById("soundImg"+(i+1)).src=Utils.path+"images/Sound.png";
	}
}
MakeTheWords.listenAgain=function(object)
{
	for(var i=1;i<=3;i++)
		$("#rhymeDiv"+i).removeClass('animated bounceIn');
	$("#"+object.id).addClass('animated bounceIn');
	var soundNumber=document.getElementById(object.id).getAttribute("listenSound");
	document.getElementById("audio").src=Utils.path+'sounds/'+soundNumber;
	document.getElementById("audio").play();
	clearTimeout(MakeTheWords.skipTimer);
	MakeTheWords.startTimer();
}
MakeTheWords.populateRandomQue=function() 				//select random word from json
{
	var vowelNo=0;
	if(MakeTheWords.gameType=="learn")
	{
		MakeTheWords.QueArray=[];
		vowelNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[MakeTheWords.selectVowel].vowel.length);
		while(MakeTheWords.wordsData.letters[MakeTheWords.selectVowel].vowel[vowelNo].list.length<3)
		{	vowelNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[MakeTheWords.selectVowel].vowel.length);}
		for(var i=0;i<3;i++)
		{
			MakeTheWords.randomNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[MakeTheWords.selectVowel].vowel[vowelNo].list.length); 
			while(MakeTheWords.QueArray.includes(MakeTheWords.wordsData.letters[MakeTheWords.selectVowel].vowel[vowelNo].list[MakeTheWords.randomNo]))
			{
				MakeTheWords.randomNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[MakeTheWords.selectVowel].vowel[vowelNo].list.length);
			}
			MakeTheWords.QueArray.push(MakeTheWords.wordsData.letters[MakeTheWords.selectVowel].vowel[vowelNo].list[MakeTheWords.randomNo]);
		}
		MakeTheWords.totalQueArray.push(MakeTheWords.wordsData.letters[MakeTheWords.selectVowel].vowel[vowelNo].list[MakeTheWords.randomNo]);
		MakeTheWords.shuffle(MakeTheWords.totalQueArray);
	}
	else
	{
		for(j=0;j<5;j++)
		{
			vowelNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[j].vowel.length);
			if(MakeTheWords.wordsData.letters[j].vowel[vowelNo].list.length>=3)
			{
				for(var i=0;i<3;i++)
				{
					MakeTheWords.randomNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[j].vowel[vowelNo].list.length); 
					while(MakeTheWords.QueArray.includes(MakeTheWords.wordsData.letters[j].vowel[vowelNo].list[MakeTheWords.randomNo]))
					{
						MakeTheWords.randomNo=Math.floor(Math.random()*MakeTheWords.wordsData.letters[j].vowel[vowelNo].list.length);
					}
					MakeTheWords.QueArray.push(MakeTheWords.wordsData.letters[j].vowel[vowelNo].list[MakeTheWords.randomNo]);
				}
			}
			else
			{
				j--;
				continue;
			}
			MakeTheWords.totalQueArray.push(MakeTheWords.wordsData.letters[j].vowel[vowelNo].list[MakeTheWords.randomNo]);
		}
		MakeTheWords.shuffle(MakeTheWords.totalQueArray);
	}
}
MakeTheWords.displaywords=function()	//display three rhyming words in learn section
{
	MakeTheWords.instructionFlag=true;
	for(var i=0;i<3;i++)
	{
		var soundNo=MakeTheWords.QueArray[i].sound;
		document.getElementById("rhymeDiv"+(i+1)).setAttribute("listenSound",soundNo);
		document.getElementById("subLangDiv"+(i+1)+""+"1").innerHTML=MakeTheWords.QueArray[i].word;
		document.getElementById("subLangDiv"+(i+1)+""+"2").innerHTML=MakeTheWords.QueArray[i].langWord;
	}
	
	MakeTheWords.selectVowel++;
	document.getElementById("rhymingWordDiv").style.pointerEvents='none';
	MakeTheWords.playInstruction();
}
MakeTheWords.playInstruction = function()	 // plays sound of three rhyming words in learn section 
{ 
	MakeTheWords.soundFlag = true;
	if(MakeTheWords.instructionFlag)
	{
		getDuration(Utils.path + 'sounds/Instructions/instruction1.mp3',"instructionFun");
		MakeTheWords.instructionFlag=false;
	//	MakeTheWords.optionCnt=0;
	}
	else
    	getDuration(Utils.path + 'sounds/' + MakeTheWords.QueArray[MakeTheWords.optionCnt].sound,"wordSound");
}
function getDuration(src,functionName) {
    var duration = 0;
    if (MakeTheWords.soundFlag)
	{
        $('#audio').on("loadedmetadata", function () 
		{
            MakeTheWords.soundFlag = false;
            duration = $('#audio').prop('duration');
			$('#audio').unbind("loadedmetadata");
			if(functionName=="wordSound")
				MakeTheWords.playOptionsInLoop(duration);
			else
				MakeTheWords.playMainInstruction(duration);
        });
        $('#audio').prop('src', src);
    }
}
MakeTheWords.playMainInstruction = function (duration)
{
	document.getElementById('audio').play();
	if (MakeTheWords.instructionTimer) 
	{
        clearTimeout(MakeTheWords.instructionTimer);
        MakeTheWords.instructionTimer = null;
    }
    MakeTheWords.instructionTimer = setTimeout(function () 
	{
		MakeTheWords.playInstruction();
	},duration*1200);
}
MakeTheWords.playOptionsInLoop = function (duration)			//play words sounds in a loop
{
	$("#rhymeDiv"+(MakeTheWords.optionCnt+1)).addClass('animated bounceIn');
    document.getElementById('audio').play();
    if (MakeTheWords.optionTimer) 
	{
        clearTimeout(MakeTheWords.optionTimer);
        MakeTheWords.optionTimer = null;
    }
    MakeTheWords.optionTimer = setTimeout(function () 
	{
		document.getElementById("rhymingWordDiv").style.pointerEvents='none';
		MakeTheWords.optionCnt++;
        if (MakeTheWords.optionCnt <3)
			MakeTheWords.playInstruction();
        else{
			clearTimeout(MakeTheWords.optionTimer);
			clearTimeout(MakeTheWords.instructionTimer);
			clearTimeout(MakeTheWords.secondInstructionTimer);
			MakeTheWords.optionCnt=0;
			document.getElementById("rhymingWordDiv").style.pointerEvents='auto';
			for(var i=1;i<=3;i++)
				$("#rhymeDiv"+i).removeClass('animated bounceIn');
			MakeTheWords.startTimer();
			}
    }, duration * 2000);
}
MakeTheWords.startTimer=function()
{
	if(MakeTheWords.skipTimer) 
	{
        clearTimeout(MakeTheWords.skipTimer);
        MakeTheWords.skipTimer = null;
    }
	MakeTheWords.skipTimer = setTimeout(function () 
	{
		MakeTheWords.skipReading();
	},5000)
}
MakeTheWords.skipReading=function()
{
	clearTimeout(MakeTheWords.skipTimer);
	clearTimeout(MakeTheWords.secondInstructionTimer);
	MakeTheWords.shuffle(MakeTheWords.QueArray);
	clearTimeout(MakeTheWords.optionTimer);
	clearTimeout(MakeTheWords.instructionTimer);
	document.getElementById("audio").pause();
	document.getElementById("gamePage").style.display="block";
	document.getElementById("readWordPage").style.display="none";
	document.getElementById("ansDiv").innerHTML="";
	MakeTheWords.showQue();
}
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 20 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","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","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()
{
	scoredMarks=0;
	scoreFlag=false;
	totalMarks=0;
	checkAlphaFlag=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;
	if(MakeTheWords.flag==true)
	{
		document.getElementById("que").innerHTML=MakeTheWords.QueArray[MakeTheWords.index].langWord;
		if(MakeTheWords.index==0)
		{
			document.getElementById("audio").src=Utils.path+'sounds/Instructions/instruction2.mp3';
				document.getElementById("audio").play();
			if (MakeTheWords.secondInstructionTimer) 
			{
				clearTimeout(MakeTheWords.secondInstructionTimer);
				MakeTheWords.secondInstructionTimer = null;
			}
			MakeTheWords.secondInstructionTimer = setTimeout(function () 
			{
				document.getElementById("audio").src=Utils.path+'sounds/'+MakeTheWords.QueArray[MakeTheWords.index].sound;
			document.getElementById("audio").play();
			if(MakeTheWords.gameType!="learn")
		MakeTheWords.showTimer();
			},3000);
		}
		else
		{
			document.getElementById("audio").src=Utils.path+'sounds/'+MakeTheWords.QueArray[MakeTheWords.index].sound;
			document.getElementById("audio").play();
			if(MakeTheWords.gameType!="learn")
				MakeTheWords.showTimer();
		}
	}
	else
	{
		document.getElementById("que").innerHTML=MakeTheWords.totalQueArray[MakeTheWords.nextcount].langWord;
		document.getElementById("audio").src=Utils.path+'sounds/'+MakeTheWords.totalQueArray[MakeTheWords.nextcount].sound;
		if(MakeTheWords.gameType!="learn")
		MakeTheWords.showTimer();
	}
	document.getElementById("audio").play();
//	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);
		}
	}
} 
MakeTheWords.dynamicQueDiv=function()		//create dynamic div for que
{
	var alphabet;
	if(MakeTheWords.flag==true)
	{
		var word=MakeTheWords.QueArray[MakeTheWords.index].word;
		questionId=MakeTheWords.QueArray[MakeTheWords.index].questionId;
	}
	else
	{
		var word=MakeTheWords.totalQueArray[MakeTheWords.nextcount].word;
		questionId=MakeTheWords.totalQueArray[MakeTheWords.nextcount].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 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
		{
			$("#wordsdiv"+(j)).removeClass('pointer');
			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
		{
			$("#wordsdiv"+(j)).removeClass('pointer');
			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("checkid").style.pointerEvents="none";
		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.showTimer=function()//*..................set timer................*/
{
	var width=0;
	var elem=document.getElementById("ProgressBar");
	width=100;
	if(MakeTheWords.setTime)
	{
		clearInterval(MakeTheWords.setTime);
		MakeTheWords.setTime=null;
	}
	MakeTheWords.setTime=setInterval(setProgressBar,200);
	function setProgressBar()
	{ 
		elem.style.width=width+"%";
		width--;
		if(width==0)
		{
			$(".pointer").css("pointer-events","none");
			MakeTheWords.displayDefultAns();
			if(MakeTheWords.timeset)
			{
				clearTimeout(MakeTheWords.timeset);
				MakeTheWords.timeset=null;
			}
			if(MakeTheWords.setTime)
			{
				clearInterval(MakeTheWords.setTime);
				MakeTheWords.setTime=null;
			}
			MakeTheWords.timeset=setTimeout(function()
			{
				scoreFlag=true;							//when time out scoredMarks=0 
				MakeTheWords.nextQue();
			},1000);
		}
	}
}
MakeTheWords.getAlphabet=function(object)/*..........select alphabet from grid..................*/
{
	clearInterval(MakeTheWords.wrongSound);
	$('.alphabetDiv').css("backgroundColor","whitesmoke");
	for(var i=0;i<$("#ansDiv").children().length-1;i++)
		document.getElementById("wordsdiv"+(i)).style.backgroundColor ="whitesmoke";
	scoreFlag=true;
	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.wrongSound);
	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";
	}
	if(MakeTheWords.gameType=="learn")
	{
		$(".pointer").css("pointer-events","none");
		var data=document.getElementById(object.id).getAttribute("alphabetdata");
		var innerHTML=document.getElementById(object.id).innerHTML;
		if(data!=innerHTML)
		{
			checkAlphaFlag=true;
			if(MakeTheWords.wrongSound)
			{
				clearInterval(MakeTheWords.wrongSound);
				MakeTheWords.wrongSound=null;
			}
			MakeTheWords.wrongSound=setTimeout(function()
			{
				$(".pointer").css("pointer-events","auto");
				document.getElementById(object.id).innerHTML='';
				document.getElementById(object.id).style.backgroundColor='';
				document.getElementById(object.id).style.backgroundColor="whitesmoke";
				$('.alphabetDiv').css("backgroundColor","whitesmoke");
				if(MakeTheWords.selectedAlphabet){
					document.getElementById("audio").src=Utils.path+'sounds/Instructions/Not_this_one__Aditi.mp3';
				document.getElementById("audio").play();}
			},500);
		}
		else{
			$(".pointer").css("pointer-events","auto");
			checkAlphaFlag=false;
		}	
	}
	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 && checkAlphaFlag!=true)
	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.....*/
{
	counter=0;
	scoredMarks=0;
	$(".pointer").css("pointer-events","none");	
	document.getElementById("alphabets").style.pointerEvents="none";	
	if(MakeTheWords.flag==true)				//flag true = show vowel
		var word=MakeTheWords.QueArray[MakeTheWords.index].word;
	else
		var word=MakeTheWords.totalQueArray[MakeTheWords.nextcount].word;
	type="word";
	var totalNos=0;
	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';
	
		if(MakeTheWords.attempQue<2)
		{
			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/Amazing!_Aditi.mp3';
			document.getElementById("alphabets").style.pointerEvents="none";
			document.getElementById("ansDiv").style.pointerEvents="none";
			document.getElementById("checkid").style.pointerEvents="none";
			selectedAlphabet="";
				if(MakeTheWords.setTime)
				{
					clearInterval(MakeTheWords.setTime);
					MakeTheWords.setTime=null;
				}
					MakeTheWords.setTimeToQue=setTimeout(function() {
					document.getElementById('ansImg').style.display='none';
					$(".pointer").css("pointer-events","auto");
					document.getElementById("alphabets").style.pointerEvents="auto";
					MakeTheWords.nextQue();
					}, 2000);
			}
			else
			{
				document.getElementById("ansImg").src=Utils.path+"images/wrong.png";
				if(MakeTheWords.attempQue==0)
					document.getElementById("audio").src=Utils.path+'sounds/Instructions/Try_Again!_Aditi.mp3';
				else document.getElementById("audio").src=Utils.path+'sounds/Instructions/wrong_answer!_Aditi.mp3';
				MakeTheWords.timesetansimg=setTimeout(function() {
				document.getElementById('ansImg').style.display='none';
				$(".pointer").css("pointer-events","auto");
				document.getElementById("alphabets").style.pointerEvents="auto";
				}, 2000);
			}
			document.getElementById("audio").play();
			MakeTheWords.attempQue++;
			if(MakeTheWords.attempQue==2)
			{
				document.getElementById("nextButton").style.pointerEvents='none';
				MakeTheWords.setTimeToQue=setTimeout(function() {
				MakeTheWords.nextQue();
				}, 2000);
			}
		}
	}
	else
	{
		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.setTimeToQue);
	clearInterval(MakeTheWords.setTime);
	clearTimeout(MakeTheWords.timeset);
	clearTimeout(MakeTheWords.secondInstructionTimer);
	document.getElementById("alphabets").style.pointerEvents="auto";
	document.getElementById("ansDiv").style.pointerEvents="auto";
	document.getElementById("soundDiv").style.pointerEvents='auto';
		if(scoreFlag==true)
			MakeTheWords.scoreFunction();
		else 
		{
			scoredMarks=-1;
			MakeTheWords.scoreFunction();
		}
	MakeTheWords.selectedAlphabet="";
	MakeTheWords.attempQue=0;
	$(".flag").removeClass('effect');
	if(MakeTheWords.flag==false)
		MakeTheWords.nextcount++;
	MakeTheWords.index++;
	document.getElementById('ansImg').style.display='none';
	if(MakeTheWords.gameType=="learn")
	{
		if(MakeTheWords.nextcount==0 && MakeTheWords.selectVowel<5)			//vowel of undefined error 
		{
			if(MakeTheWords.selectVowel==5 && MakeTheWords.index==3)
			{
				MakeTheWords.flag=false;
				document.getElementById("ansDiv").innerHTML="";
				MakeTheWords.showQue();
			}
			if(MakeTheWords.index==3)
			{
				document.getElementById("rhymingWordDiv").innerHTML="";
				MakeTheWords.index=0;
				MakeTheWords.createWordsDiv();
				MakeTheWords.populateRandomQue();
			//	MakeTheWords.optionCnt=-1;
				MakeTheWords.displaywords();
				document.getElementById("gamePage").style.display="none";
				document.getElementById("readWordPage").style.display="block";
			}
			else
			{
			document.getElementById("ansDiv").innerHTML="";
			MakeTheWords.showQue();
			}
		}
		else
		{
			if(MakeTheWords.selectVowel==5 && MakeTheWords.index==3)
			{
				MakeTheWords.flag=false;
				document.getElementById("ansDiv").innerHTML="";
				MakeTheWords.showQue();
			}
			else
			{	
				if(MakeTheWords.nextcount==5)
					MakeTheWords.gameover();
				else
				{
					document.getElementById("ansDiv").innerHTML="";
					MakeTheWords.showQue();
				}
			}
		}
	}
	else
	{
		if(MakeTheWords.nextcount==0)
		{
			if(MakeTheWords.index==15)
			{
				MakeTheWords.flag=false;
				document.getElementById("ansDiv").innerHTML="";
				MakeTheWords.showQue();	
			}
			else
			{
			document.getElementById("ansDiv").innerHTML="";
			MakeTheWords.showQue();
			}
		}	
		else
		{
			if(MakeTheWords.nextcount==5)
				MakeTheWords.gameover();
			else
			{
				document.getElementById("ansDiv").innerHTML="";
				MakeTheWords.showQue();
			}
		}
	}
}
MakeTheWords.displayDefultAns=function()				//display Ans when time finish
{
	if(MakeTheWords.setTime)
	{
		clearInterval(MakeTheWords.setTime);
		MakeTheWords.setTime=null;
	}
	for(var j=0;j<$("#ansDiv").children().length-1;j++)
	{	
	var ans=document.getElementById("wordsdiv"+j).getAttribute("alphabetdata");
	document.getElementById("wordsdiv"+j).innerHTML=ans;
	document.getElementById("wordsdiv"+(j)).style.setProperty("color","");
	}
}
MakeTheWords.playSound=function()						//to play sound
{	
	if(MakeTheWords.flag==true)
		document.getElementById("audio").src=Utils.path+'sounds/'+MakeTheWords.QueArray[MakeTheWords.index].sound;
	else
	{
		document.getElementById("audio").src=Utils.path+'sounds/'+MakeTheWords.totalQueArray[MakeTheWords.nextcount].sound;
	}
	document.getElementById("audio").play(); 
} 
MakeTheWords.gameover=function()					//game over function
{
	document.getElementById("audio").pause();
	document.getElementById("coverPage").style.display="none";
	document.getElementById("gamePage").style.display="none";
	document.getElementById("finalPage").style.display="block";
	document.getElementById("progressBarDiv").style.visibility="hidden";
	document.getElementById('gameOver').innerHTML=MakeTheWords.hardcodedData.message2;
	for(i=0;i<Object.keys(MakeTheWords.AcknowledgementPageData).length;i++)
	{
		div=document.createElement('div');
		div.className="fontClass firstLetter col-xs-12 col-sm-12 col-md-12 col-lg-12";
		div.innerHTML=Object.keys(MakeTheWords.AcknowledgementPageData)[i]+" : "+Object.values(MakeTheWords.AcknowledgementPageData)[i];
		acknowledgementDiv.appendChild(div);
	}
	div=document.createElement('div');
	div.className="fontClass firstLetter col-xs-12 col-sm-12 col-md-12 col-lg-12";
	div.innerHTML=MakeTheWords.hardcodedData['createdOn'];
	acknowledgementDiv.appendChild(div);
	document.getElementById("acknowledgementDiv").style.display="none";
}
MakeTheWords.returnback=function()			//return to previous page (reload)
{	
	document.getElementById("audio").pause();
	clearTimeout(MakeTheWords.skipTimer);
	clearTimeout(MakeTheWords.optionTimer);
	clearTimeout(MakeTheWords.instructionTimer);
	clearTimeout(MakeTheWords.secondInstructionTimer);
    clearInterval(MakeTheWords.setTime);
	clearTimeout(MakeTheWords.setTimeToQue);
	if(scoreFlag==true)
		MakeTheWords.scoreFunction();
		
		location.reload(true);
}
MakeTheWords.showCredits=function()			//show credits on click credit button
{
	document.getElementById("acknowledgementDiv").style.display="block";
}