					//22th Oct 2018
var ShowMe={};
var Utils={};
Utils.Path='';
Utils.mobileDeviceFlag=false;
var questionId=0,startTime=0,scoredMarks=0,resId=0,totalMarks=10,noOfAttemptedCnt=0;
ShowMe.skipedQ=0;
ShowMe.homeFlag=null;
ShowMe.alreadyShownObject=[];
ShowMe.tempArr=[];
//function for loader
$(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(""); 
	setTimeout(function(){
		document.getElementById('coverpage').style.display="block";
		document.getElementById('gamepage').style.display="none";
		document.getElementById('endpage').style.display="none";
		document.getElementById("homeImg").style.display = "none";
		ShowMe.setImages();
		ShowMe.init();
	},300);
});
ShowMe.setImages=function()
{
	document.body.style.backgroundImage="url("+Utils.Path+ShowMe.coverImage+")";
	document.getElementById("homeImg").src=Utils.Path+"images/Home.png";
	document.getElementById("logoImg").src=Utils.Path+"images/logo.png";
	document.getElementById("playImg").src=Utils.Path+"images/Play.png";
	document.getElementById("nextImage").src=Utils.Path+"images/Next.png";
	document.getElementById("replayImage").src=Utils.Path+"images/Replay.png";
	document.getElementById("sound").src=Utils.Path+"images/Sound.png";
}
ShowMe.init=function()
{
	ShowMe.randomLevel=Math.floor(Math.random()*ShowMe.data.length);
	
}
ShowMe.playGame=function()
{
	document.getElementById('coverpage').style.display="none";
	document.getElementById('gamepage').style.display="none";
	document.getElementById("homeImg").style.display = "block";
	var middlepage=document.getElementById("middlepage");
	ShowMe.createDivs(optDiv,"level",'',4,2,1);
	ShowMe.createDivs(showMePageDiv,"picture","pointerClass",1,4,4);
}
//creates No. of Divs
ShowMe.createDivs=function(parentDiv,id,className,no,temp,offset)
{
	var ShowMeDiv,pictureDiv,img;
	for(var j=0;j<no;j++)
	{
		pictureDiv= document.createElement("div");
		pictureDiv.setAttribute("id",id+j); 
		pictureDiv.setAttribute("class",className+"  noPadding col-md-"+temp+" col-xs-"+temp+" col-lg-"+temp+" col-sm-"+temp+" col-xs-offset-"+offset+" col-xs-offset-"+offset +" col-xs-offset-"+offset+" col-xs-offset-"+offset); 
		parentDiv.appendChild(pictureDiv);

		img=document.createElement('img');
		img.setAttribute("id",id+"img"+j); 
		img.setAttribute("class","noPadding borderClass img-responsive col-lg-12 col-md-12 col-xs-12 col-sm-12");
		pictureDiv.appendChild(img);
		if(parentDiv==optDiv)
		{
			img.setAttribute("src",Utils.Path+"images/"+ShowMe.data[ShowMe.randomLevel].list[j].img);
			$(img).data("ans",j);
			img.setAttribute("onclick","ShowMe.selectLevel(this)"); 
			para= document.createElement("p");
			para.setAttribute("id","para"+j);
			para.setAttribute("class","menuNames noPadding text-center col-lg-12 col-md-12 col-xs-12 col-sm-12");
			para.innerHTML=ShowMe.data[ShowMe.randomLevel].list[j].name;
			pictureDiv.appendChild(para);
		}
	}
}
ShowMe.selectLevel=function(element)
{
	ShowMe.skipedQ=0;
	noOfAttemptedCnt=0;
	ShowMe.alreadyShownObject=[];
	ShowMe.levelNumber=$(element).data("ans");
	ShowMe.tempArr=JSON.parse(JSON.stringify(ShowMe.data[ShowMe.randomLevel].list[ShowMe.levelNumber].data));
	ShowMe.showObjects();
}
//Show Objects on the screen
ShowMe.showObjects=function()
{
	var d,imgCnt=0;
	ShowMe.homeFlag="showlevel";
	d=new Date();
	document.getElementById('middlepage').style.display="none";
	document.getElementById('gamepage').style.display="block";
	startTime=d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();document.getElementById("correctWrongDiv").style.visibility="hidden";
	ShowMe.uniqueImgArr=[];
	ShowMe.uniqueImgArr=populate(ShowMe.tempArr,ShowMe.uniqueImgArr,ShowMe.hardcorded.number);
	
		$("#pictureimg0").prop("src",Utils.Path+"images/"+ShowMe.tempArr[ShowMe.uniqueImgArr[0]].imgName);
		$("#pictureimg0").data("ans",ShowMe.tempArr[ShowMe.uniqueImgArr[0]].name);
		
	ShowMe.uniqueQue= Math.floor(Math.random()*(ShowMe.uniqueImgArr.length));
	while($.inArray(ShowMe.uniqueImgArr[ShowMe.uniqueQue].name,ShowMe.alreadyShownObject)!==-1)
		ShowMe.uniqueQue= Math.floor(Math.random()*(ShowMe.uniqueImgArr.length));
	ShowMe.alreadyShownObject.push(ShowMe.tempArr[ShowMe.uniqueImgArr[ShowMe.uniqueQue]].name);
	console.log(ShowMe.tempArr[ShowMe.uniqueImgArr[ShowMe.uniqueQue]].name);
	ShowMe.playInstruction();	
	
}
ShowMe.playInstruction=function()
{
	var duration;
	document.getElementById('playSound').pause();
	//$(".pointerClass").css("pointer-events","none");
	console.log(ShowMe.tempArr[ShowMe.uniqueImgArr[ShowMe.uniqueQue]].sound);
	document.getElementById('playSound').src=Utils.Path+'sounds/'+ShowMe.tempArr[ShowMe.uniqueImgArr[ShowMe.uniqueQue]].sound;
	document.getElementById('playSound').play();
	questionId=parseInt(ShowMe.tempArr[ShowMe.uniqueImgArr[ShowMe.uniqueQue]].questionId);
	
}
//Check Answer
/* ShowMe.checkAnswer=function(element)
{	
	var randomSound;
	noOfAttemptedCnt++;
	document.getElementById("correctWrongDiv").style.visibility="visible";
	if(($(element).data('ans')==ShowMe.tempArr[ShowMe.uniqueImgArr[ShowMe.uniqueQue]].name))
	{
		scoredMarks=10;
		document.getElementById('correctWrongImg').src=Utils.Path+"images/correct.png";
		randomSound=Math.floor(Math.random()*(ShowMe.correctAns.length));
		document.getElementById('playSound').src=Utils.Path+'sounds/'+ShowMe.correctAns[randomSound];
		document.getElementById('playSound').play();
		$(".pointerClass").css("pointer-events","none");
		ShowMe.nextQ=setTimeout(function(){
			ShowMe.nextStory();
		},2000);
	}
	else
	{
		scoredMarks=0;
		document.getElementById('correctWrongImg').src=Utils.Path+"images/wrong.png";
		randomSound=Math.floor(Math.random()*(ShowMe.wrongAns.length));
		document.getElementById('playSound').src=Utils.Path+'sounds/'+ShowMe.wrongAns[randomSound];
		document.getElementById('playSound').play();
		setTimeout(function(){
			document.getElementById("correctWrongDiv").style.visibility="hidden";
		},1500);
	}
	if(noOfAttemptedCnt==1)
	{
		console.log(resId,questionId,scoredMarks,totalMarks,ShowMe.randomLevel,startTime);
		if(Utils.mobileDeviceFlag)
			Android.addScore(resId,questionId,scoredMarks,totalMarks,ShowMe.randomLevel,startTime);
	}
} */
//Load Next Question Of The Same Story
ShowMe.nextStory=function()
{
	ShowMe.skipedQ++;
	noOfAttemptedCnt=0;
	clearTimeout(ShowMe.instruction);
	clearTimeout(ShowMe.myTimer);
	clearTimeout(ShowMe.nextQ);
	document.getElementById('playSound').pause();
	ShowMe.tempArr.splice(ShowMe.uniqueImgArr[ShowMe.uniqueQue],1);	
	if(ShowMe.skipedQ==5)
	{
		//ShowMe.homeFlag=null;
		document.getElementById("gamepage").style.display="none";
		document.getElementById('acknowledgementDiv').style.display="block";
		$('#endpage').show();
		document.getElementById('conceptDiv').innerHTML=ShowMe.hardcorded.ConceptBy;
		document.getElementById('artWorkDiv').innerHTML=ShowMe.hardcorded.ArtWork;
		document.getElementById('audioRecordingDiv').innerHTML=ShowMe.hardcorded.AudioRecording;
		document.getElementById('musicgDiv').innerHTML=ShowMe.hardcorded.Music;
		document.getElementById('developerNameDiv').innerHTML=ShowMe.hardcorded.DevelopedBy;
	}
	else
		ShowMe.showObjects(ShowMe.levelNumber);
}
ShowMe.callHome=function()
{
	ShowMe.resetAll();
	if(ShowMe.homeFlag=="showlevel")
	{
		document.getElementById('middlepage').style.display="block";
		document.getElementById('gamepage').style.display="none";
		document.getElementById('endpage').style.display="none";
		ShowMe.homeFlag=null;
	}	
	else
		location.reload(true);
}
ShowMe.playAgain=function()
{
	ShowMe.resetAll();
	document.getElementById('endpage').style.display="none";
	noOfAttemptedCnt=0;
	ShowMe.skipedQ=0;
	ShowMe.alreadyShownObject=[];
	ShowMe.tempArr=[];
	ShowMe.tempArr=JSON.parse(JSON.stringify(ShowMe.data[ShowMe.randomLevel].list[ShowMe.levelNumber].data));
	ShowMe.showObjects(ShowMe.levelNumber);
}
ShowMe.resetAll=function()
{
	document.getElementById('playSound').pause();
	clearTimeout(ShowMe.instruction);
	clearTimeout(ShowMe.myTimer);
	clearTimeout(ShowMe.nextQ);
}