var dhoom={};
var Utils={},startTime,scoredMarks,totalMarks=10,mobileDeviceFlag;

dhoom.vehiclePosition= {0 : 'myCopRunning', 1 : 'myCopCycle', 2 : 'myCopHorse', 3 : 'myCopBike', 4 : 'myCopCopter'};
//dhoom.vehiclePosition2= { 0 : 'myCopRunning', 1 : 'myCopCycle2', 2 : 'myCopHorse2', 3 : 'myCopBike2', 4 : 'myCopCopter2'};

$( document ).ready(function() {
   	// check whether it is Tablet or Desktop
	   if ((navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) && !(window.location.href.includes('http')))
 	{	Utils.Path=Android.getMediaPath("Dhoom");  
		mobileDeviceFlag=true;
	}
	else
		Utils.Path='';

	$(".se-pre-con").fadeOut("slow");
	setTimeout(function()
	{
		dhoom.init();
	},100);
	
});

dhoom.init=function()
{
	$("#coverPage").show();
	$("#gameVideo,#playTopSection,#gamePlayButton,#copWinPage,#criminalWinPage,#midHide1Page").hide();
	$('#play').prop("src",Utils.Path+"Images/play.png");
	document.body.style.backgroundImage="url("+Utils.Path+"Images/BodyBG.jpg)";
}

dhoom.playGame=function()
{
	$("#coverPage").hide();
	$("#gameVideo,#playTopSection,#gamePlayButton,#copWinPage,#criminalWinPage,#midHide1Page").show();
	document.body.style.backgroundImage="url("+Utils.Path+"Images/BodyBG2.jpg)";
	dhoom.playIntroVideo();
	dhoom.play();
}
// Run After Video
dhoom.play=function()
{
	dhoom.setImages();
	dhoom.setEvents();
	dhoom.initialHiddenDivs();
	dhoom.initializeVars();
	dhoom.initialPosDivs();
	dhoom.playBackgroundAudio(0);
    dhoom.setLabels();
  	//$("#home").css("display","none");
	$("#home").css("visibility","hidden");
    dhoom.rotateScore(90);
};

// Set OnClick Events
dhoom.setEvents=function()
{
	if(dhoom.replayClick!=1)
		dhoom.playIntroVideo();
	$("#home").on('click',dhoom.playIntroVideo);
	$(".playButton").on('click', dhoom.startGame);
	$("#home,.myReplayBtn").on('click', dhoom.replayClick);
	$(".ansBtns").on('click', dhoom.checkAnswer);
	$(".ansBtns").prop('disabled',true);
};

// Call on Home Button Click
dhoom.replayClick = function(){
	$("#home,.myReplayBtn").prop('disabled',true);
	dhoom.replayClick = 1;
	$('.GameDiv').hide();
	dhoom.playBackgroundAudio(0);
	$('#gamePlayButton').show();
	$(".move,#myThief").css('left','-50%');
	document.getElementById('question').innerHTML = "";
	dhoom.initializeVars();
	dhoom.initialPosDivs();
	dhoom.switchBackgrounds();

	dhoom.rotateScore(50);

	$('.CopWin').hide();$('.CriminalWin').hide();
	$('#roadImage2,#frameDivider,#equation,#thiefMarker').show();
	$('#roadImage').css("width","48vw");
	$(".mainBg").css("background-image", "");
	//$("#home").css("visibility","hidden");
	dhoom.level5Flag=0;
};

// Call on Play button Click
dhoom.startGame= function(){
	$("#home").css("visibility","hidden");
	setTimeout(function(){
			$("#home").css("visibility","visible");
	},5000);
	$("#logo").on('click',dhoom.logoCall);
	$('#gamePlayButton').hide();
	$('.forIntroHide,.endHide,#topSection1').show();
	dhoom.playBackgroundAudio(1);
	dhoom.enterCharacters();
	dhoom.thiefToNextWindow();
};
//Set Images
dhoom.setImages=function(){
	$('#pLogo').prop("src",Utils.Path+"Images/plogo.png");
    $('#myHome').prop("src",Utils.Path+"Images/homeIcon.png");
     $('.copRunningImg').prop("src",Utils.Path+"Images/CopRunning.gif");
    $('.copCycleImg').prop("src",Utils.Path+"Images/CopCycle.gif");
    $('.copHorseImg').prop("src",Utils.Path+"Images/CopHorse.gif");
    $('.copBikeImg').prop("src",Utils.Path+"Images/CopBike.gif");
    $('.copCopterImg').prop("src",Utils.Path+"Images/CopCopter.gif");
    $('.thiefLookingAhead').prop("src",Utils.Path+"Images/ThiefBike.gif");
    $('.thiefLookingBehind').prop("src",Utils.Path+"Images/ThiefBike2.gif");
    $('.mapBGImg').prop("src",Utils.Path+"Images/mapBG.jpg");
    $('.copMarkerImg').prop("src",Utils.Path+"Images/copMarker.png");
    $('.thiefMarkerImg').prop("src",Utils.Path+"Images/thiefMarker.png");
    $('.airportMarkerImg').prop("src",Utils.Path+"Images/airportMarker.png");
    $('.PrisonMarkerImg').prop("src",Utils.Path+"Images/PrisonMarker.png");
    $('.copImg').prop("src",Utils.Path+"Images/Cop.png");
    $('.criminalImg').prop("src",Utils.Path+"Images/Criminal.png");
    $('.sadCopImg').prop("src",Utils.Path+"Images/sadCop.png");
    $('.happyCriminalImg').prop("src",Utils.Path+"Images/happyCriminal.png");
    $('#frameDivider').css("background-image", "url("+Utils.Path+"Images/BodyBG2.jpg");
    $('#mapOuter').prop("src",Utils.Path+"Images/mapBG.jpg");
    $('.border').prop("src",Utils.Path+"Images/divBG.jpg");
    $('#roadRotate').css("background-image", "url("+Utils.Path+"Images/RoadBg0.gif)");
    $('#roadRotate2').css("background-image", "url("+Utils.Path+"Images/RoadBg1.gif)");
};

dhoom.logoCall= function(){
	window.location.reload();
};

// Run On Document load
dhoom.playIntroVideo = function(){
	var timeOut=13000; //12000;
    $('#gamePlayButton').hide();
	$("#gameVid").show();
	$('#gameVideo').show();
	if(mobileDeviceFlag==true)
			Android.showVideo("Media/videos/DhoomIntro.mp4",null);
		else
			$('#gameVid').prop("src","videos/DhoomIntro.mp4");
			//video.play();
	setTimeout(function(){
		$('#gameVideo').hide();
		$('#gamePlayButton').show();
	},timeOut);
};
// Hide divs on starting
dhoom.initialHiddenDivs= function(){
	$("#home").css("display","block");
	$('#gamePlayButton,.forIntroHide,.CopWin,.CriminalWin,#mapOuter,.thiefLookingBehind').hide();
};

// init Variables
dhoom.initializeVars=function(){
	dhoom.level5Flag=0;
	dhoom.initialCopLeftPosition=2;
	dhoom.levelQueAttemptCounter=0;
	dhoom.queAttemptCounter=0;
	dhoom.score=0;
	dhoom.questionNumber=0;
	dhoom.currentLevel=0;
	dhoom.thiefWhilee = 0;
	dhoom.correctAnsCounter=0;
};

dhoom.initialPosDivs= function(){
	$(".move").css('left','-50%');
 	$("#copMarker").css('top','95%' , 'left','80%');
	$("#thiefMarker").css('top','50%' , 'left','80%');
	$("#airportMarker").css('top','15%' , 'left','-160%');
};

dhoom.setLabels= function(){
	$('.instructionsLBL').html(""+dhoom.Labels.instructionsLBL);
	$('.ModalInstructions').html(""+dhoom.Labels.ModalInstructions);
	$('.lblInstructionsBtn').html(""+dhoom.Labels.InstructionsBtn);
	$('.lblPlayBtn').html(""+dhoom.Labels.PlayBtn);
	$('.CloseBtn').html(""+dhoom.Labels.CloseBtn);
	$('.scoreLbl').html(""+dhoom.Labels.scoreLbl);
	$('.replayLbl').html(""+dhoom.Labels.replayLbl);
	$('.gameName').html(""+dhoom.Labels.gameName);
};

dhoom.playBackgroundAudio=function(play){
		if(play == 1){
			document.getElementById('gameSoundBg').src = Utils.Path+'audio/BackgroundTrack.mp3';
			document.getElementById('gameSoundBg').loop=true;
			document.getElementById('gameSoundBg').play();		
		}
	else{
		document.getElementById('gameSoundBg').src ='';
		document.getElementById('gameSoundBg').pause();
	}
};

dhoom.enterCharacters=function(){
	$(".mainBg").css("background-image", "url("+Utils.Path+"Images/BodyBG.jpg)");
	setTimeout(function(){
		$("#"+dhoom.vehiclePosition[dhoom.currentLevel]).animate({
			left: dhoom.initialCopLeftPosition+"%"
		},2000);
		$("#myThief").animate({
			left: 20+"%"
		},1500);
		$("#myCopRunning").animate({
			left: 8+"%"
		},2000);
	}, 500);
};

// Call on 2/3 Ans are Correct
dhoom.switchBackgrounds=function(){
	dhoom.chorbg=dhoom.currentLevel+1;
	document.getElementById("roadRotate2").style.backgroundImage = "url("+Utils.Path+"Images/RoadBg"+dhoom.chorbg+".gif)";
	document.getElementById("roadRotate").style.backgroundImage = "url("+Utils.Path+"Images/RoadBg"+dhoom.currentLevel+".gif)";
};

// Move Thief to nxt Window on Starting
dhoom.thiefToNextWindow=function(){
		var moveVehicle=setTimeout(function(){
		dhoom.playGameSound(Utils.Path+"audio/ThiefBike.mp3");

		dhoom.thiefLooking();
		setTimeout(function(){
			if(dhoom.thiefWhilee == 0)
			{
				dhoom.thiefWhilee = 1;
				$("#myThief").css({'-webkit-transform' : 'rotate(-30deg)','-moz-transform' : 'rotate(-30deg)','-ms-transform' : 'rotate(-30deg)','transform' : 'rotate(-30deg)'});
			}
			$("#myThief").animate({
				left: 65+'%',
			},1200);
			setTimeout(function(){
				$("#myThief").css({'-webkit-transform' : 'rotate(0deg)','-moz-transform' : 'rotate(0deg)','-ms-transform' : 'rotate(0deg)','transform' : 'rotate(0deg)'});
			},800);
		},700);
	
	/*** Call to Generate Question */
		setTimeout(function(){
			dhoom.generateQuestion();
			$('#BottomSection').show();
		},2200);
	},3000);
};

dhoom.thiefLooking=function(){
	$('.thiefLookingAhead').hide();	
	$('.thiefLookingBehind').show();
	setTimeout(function(){
		$('.thiefLookingBehind').hide();
		$('.thiefLookingAhead').show();
	},1000);
};

dhoom.generateQuestion= function(){
     var i=0, len;	
	/*--------X--------X-------- Level Check --------X--------X--------*/
	dhoom.checkLevel();
	dhoom.getQuestionData();

	/*--------X--------X-------- Score And Position End Part --------X--------X--------*/
	
	//*--------X--------X-------- Generating Questions --------X--------X--------*/

	dhoom.firstNum= dhoom.lowerBound.match(/[0-9]+/g).map(function(n) {
		return +(n);
	});

	dhoom.secondNum= dhoom.upperBound.match(/[0-9]+/g).map(function(n) {
		return +(n);
	});
	
	dhoom.getRandomNumbers();
	//console.log("N1 : "+dhoom.firstRandomNumber+" N2 : "+dhoom.secondRandomNumber );
 	/*--------X--------X-------- Checking Calculating Answer According to the level --------X--------X--------*/
 	//Call Function According to Level	

	len=dhoom.difficulty[dhoom.currentLevel].quesList[dhoom.questionNumber].format.length;
	dhoom.difficulty[dhoom.currentLevel].quesList[dhoom.questionNumber]["type"](dhoom.firstRandomNumber, dhoom.secondRandomNumber);
	dhoom.displayQuestion = dhoom.tempQues;
	for(i=0; i<len; i++){
		if(dhoom.displayQuestion.includes('_'))
			dhoom.displayQuestion = dhoom.displayQuestion.replace("_", eval(dhoom.difficulty[dhoom.currentLevel].quesList[dhoom.questionNumber].format[i]));
		else
			break;
	}
	/*--------X--------X-------- Displaying The Questions --------X--------X--------*/

	$(".ansBtns").prop('disabled',false);
	//console.log("DA: "+dhoom.displayAnswer + " CA:"+dhoom.correctAns+" ans : "+dhoom.correctAns);
	//console.log("ans : "+dhoom.correctAns);
/*----------------------------------------------------------------------------------------------*/ //$("#currentLevel").html(""+dhoom.currentLevel);
	$("#question").html(dhoom.displayQuestion).addClass('magictime puffIn');
	setTimeout(function(){	$("#question").removeClass('magictime puffIn'); },1000);
	/*--------X--------X-------- Thief Looking Behind and going to next frame --------X--------X--------*/
	dhoom.thiefLooking();
	dhoom.queAttemptCounter++;
};

dhoom.checkLevel= function(){

	if((dhoom.queAttemptCounter > 16) || ((dhoom.currentLevel == 4) && (dhoom.levelQueAttemptCounter > 3)) /**Temp Condi --- > ||(dhoom.score > 75) **/ ) 
		dhoom.playVideosAndEndGame();
	else if ( (dhoom.correctAnsCounter >= 2) &&  (dhoom.levelQueAttemptCounter >=3 ) && (dhoom.currentLevel <4 ))
	{
		dhoom.questionNumber=0;
		dhoom.correctAnsCounter=0;
		dhoom.levelQueAttemptCounter=0;
		dhoom.currentLevel+=1;		
		dhoom.moveCopVehicle();

		if (dhoom.currentLevel<4)
			dhoom.switchBackgrounds();
 		else if (dhoom.currentLevel==4)
			dhoom.mergAndShowBackgrounds();
	}
}

dhoom.mergAndShowBackgrounds = function(){
	//---------- Merging Backgrounds ----------//
	if( (dhoom.currentLevel == 4) && (dhoom.level5Flag == 0) ){
		document.getElementById("roadRotate2").style.backgroundImage = "url("+Utils.Path+"Images/RoadBg"+dhoom.currentLevel+".gif)";
		$('#roadImage2,#frameDivider').hide();
		$('#roadImage,#roadRotate').css("width","100%");
		$('#roadRotate').css("background-size","100% 47vh");
		dhoom.level5Flag=1;
	}
	if( (dhoom.currentLevel == 3) && (dhoom.level5Flag == 1) ){
		dhoom.initialCopLeftPosition=3;
		setTimeout(function(){
			$('#roadImage2,#frameDivider').show();
			$('#roadImage').css("width","45%");
			dhoom.level5Flag=0;
		},1500);
	}
	else{
		dhoom.chorbg=dhoom.currentLevel+1;
		document.getElementById("roadRotate2").style.backgroundImage = "url("+Utils.Path+"Images/RoadBg"+dhoom.chorbg+".gif)";
	}
	document.getElementById("roadRotate").style.backgroundImage = "url("+Utils.Path+"Images/RoadBg"+dhoom.currentLevel+".gif)";

	//document.getElementById("chaseCam").style.backgroundImage = "url("+Utils.Path+"Images/RoadBg"+dhoom.currentLevel+".gif)";
	//-----------------------------------------//
}


dhoom.playVideosAndEndGame=function(){
	var winFlag=0, vidTimeout=7500;

	//$("#home").hide();
	$("#home").css("visibility","hidden");
	$(".endHide").hide();
	$('#gameVideo').show();
	$(".mainBg").css("background-image", "url("+Utils.Path+"Images/BodyBG.jpg)");
	if( (dhoom.score > 90) )
		winFlag=1;
	else
		vidTimeout=8800; // 8800;

    $("#airportMarker").css('left','20%');

	if(winFlag == 1){
    	if(mobileDeviceFlag)
			Android.showVideo("Media/videos/CopWin.mp4",null);
		else
			$('#gameVid').prop("src","videos/CopWin.mp4");
		setTimeout(function(){
			dhoom.hideDivAfterResult();
			$("#mapOuter").animate({
				height: "90%",
				width: "25%"
			},100);

			$("#copMarker").animate({
				top: 45+'%'
			},1000);

			$("#thiefMarker").animate({
				top: 40+'%'
			},1000);

			setTimeout(function(){
				$("#thiefMarker").animate({
					left: 98+'%',
					top: 14+'%'
				},1000);
			},1800);
			setTimeout(function(){
				$("#copMarker").animate({
					left: 98+'%',
					top: 50+'%'
				},1000);
			},1800);

			setTimeout(function(){
				$('.GameDiv').hide();
				$('.CopWin').show();
				$('#test1').html(""+dhoom.score);
                $(".mainBg").css("background-image", "url("+Utils.Path+"Images/BodyBG3.jpg)");
			},4200);
		},vidTimeout);
	}
	else{
    	if(mobileDeviceFlag)
			Android.showVideo("Media/videos/ThiefWin.mp4",null);
		else
			$('#gameVid').prop("src","videos/ThiefWin.mp4");
		setTimeout(function(){

			dhoom.hideDivAfterResult();
			$("#mapOuter").animate({
				height: "90%",
				width: "25%"
			},100);

			setTimeout(function(){
				$("#thiefMarker").animate({
					top: 13+'%',
					left: 10+'%'
				},1000);
				$("#copMarker").animate({
					top: 30+'%'
				},600);
			},2000);

			setTimeout(function(){$("#thiefMarker").hide();},3200);
			
			setTimeout(function(){
				$("#airportMarker").animate({
					left: 160+'%',
					top: -60+'%'
				},2000);
			},3800);
			setTimeout(function(){
				$('.GameDiv').hide();
				$('.CriminalWin').show();
                $(".mainBg").css("background-image", "url("+Utils.Path+"Images/BodyBG3.jpg)");
				$('#test2').html(""+dhoom.score);
			},5800);
		},vidTimeout);
	}
};

// Call From dhoom.playVideosAndEndGame
dhoom.hideDivAfterResult=function(){
	$('#equation,#BottomSection').hide();
	$('#gameVideo').hide();
	$('#mapOuter').show();
	$("#mapOuter").css("marginLeft","25%");
    $(".mainBg").css("background-image", "url("+Utils.Path+"Images/BodyBG.jpg)");
}

dhoom.getQuestionData = function(){
    var d=new Date();
   	startTime=d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();    

	var levelQueCnt=dhoom.difficulty[dhoom.currentLevel].quesList.length;
	dhoom.questionNumber = Math.floor((Math.random() * levelQueCnt ) + 0);
	if( dhoom.questionNumber == dhoom.prevQuestion)
		dhoom.getQuestionData();
	else
	{	
		dhoom.tempQues=dhoom.difficulty[dhoom.currentLevel].quesList[dhoom.questionNumber].ques;
		dhoom.lowerBound=dhoom.difficulty[dhoom.currentLevel].quesList[dhoom.questionNumber].firstRange;
		dhoom.upperBound=dhoom.difficulty[dhoom.currentLevel].quesList[dhoom.questionNumber].secondRange;
		dhoom.prevQuestion = dhoom.questionNumber;
	}	
};

dhoom.getRandomNumbers= function(){	
	var tempRandomNum1,tempRandomNum2,randomPrevious1,randomPrevious2,shapeName,angleName,primeArray;
	dhoom.forDisplayAnswer = Math.floor((Math.random() * 2) + 0);
//	dhoom.forDisplayAnswer = 1;

	tempRandomNum1 = Math.floor((Math.random() * (dhoom.firstNum[1] - dhoom.firstNum[0])) + dhoom.firstNum[0] );
	tempRandomNum2 = Math.floor((Math.random() * (dhoom.secondNum[1] - dhoom.secondNum[0])) + dhoom.secondNum[0] );

	if(dhoom.currentLevel == 0 && dhoom.questionNumber == 5){
		primeArray=[2,3,5,7,11];
		tempRandomNum1 = primeArray[tempRandomNum1];
		tempRandomNum2 = tempRandomNum1 *2;
	}
	else if(dhoom.currentLevel == 1 ){
		if(dhoom.questionNumber == 0){
			shapeName = dhoom.shapes[tempRandomNum1];
			tempRandomNum2 = shapeName;
		}
		if(dhoom.questionNumber == 1){
			angleName= dhoom.angles[tempRandomNum1];

			if(tempRandomNum1 == 1)
				dhoom.angle= Math.floor((Math.random() * 89) + 1 );
			else if(tempRandomNum1 == 2)
				dhoom.angle= 90;
			else if(tempRandomNum1 == 3)
				dhoom.angle= Math.floor((Math.random() * (179 - 91)) + 91 );
			else
				dhoom.angle= 180;

			tempRandomNum1=dhoom.angle;
			tempRandomNum2=angleName;
		}
	}
	else if(dhoom.currentLevel == 2 && dhoom.questionNumber == 4){
		dhoom.chooseFraction = tempRandomNum1;
		dhoom.fractionName= dhoom.fractions[dhoom.chooseFraction];

		dhoom.randomNumerator= Math.floor((Math.random() * 6) + 1 );
		dhoom.randomDenominator= Math.floor((Math.random() * (15 - 8)) + 8 );

		if(dhoom.chooseFraction == 1){
			tempRandomNum1=dhoom.randomNumerator;
			tempRandomNum2=dhoom.randomDenominator;
		}
		else if(dhoom.chooseFraction == 2){
			tempRandomNum1=dhoom.randomDenominator;
			tempRandomNum2=dhoom.randomNumerator;
		}
		else if(dhoom.chooseFraction == 3){
			dhoom.randomMixedNumber= Math.floor((Math.random() * 10) + 1 );
			tempRandomNum1=dhoom.randomNumerator;
			tempRandomNum2=dhoom.randomDenominator;
		}
	}
	else if(dhoom.currentLevel == 3 ){
		tempRandomNum1 = ((Math.random() * dhoom.firstNum[1]) + dhoom.firstNum[0] ).toFixed(2);
//		if (dhoom.questionNumber == 0 || dhoom.questionNumber == 1){
		var numTemp=Math.floor(tempRandomNum1);
			if(tempRandomNum1 > (numTemp+.45))
				tempRandomNum1 = (Number(tempRandomNum1 - .45)).toFixed(2);

			var tempSecond1=Number("0."+dhoom.secondNum[1]);
			var tempSecond0=Number("0."+dhoom.secondNum[0]);

			dhoom.tempRandomNum3 = (Number((Math.random() * (tempSecond1 - tempSecond0)) + tempSecond0)).toFixed(2);
			tempRandomNum2 = (numTemp+Number(dhoom.tempRandomNum3)).toFixed(2);
	
/*		dhoom.tempRandomNum4 = Math.floor((Math.random() * (dhoom.thirdNum[1] - dhoom.thirdNum[0])) + dhoom.thirdNum[0] );
		dhoom.randomNumerator= Math.floor((Math.random() * 11) + 1 );
		dhoom.randomDenominator= Math.floor((Math.random() * 11) + 1 );
 end cmnt//*/
		if ( (randomPrevious1 == tempRandomNum1) || (randomPrevious2 == tempRandomNum2) || (dhoom.randomPrevious3 == dhoom.tempRandomNum3) )
			dhoom.getRandomNumbers();
	}
	else{
		if ( (randomPrevious1 == tempRandomNum1) || (randomPrevious2 == tempRandomNum2) || (tempRandomNum1 == tempRandomNum2))
			dhoom.getRandomNumbers();
	}

	dhoom.firstRandomNumber = tempRandomNum1;
	dhoom.secondRandomNumber = tempRandomNum2;
	randomPrevious1 = tempRandomNum1;
	randomPrevious2 = tempRandomNum2;

};

// Change Vehicle after 2 /3 Correct Ans
dhoom.moveCopVehicle=function(){

	setTimeout(function(){
		$(".move").css({'-webkit-transform' : 'rotate(0deg)','-moz-transform' : 'rotate(0deg)','-ms-transform' : 'rotate(0deg)','transform' : 'rotate(0deg)'});
	},500);

	$(".move").animate({
		left: -50+'%'
	},1000);
	$("#"+dhoom.vehiclePosition[dhoom.currentLevel]).removeClass('move');
	$("#"+dhoom.vehiclePosition[dhoom.currentLevel]).animate({
			left: dhoom.initialCopLeftPosition+"%"
	},400);
	setTimeout(function(){	
		$("#"+dhoom.vehiclePosition[dhoom.currentLevel]).addClass('move'); 
	},100);
}

// Check the Answer

dhoom.checkAnswer= function()
{
	dhoom.levelQueAttemptCounter++;
	$(".ansBtns").prop('disabled',true);
	if(($(this).hasClass("correctBtn") && (dhoom.correctAns == dhoom.displayAnswer)) || ($(this).hasClass("wrongBtn") && (dhoom.correctAns != dhoom.displayAnswer))){
		dhoom.correctAnsCounter+=1;
		console.log("Correct");
/* 		ansData = genie.getGenieReadyData("Yes", 10);
		genie.addScore(dhoom.questionNumber.toString(), "Maths", dhoom.currentLevel, ansData); */
		scoredMarks=10;
        console.log(dhoom.questionNumber,scoredMarks,totalMarks,dhoom.currentLevel,startTime);
        if(mobileDeviceFlag)
      	  Android.addScore(resId,dhoom.questionNumber,scoredMarks,totalMarks,dhoom.currentLevel,startTime);

		dhoom.playGameSound(Utils.Path+"audio/CorrectAns.mp3");
		setTimeout(function(){
            if(dhoom.currentLevel===0)
            	dhoom.playGameSound(Utils.Path+"audio/RunningFast.mp3");
            else if(dhoom.currentLevel===1)
				dhoom.playGameSound(Utils.Path+"audio/BicycleHorn.mp3");
            else if(dhoom.currentLevel === 2)
				dhoom.playGameSound(Utils.Path+"audio/HorseRun.mp3");
            else if(dhoom.currentLevel === 3)
				dhoom.playGameSound(Utils.Path+"audio/BikeRevs.mp3");
			else
				dhoom.playGameSound(Utils.Path+"audio/CopterRevs.mp3");

	    	dhoom.moveCopForward();
    	},1000);

		dhoom.marksObtained=10;
		dhoom.score+=dhoom.marksObtained;
		dhoom.rotateScore(50);
	}
	else {
		console.log("Wrong");
 		scoredMarks=0;
        console.log(dhoom.questionNumber,scoredMarks,totalMarks,dhoom.currentLevel,startTime);
        if(mobileDeviceFlag)
			Android.addScore(resId,dhoom.questionNumber,scoredMarks,totalMarks,dhoom.currentLevel,startTime);
		
		dhoom.playGameSound(Utils.Path+"audio/WrongAns.mp3");
		setTimeout(function(){
			dhoom.playGameSound(Utils.Path+"audio/ThiefBike2.mp3");
            $("#myThief").css({'-webkit-transform' : 'rotate(-20deg)','-moz-transform' : 'rotate(-20deg)','-ms-transform' : 'rotate(-20deg)','transform' : 'rotate(-20deg)'});
            setTimeout(function(){
                $("#myThief").css({'-webkit-transform' : 'rotate(0deg)','-moz-transform' : 'rotate(0deg)','-ms-transform' : 'rotate(0deg)','transform' : 'rotate(0deg)'});
            },500);
		},1500);

		dhoom.wrongAnsCounter+=1;
		dhoom.marksObtained=0;
		dhoom.score+=dhoom.marksObtained;

		 dhoom.rotateScore(50);
	}

    setTimeout(function(){
        dhoom.generateQuestion();
		$(".ansBtns").prop('disabled',false);
    },1400);

};

 dhoom.rotateScore=function(movingSpeed){
	$("#test").splitFlap({
			text:''+dhoom.score,
			speed:''+movingSpeed
		});
 };
// Call For Number and its Hindi Word Equality Question ********(Level-0) 

dhoom.lessThan=function(firstNumber, secondNumber){
	if (firstNumber < secondNumber){
		dhoom.displayAnswer = dhoom.correctAns = 1;
	}
	else {
		dhoom.displayAnswer =0;
		dhoom.correctAns = 1;
	}
};

/*dhoom.substraction = function (firstNumber, secondNumber){
	if(firstNumber<secondNumber){
		dhoom.firstRandomNumber=secondNumber;
		dhoom.secondRandomNumber=firstNumber;
	}
	dhoom.forSubs= Math.floor((Math.random() * 8) + 2 );
	dhoom.correctAns =dhoom.firstRandomNumber - dhoom.secondRandomNumber;
	
	if(dhoom.forDisplayAnswer==1)
		dhoom.displayAnswer=dhoom.correctAns;
	else{
		dhoom.displayAnswer = dhoom.correctAns+dhoom.forSubs;
		dhoom.correctAns=0;
	}
};*/
//**** Level-1
dhoom.mod=function(firstNumber, secondNumber){
	
	dhoom.CAnswer = secondNumber % firstNumber;

	if (dhoom.CAnswer==0){
		dhoom.displayAnswer = dhoom.correctAns = 1;
	}
	else {
		dhoom.displayAnswer = dhoom.displayAnswer-2;
		dhoom.correctAns = dhoom.displayAnswer+1;
	}
};

dhoom.evenOdd=function(firstNumber, secondNumber){
	if(dhoom.forDisplayAnswer==1){
		if (firstNumber % 2 == 0)
			dhoom.displayAnswer = dhoom.correctAns = dhoom.nosOddEven[1];
		else 
			dhoom.displayAnswer = dhoom.correctAns = dhoom.nosOddEven[2];
	}
	else{
		if (firstNumber % 2 == 0){
			dhoom.correctAns = dhoom.nosOddEven[1];
			dhoom.displayAnswer= dhoom.nosOddEven[2];
		}
		else {
			dhoom.correctAns = dhoom.nosOddEven[2];
			dhoom.displayAnswer= dhoom.nosOddEven[1];
		}
	}
};

//***** Level-2
dhoom.multiply=function(firstNumber, secondNumber){
	var makeWrong=10;
	dhoom.firstRandomNumber=firstNumber*10;
	dhoom.secondRandomNumber=secondNumber*10;
	
	dhoom.displayAnswer=dhoom.correctAns = dhoom.firstRandomNumber * dhoom.secondRandomNumber;
	if(dhoom.forDisplayAnswer != 1){
		dhoom.displayAnswer = dhoom.correctAns + makeWrong;
	}
};
// ***** Level-3
dhoom.prime=function(firstNumber, secondNumber){
	var tempShape,tempShapeName;
	dhoom.correctAns = secondNumber;

	if(dhoom.forDisplayAnswer==1)
		dhoom.displayAnswer = dhoom.correctAns;
	else{
		if(dhoom.currentLevel == 0 && dhoom.questionNumber == 5){
			dhoom.displayAnswer =dhoom.correctAns+2;
		}
		else if(dhoom.currentLevel == 1 && dhoom.questionNumber == 0){
			if(firstNumber == 7)
			tempShape=firstNumber-1;
			else
				tempShape=firstNumber+1;

			tempShapeName = dhoom.shapes[tempShape];
			dhoom.displayAnswer = tempShapeName;
		}
		else if(dhoom.currentLevel == 1 && dhoom.questionNumber == 1){
			if(secondNumber == dhoom.angles[1])
				tempNo=2;
			else if(secondNumber == dhoom.angles[2])
				tempNo=3;
			else if(secondNumber == dhoom.angles[3])
				tempNo=4;
			else if(secondNumber == dhoom.angles[4])
				tempNo=1;
							
			dhoom.displayAnswer = dhoom.angles[tempNo];
		}
	}
};

dhoom.greaterThan=function(firstNumber, secondNumber){
	if (firstNumber > secondNumber){
		dhoom.displayAnswer = dhoom.correctAns = 1;
	}
	else {
		dhoom.displayAnswer =0;
		dhoom.correctAns = 1;
	}
	//dhoom.firstRandomNumber=(Number(firstNumber)).toFixed(2);
	//dhoom.secondRandomNumber=(Number(secondNumber)).toFixed(2);
};

dhoom.posNeg=function(firstNumber, secondNumber){
	var tempSign=Math.floor((Math.random() * 2) + 0);

	if(dhoom.forDisplayAnswer==1){
		if (tempSign == 0){
			firstNumber=firstNumber - (firstNumber*2);
			dhoom.firstRandomNumber=firstNumber;
			dhoom.displayAnswer=dhoom.positiveNegative[1];
			dhoom.secondRandomNumber=dhoom.positiveNegative[2];
		}
		else {
			dhoom.displayAnswer=dhoom.positiveNegative[3];
			dhoom.secondRandomNumber=dhoom.positiveNegative[4];
		}
		dhoom.correctAns=dhoom.displayAnswer;
	}
	else{
		if (tempSign == 0){
			dhoom.displayAnswer=dhoom.positiveNegative[1];
			dhoom.secondRandomNumber=dhoom.positiveNegative[2];
		}
		else {
			firstNumber=firstNumber - (firstNumber*2);
			dhoom.firstRandomNumber=firstNumber;
			dhoom.displayAnswer=dhoom.positiveNegative[3];
			dhoom.secondRandomNumber=dhoom.positiveNegative[4];
		}
		dhoom.correctAns=1;
		dhoom.displayAnswer;
	}
};

dhoom.ascDescOrder=function(firstNumber, secondNumber){
	dhoom.forAscendind = Math.floor((Math.random() * 2) + 0);

	if(dhoom.forDisplayAnswer==1){
		if(dhoom.forAscendind == 1){
			dhoom.firstRandomNumber = dhoom.nosAscendingOrder[2];
			dhoom.correctAns = dhoom.displayAnswer = dhoom.nosAscendingOrder[1];
			return dhoom.displayAnswer;
		}
		else{
			dhoom.firstRandomNumber = dhoom.nosDescendingOrder[2];
			dhoom.correctAns = dhoom.displayAnswer = dhoom.nosDescendingOrder[1];
			return dhoom.displayAnswer;
		}
	}
	else{
		if(dhoom.forAscendind == 1){
			dhoom.firstRandomNumber = dhoom.nosAscendingOrder[3];
			dhoom.correctAns =1;
			dhoom.displayAnswer = dhoom.nosAscendingOrder[1];
			return dhoom.displayAnswer;
		}
		else{
			dhoom.firstRandomNumber = dhoom.nosDescendingOrder[3];
			dhoom.correctAns = 1;
			dhoom.displayAnswer = dhoom.nosDescendingOrder[1];
			return dhoom.displayAnswer;
		}
	}
};
dhoom.similarFraction = function(firstNumber, secondNumber){

	dhoom.randomDenominator = secondNumber + 3;
	dhoom.forSimilarAnswer = Math.floor((Math.random() * (6-2)) + 2 );

	if(dhoom.forDisplayAnswer==1){
		secondNumber = firstNumber * dhoom.forSimilarAnswer;
		dhoom.randomDenominator2 = dhoom.randomDenominator * dhoom.forSimilarAnswer;
		dhoom.displayAnswer = dhoom.correctAns=1;
	}
	else{
		secondNumber = firstNumber + dhoom.forSimilarAnswer+1;
		dhoom.randomDenominator2 = dhoom.randomDenominator + dhoom.forSimilarAnswer +2;
		dhoom.displayAnswer = 1;
		dhoom.correctAns=0;
	}
	dhoom.firstRandomNumber= '<div class="frac"> <span>'+ firstNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
	dhoom.secondRandomNumber= '<div class="frac"> <span>'+ secondNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator2 +'</span></div>';
	return dhoom.displayAnswer;
};

dhoom.fractionAddition = function(firstNumber, secondNumber){

	dhoom.randomDenominator= Math.floor((Math.random() * (15 - 8)) + 8 );
	dhoom.wrongAns= Math.floor((Math.random() * 2) + 0);
	dhoom.addAnswer = firstNumber+secondNumber;

	if(dhoom.forDisplayAnswer==1){
		dhoom.firstRandomNumber= '<div class="frac"> <span>'+ firstNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.secondRandomNumber= '<div class="frac"> <span>'+ secondNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.displayAnswer= '<div class="frac"> <span>'+ dhoom.addAnswer + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.correctAns = dhoom.displayAnswer;
	}
	else{
		if(dhoom.wrongAns==0)
			dhoom.addAnswer = firstNumber+secondNumber+3;
		else
			dhoom.addAnswer = firstNumber+secondNumber-3;

		dhoom.firstRandomNumber= '<div class="frac"> <span>'+ firstNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.secondRandomNumber= '<div class="frac"> <span>'+ secondNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.displayAnswer= '<div class="frac"> <span>'+ dhoom.addAnswer + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.correctAns = 0;
	}
	return dhoom.displayAnswer;
};

dhoom.fractionSubstraction = function(firstNumber, secondNumber){

	dhoom.randomDenominator= Math.floor((Math.random() * (15 - 8)) + 8 );

	if(firstNumber > secondNumber)
		dhoom.subAnswer = firstNumber-secondNumber;
	else{
		dhoom.subAnswer = secondNumber-firstNumber;
		var tempNo=firstNumber;
		firstNumber=secondNumber;
		secondNumber=tempNo;
	}

	if(dhoom.forDisplayAnswer==1){
		dhoom.firstRandomNumber= '<div class="frac"> <span>'+ firstNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.secondRandomNumber= '<div class="frac"> <span>'+ secondNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.correctAns=dhoom.displayAnswer= '<div class="frac"> <span>'+ dhoom.subAnswer + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
	}
	else{
		dhoom.subAnswer=dhoom.subAnswer+2;
		dhoom.correctAns=0;
		dhoom.firstRandomNumber= '<div class="frac"> <span>'+ firstNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.secondRandomNumber= '<div class="frac"> <span>'+ secondNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
		dhoom.displayAnswer= '<div class="frac"> <span>'+ dhoom.subAnswer + ' </span><span class="symbol">/</span><span class="bottom">'+ dhoom.randomDenominator +'</span></div>';
	}
	return dhoom.displayAnswer;
};

dhoom.fractionType = function(firstNumber, secondNumber){

	if(dhoom.chooseFraction != 3)
		dhoom.firstRandomNumber= '<div class="frac"> <span>'+firstNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ secondNumber +'</span></div>';
	else
		dhoom.firstRandomNumber= dhoom.randomMixedNumber+'<div class="frac"> <span>'+firstNumber + ' </span><span class="symbol">/</span><span class="bottom">'+ secondNumber +'</span></div>';

	if(dhoom.forDisplayAnswer==1)
		dhoom.displayAnswer = dhoom.correctAns = dhoom.fractionName;
	else{
		if(dhoom.chooseFraction == 3)
			dhoom.tempFrac=dhoom.chooseFraction-1;
		else
			dhoom.tempFrac=dhoom.chooseFraction+1;

		dhoom.fractionName = dhoom.fractions[dhoom.tempFrac];
		dhoom.displayAnswer = dhoom.fractionName;
		dhoom.correctAns = 0;
	}

	return dhoom.displayAnswer;
};

dhoom.addition = function (firstNumber, secondNumber){
	dhoom.correctAns = (Number(firstNumber) + Number(secondNumber)).toFixed(2);;
//	console.log("ADD ANSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS: "+dhoom.correctAns );
	if(dhoom.forDisplayAnswer==1){
		dhoom.displayAnswer=(Number(dhoom.correctAns)).toFixed(2);
	}
	else{
		var forWrong= Math.floor((Math.random() * 10) + 1);
		dhoom.displayAnswer=(Number(dhoom.correctAns + forWrong )).toFixed(2);
	}
	return dhoom.displayAnswer;
};

dhoom.additionDecimal = function(firstNumber, secondNumber){
	var forAdd;
	forAdd= Math.floor((Math.random() * 2) + 0 );

	if(dhoom.forDisplayAnswer==1){
		if(forAdd== 0){
			dhoom.correctAns=(Number(firstNumber)+0.01).toFixed(2);
			dhoom.secondRandomNumber=0.01;
			dhoom.displayAnswer=(Number(dhoom.correctAns)).toFixed(2);
		}
		else{
			dhoom.correctAns=(Number(firstNumber)+0.001).toFixed(3);
			dhoom.secondRandomNumber=0.001;
			dhoom.displayAnswer=(Number(dhoom.correctAns)).toFixed(3);
		}
	}
	else{
		var tempAnswer;
		if(forAdd== 0){
			tempAnswer=(Number(firstNumber)+0.02);
			dhoom.secondRandomNumber=0.01;
		}
		else{
			tempAnswer=(Number(firstNumber)+0.101);
			dhoom.secondRandomNumber=0.001;
		}
		dhoom.displayAnswer=(Number(tempAnswer)).toFixed(3);
		dhoom.correctAns=0;
	}
	return dhoom.displayAnswer;
};

dhoom.substraction = function (firstNumber, secondNumber){

	forSubs= Math.floor((Math.random() * (6 - 2)) + 2 );

	firstNumber=(Number(firstNumber)+forSubs).toFixed(2);
	dhoom.firstRandomNumber=firstNumber;

	if(dhoom.forDisplayAnswer==1){
		dhoom.correctAns = (Number(firstNumber - secondNumber)).toFixed(2);
		dhoom.displayAnswer=dhoom.correctAns;
	}
	else{
		var tempAns = (Number(firstNumber - secondNumber + 1.2)).toFixed(2);

		dhoom.displayAnswer=tempAns;
		dhoom.correctAns=0;
	}
}

dhoom.LCM=function(firstNumber, secondNumber){

	x = dhoom.firstRandomNumber;
	y = dhoom.secondRandomNumber;

	while(x != y){
		if(x > y)
			x = x - y;
		else
			y = y - x;
	}
	dhoom.lcm= (dhoom.firstRandomNumber*dhoom.secondRandomNumber)/x;
	dhoom.correctAns = dhoom.lcm;

	if(dhoom.forDisplayAnswer==1){
		dhoom.displayAnswer = dhoom.correctAns;
	}
	else{
		var tempWrongAns = Math.floor((Math.random() * (6 - 2)) + 2 );
		dhoom.displayAnswer=dhoom.correctAns+tempWrongAns;
	}
};

dhoom.HCF=function(firstNumber, secondNumber){
	var hcf,x,y;
	x = dhoom.firstRandomNumber;
	y = dhoom.secondRandomNumber;

	while (y != 0){
		if(x > y){
			x = x - y;
		}
		else {
			y = y - x;
		}
	}
	hcf= x;
	dhoom.correctAns = hcf;

	if(dhoom.forDisplayAnswer==1){
		dhoom.displayAnswer = dhoom.correctAns;
	}
	else{
		var tempWrongAns = Math.floor((Math.random() * (6 - 2)) + 2 );
		dhoom.displayAnswer=dhoom.correctAns+tempWrongAns;
	}
};

dhoom.areaSquare=function(firstNumber, secondNumber){
	var tempWrongAns;
	dhoom.correctAns= firstNumber*firstNumber;
	if(dhoom.forDisplayAnswer==1){
		dhoom.displayAnswer = dhoom.correctAns;
	}
	else{
		 tempWrongAns = Math.floor((Math.random() * (6 - 2)) + 2 );
		dhoom.displayAnswer=dhoom.correctAns+tempWrongAns;
	}
};

dhoom.perimeterRect=function (firstNumber,secondNumber){

	var tempWrongAns,perimeter= 2*(firstNumber+secondNumber);
	dhoom.correctAns= perimeter;
	if(dhoom.forDisplayAnswer==1){
		dhoom.displayAnswer = dhoom.correctAns;
	}
	else{
		tempWrongAns = Math.floor((Math.random() * (6 - 2)) + 2 );
		dhoom.displayAnswer=dhoom.correctAns+tempWrongAns;
	}
};

dhoom.circumferenceCircle=function (firstNumber,secondNumber){

	var tempAns,tempWrongAns,circum= 2*3.14*firstNumber;
	dhoom.correctAns= (Number(circum)).toFixed(2);
	if(dhoom.forDisplayAnswer==1){
		dhoom.displayAnswer = dhoom.correctAns;
	}
	else{
		tempWrongAns = Math.floor((Math.random() * (6 - 2)) + 2 );
		tempAns=(Number(dhoom.correctAns+tempWrongAns)).toFixed(2);
		dhoom.displayAnswer=tempAns;
	}
};

dhoom.moveCopForward= function() {
	if(dhoom.currentLevel == 4 || dhoom.currentLevel == 0)
		$("#"+dhoom.vehiclePosition[dhoom.currentLevel]).css({'-webkit-transform' : 'rotate(20deg)','-moz-transform' : 'rotate(20deg)','-ms-transform' : 'rotate(20deg)','transform' : 'rotate(20deg)'});
	else
		$("#"+dhoom.vehiclePosition[dhoom.currentLevel]).css({'-webkit-transform' : 'rotate(-30deg)','-moz-transform' : 'rotate(-30deg)','-ms-transform' : 'rotate(-30deg)','transform' : 'rotate(-30deg)'});

	if(dhoom.currentLevel==4){
		if(dhoom.initialCopLeftPosition < 35){
			dhoom.initialCopLeftPosition= dhoom.initialCopLeftPosition+5;
			$("#"+dhoom.vehiclePosition[dhoom.currentLevel]).animate({
				left: dhoom.initialCopLeftPosition+"%"
			});
		}
	}
	setTimeout(function(){
		$("#"+dhoom.vehiclePosition[dhoom.currentLevel]).css({'-webkit-transform' : 'rotate(0deg)','-moz-transform' : 'rotate(0deg)','-ms-transform' : 'rotate(0deg)','transform' : 'rotate(0deg)'});
	},500);
};

dhoom.playGameSound=function(path){
	document.getElementById('gameSound').src = path;
	document.getElementById('gameSound').play();
};
