var YouSaid={};
YouSaid.recordFlag=0;//record flag
YouSaid.recordedSound=0;//recorded flag
YouSaid.recordCounter=0;//total records
var Utils={};
Utils.Path='';
Utils.mobileDeviceFlag=false;
$(document).ready(function()
{
	$(".se-pre-con").fadeOut("slow");
	if(navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))
		Utils.mobileDeviceFlag=true;
	
	
	
	setTimeout(function()
	{
		document.body.style.backgroundImage="url(images/BG.png)";
		document.getElementById('coverpage').style.display="block";
		document.getElementById('gamepage').style.display="none";
		document.getElementById('home').style.display="none";
		document.getElementById('sound').style.display='none';
		YouSaid.setImage();
	},200);
});
//play game
YouSaid.playGame=function()
{
	document.body.style.backgroundImage="url('images/BG.png')";
	document.getElementById('gamepage').style.display="block";
	document.getElementById('coverpage').style.display="none";
	document.getElementById('home').style.display="block";
	document.getElementById('sound').style.display='block';
	document.getElementById('recordImg').style.display='block';
	document.getElementById('checkAnsImg').style.display='block';
	document.getElementById("checkAnsDiv").style.visibility = "hidden";
	document.getElementById("playSoundBack").src="sounds/backmusic.mp3";
	document.getElementById("playSoundBack").loop=true;
	document.getElementById("playSoundBack").play();
}
// set Images//
YouSaid.setImage=function()
{
	document.getElementById('logo').src="images/logo.png";
	document.getElementById('play').src="images/Play.png";
	document.getElementById('home').src="images/Home.png";
	document.getElementById('sound').src="images/Sound.png";
	document.getElementById('recordImg').src="images/Record.png";
	document.getElementById('checkAnsImg').src="images/Listen.png";
}
// on click of record
YouSaid.recordAns=function()
{
	/* document.getElementById("playSoundBack").pause(); */
	var record='';
	//document.getElementById('playSound').pause();
	clearTimeout(YouSaid.soundTimer);
	if(YouSaid.recordFlag==0)
	{
		document.getElementById("checkAnsDiv").style.visibility = "hidden";
		//document.getElementById("soundDiv").style.pointerEvents = "none";
		YouSaid.recordFlag=1;
		YouSaid.recordedSound=1
		document.getElementById('recordImg').src="images/Stop.png";
		record='myRecording_'+YouSaid.recordCounter+'.mp3';
		if(Utils.mobileDeviceFlag)
			Android.startRecording(record);
	}
	else
	{
		if(Utils.mobileDeviceFlag)
			Android.stopRecording();
		document.getElementById('playSound').pause();
		YouSaid.recordFlag=0;
		document.getElementById("checkAnsDiv").style.visibility = "visible";
		//document.getElementById("soundDiv").style.pointerEvents = "auto";
		document.getElementById("checkAnsDiv").style.pointerEvents = "auto";
		document.getElementById('recordImg').src="images/Record.png";
	}
	/* document.getElementById("playSoundBack").play();*/
} 
//check answer
YouSaid.YourAns=function()
{
	
	if(YouSaid.recordedSound)
	{
		alert("true");
		YouSaid.recordedSound=0;
		document.getElementById('checkAnsImg').src="images/Stop.png";
		document.getElementById("recordDiv").style.pointerEvents = "none";
	//	document.getElementById("soundDiv").style.pointerEvents = "none";
		document.getElementById('playSound').pause();
		setTimeout(function()
		{
			duration=document.getElementById("playSound").duration;
			setTimeout(function()
			{
				if(Utils.mobileDeviceFlag)
					Android.audioPlayerForStory('/'+'myRecording_'+YouSaid.recordCounter+'.mp3',null);
				document.getElementById("playSoundBack").pause();
			},duration*1000);	
		},150);
	}
	else if(YouSaid.recordedSound==0)
	{
		YouSaid.recordedSound=1;
		document.getElementById('playSound').pause();
		document.getElementById('checkAnsImg').src="images/Listen.png";
		document.getElementById("recordDiv").style.pointerEvents = "auto";
		document.getElementById("soundDiv").style.pointerEvents = "auto";
	}
	document.getElementById("playSoundBack").play();
}
