
//10 jan 2019
var CricketGame={};
var Utils={};
Utils.Path='';
var resId=2000,questionId=0,totalMarks=40,startTime,scoredMarks=0;
var canvas,ctx,startAngle=0;
var endAngle=30,AnswerFlag=0;
var arrayOfRandomNumbers1=[],arrayOfRandomNumbers2=[],stopTimerFromCalling=0,trueOrfalse;
CricketGame.init=function()
{
	if(navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))
		Utils.mobileDeviceFlag=true;
	document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.CricketDataDependingUponLanguage.backgroundImage+")";
	document.getElementById("playSound").src="sound/tenExtra.mp3";
	document.getElementById("playSound").play();
	$('#home').prop('src',Utils.Path+'images/Home.png');
	$('#logo').prop('src',Utils.Path+'images/logo.png');
	$('#help').prop('src',Utils.Path+'images/Helpcricket.png');
	$('#queOptionDiv').hide();
	CricketGame.setVariables();
	CricketGame.createDynamicElements();
	CricketGame.setPlayersImages();
	setTimeout(function(){
		$("#howToPlayButtonDiv").css("visibility", "visible");
		$('#playImg').prop('src',Utils.Path+'images/Play.png');
		$("#playImg").addClass('animated zoomInRight');
	},4000);
	
	canvas = document.getElementById("CanvasId");
	ctx = canvas.getContext("2d");
	
}

CricketGame.setVariables=function()
{
	CricketGame.questionDifficultyLevel=0;
	CricketGame.selectedPlayer=0;
	CricketGame.score=0;
	CricketGame.wickets=0;
	CricketGame.overs=0;
	CricketGame.strRate=0;
	CricketGame.playerOneScore=0;
	CricketGame.playerOneBalls=0;
	CricketGame.playerTwoScore=0;
	CricketGame.playerTwoBalls=0;
	CricketGame.queValue1=0;
	CricketGame.queValue2=0;
	CricketGame.actualAnswers=[];
	CricketGame.uniqueAnswers=[];
	CricketGame.dummyPlayerArray=[];
	CricketGame.ckeckShot=0;
	CricketGame.batFlag=true;
	CricketGame.winFlag=false;
	CricketGame.stopFlag=false;
	CricketGame.sixBallCount=0;
	CricketGame.checkForChangeLevel=0;
	CricketGame.clickedAnswer=0;
	
}


CricketGame.createDynamicElements=function()
{
	var options,i=0,plyerDiv,plyerImg;
	var Div,Div1,Div2;
	// How to play information 
	for(i=0;i<5;i++)
	{
		options=document.createElement('p');
		options.setAttribute("id","instuctuion"+(i+1));
		options.setAttribute("class","instuctuionClass noPadding");
		howToPlayInfo.appendChild(options);
		//last page div
		Div=document.createElement('DIV');
		Div.setAttribute("id","plyerInfo"+(i+1));
		Div.setAttribute("class","playerInfoClass1 col-xs-12 col-sm-12 col-md-12 col-lg-12");
		
		Div1=document.createElement('DIV');
		Div1.setAttribute("id","plyerInfo1"+(i+1));
		Div1.setAttribute("class","playerInfoClass2 col-xs-6 col-sm-6 col-md-6 col-lg-6");
		
		Div2=document.createElement('DIV');
		Div2.setAttribute("id","plyerInfo2"+(i+1));
		Div2.setAttribute("class","playerInfoClass2 col-xs-6 col-sm-6 col-md-6 col-lg-6");
			
		Div.appendChild(Div1);
		Div.appendChild(Div2);
		playerScoreInfo.appendChild(Div);
	}
	for(i=0;i<4;i++)
	{
		plyerDiv=document.createElement('DIV');
		plyerDiv.setAttribute("id","plyerDiv"+(i+1));
		plyerDiv.setAttribute("class","col-xs-3 col-sm-3 col-md-3 col-lg-3");
		plyerImg=document.createElement('IMG');
		plyerImg.setAttribute("id","plyerImg"+(i+1));
		plyerImg.setAttribute("class","col-xs-11 col-sm-11 col-md-11 col-lg-11 img-responsive");
		plyerImg.setAttribute("onclick","CricketGame.selectPlayer(this.id)");
		plyerDiv.appendChild(plyerImg);
		playersDiv.appendChild(plyerDiv);
		
		// options divs
		options=document.createElement('DIV');
		options.setAttribute("id","options"+(i+1));
		options.setAttribute("class","optionsClass col-xs-12 col-sm-12 col-md-12 col-lg-12");
		options.setAttribute("onclick","CricketGame.checkAnswerAndPlayShot(this.id)");
		queOptionDiv.appendChild(options);
	}	
}

//show game insturctions 
CricketGame.showHowToPlayGameInfo=function()
{	
	$('#howToPlayButtonDiv').hide();
	$('#homeDiv').show();
	document.body.style.backgroundImage="url("+Utils.Path+"images/Back.png"+")";
	document.getElementById("instuctuion1").innerHTML=CricketGame.CricketDataDependingUponLanguage.titleForInstructions;
	document.getElementById("instuctuion2").innerHTML=CricketGame.CricketDataDependingUponLanguage.singleRun;
	document.getElementById("instuctuion3").innerHTML=CricketGame.CricketDataDependingUponLanguage.twoRuns;
	document.getElementById("instuctuion4").innerHTML=CricketGame.CricketDataDependingUponLanguage.fourRuns;
	document.getElementById("instuctuion5").innerHTML=CricketGame.CricketDataDependingUponLanguage.sixRuns;
	$('#howToPlayInfoDiv').show();
	
}

//set players images// choose player
CricketGame.setPlayersImages=function()
{
	var i=0,indexNumber,tempArray=[];
	document.getElementById("centuryTextImg").src=Utils.Path+"images/"+CricketGame.CricketDataDependingUponLanguage.choosePlayer;
	for(i=1;i<=4;i++)
	{
		indexNumber=Math.floor(Math.random() * CricketGame.cricketers.length);
		if(tempArray.includes(indexNumber))
		{
			i--;
			continue;	
		}
		tempArray.push(indexNumber);
		document.getElementById("plyerImg"+i).src=Utils.Path+"images/"+CricketGame.cricketers[indexNumber].source;
		document.getElementById("plyerImg"+i).setAttribute("playerIndex",indexNumber);
	}
}

//onclick of play button
CricketGame.startGame=function()
{
	$('#homeDiv').show();
	document.body.style.backgroundImage="url("+Utils.Path+"images/Back.png"+")";
	document.getElementById("playSound").pause();
	document.getElementById("playSound").src="sound/ting.mp3";
	document.getElementById("playSound").play();
	$("#playersDiv").addClass('animated zoomInRight');
	$('#howToPlayButtonDiv').hide();
	$('#palyBtnDiv').hide();
	$('#howToPlayInfoDiv').hide();
	$('#selectPlayerForCenturyDiv').show();
}

//select plyer 
CricketGame.selectPlayer=function(playerId)
{
	$('#selectPlayerForCenturyDiv').hide();
	CricketGame.selectedPlayer=Number(document.getElementById(playerId).getAttribute("playerIndex"));
	document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].startingPosition+")";
	CricketGame.setInitialData();
}

//
CricketGame.setInitialData=function()
{
	var i=0;
	document.getElementById("playSoundInLoop").src="sound/Stedium_crowd.mp3";
	document.getElementById("playSoundInLoop").play();
	CricketGame.score=Math.floor(Math.random() * 60) + 220;
	CricketGame.wickets=Math.floor(Math.random() * 3) + 5;
	CricketGame.overs=47;
	CricketGame.playerOneScore=Math.floor(Math.random() * 20) + 55;
	CricketGame.playerOneBalls=Math.floor(Math.random() * 20) + 45;
	CricketGame.playerTwoScore=Math.floor(Math.random() * 20) + 10;
	CricketGame.playerTwoBalls=Math.floor(Math.random() * 20) + 10;
	CricketGame.strRate=((CricketGame.playerOneScore*100)/CricketGame.playerOneBalls);
	CricketGame.strRate=Math.round(CricketGame.strRate * 100) / 100;
	document.getElementById("questionValue1").style.backgroundImage="url("+Utils.Path+"images/ball2.jpg"+")";
	document.getElementById("questionValue2").style.backgroundImage="url("+Utils.Path+"images/ball2.jpg"+")";
	document.getElementById("nextBallImg").src=Utils.Path+"images/Nextball.png";
	document.getElementById("countryName").innerHTML=CricketGame.cricketers[CricketGame.selectedPlayer].country;
	document.getElementById("score").innerHTML=CricketGame.score+"/"+CricketGame.wickets;
	document.getElementById("overs").innerHTML="Overs";
	document.getElementById("oversCount").innerHTML=CricketGame.overs;
	document.getElementById("strikeRateText").innerHTML="strRate ";
	document.getElementById("strikeRate").innerHTML=CricketGame.strRate;
	document.getElementById("playername").innerHTML=CricketGame.cricketers[CricketGame.selectedPlayer].Name;
	document.getElementById("playerScore").innerHTML=CricketGame.playerOneScore+"("+CricketGame.playerOneBalls+")"+"*";
	$("#playerScore").addClass("boldScore");
	//$("#playerScore").addClass('redClass');
	document.getElementById("dummyPlayername").innerHTML=CricketGame.cricketers[CricketGame.selectedPlayer].dummyPlayer;
	document.getElementById("dummyPlayerScore").innerHTML=CricketGame.playerTwoScore+"("+CricketGame.playerTwoBalls+")";
	country=CricketGame.cricketers[CricketGame.selectedPlayer].country;
	CricketGame.dummyPlayerArray.push(CricketGame.cricketers[CricketGame.selectedPlayer].dummyPlayer);
	for(i=0;i<5;i++)
	{
		CricketGame.dummyPlayerArray.push(CricketGame.dummyPlayersList[country][i]);
	}
	$("#questionBoardDiv").addClass('magictime puffIn');
	$('#scoreBoardDiv').show();
	$('#questionBoard').show();
		
}

//check level for difficulty
CricketGame.setDifficultyLevel=function()
{
	StopWheel();
	$("#nextBallImg").css({pointerEvents:'none'});
	$('#nextBallDiv').hide();
	$('#questionBoard').hide();
	$('#timerDiv').show();
	$('#divshowingCricketBall').show();
	var number1=0,number2=0;
	number1=Math.floor(Math.random() * CricketGame.difficultyValues[CricketGame.questionDifficultyLevel].level[0].second) + CricketGame.difficultyValues[CricketGame.questionDifficultyLevel].level[0].first;
	number2=Math.floor(Math.random() * CricketGame.difficultyValues[CricketGame.questionDifficultyLevel].level[1].second) + CricketGame.difficultyValues[CricketGame.questionDifficultyLevel].level[1].first;
	if(CricketGame.questionDifficultyLevel>2)
	{
		if(CricketGame.questionDifficultyLevel==3)
		{
			number1= (number1+(Math.random())).toFixed(1);
		}
		else
		{
			number1= (number1+(Math.random())).toFixed(1);
			number2= (number2+(Math.random())).toFixed(1);
		}
	}
	CricketGame.showQuestionsValues(number1,number2);
}

//set values for question
CricketGame.showQuestionsValues=function(number1,number2)
{
	if((number1*10)>(number2*10))
	{
		CricketGame.firstOperand=number1;
		CricketGame.secondOperand=number2;
	}
	else
	{
		CricketGame.firstOperand=number2;
		CricketGame.secondOperand=number1;
	}
	document.getElementById("questionValue1").style.backgroundImage="url("+Utils.Path+"images/ball4.jpg"+")";
	document.getElementById("questionValue2").style.backgroundImage="url("+Utils.Path+"images/ball4.jpg"+")";
	document.getElementById("question1").innerHTML=CricketGame.firstOperand;
	document.getElementById("question2").innerHTML=CricketGame.secondOperand;
	CricketGame.getOptions();
}


//get unique options
CricketGame.getOptions=function()
{
	var i=0,tempVar=0;
	CricketGame.actualAnswers=[];
	CricketGame.uniqueAnswers=[];
	if(CricketGame.batFlag==true)
	{
		if(CricketGame.firstOperand%CricketGame.secondOperand==0)
		{
			
			CricketGame.actualAnswers[0]=parseFloat(CricketGame.firstOperand)/parseFloat(CricketGame.secondOperand);
			console.log(CricketGame.actualAnswers);
		}
		else
			CricketGame.actualAnswers[0]=Math.floor(Math.random() * 80) + 10;
		CricketGame.actualAnswers[1]=parseFloat(CricketGame.firstOperand)*parseFloat(CricketGame.secondOperand);
		CricketGame.actualAnswers[2]=parseFloat(CricketGame.firstOperand)-parseFloat(CricketGame.secondOperand);
		CricketGame.actualAnswers[3]=(parseFloat(CricketGame.firstOperand) + parseFloat(CricketGame.secondOperand));
	}
	else
	{
		CricketGame.actualAnswers[0]=(parseFloat(CricketGame.firstOperand) + parseFloat(CricketGame.secondOperand));
	}
	
	for(i=0;i<CricketGame.actualAnswers.length;i++)
	{
		if(CricketGame.uniqueAnswers.includes(CricketGame.actualAnswers[i]))
			continue;
		else
			CricketGame.uniqueAnswers.push(CricketGame.actualAnswers[i]);
	}
	while(CricketGame.uniqueAnswers.length!=4)
	{
		if(CricketGame.batFlag==false)
		{
			
			if(CricketGame.questionDifficultyLevel>2)
				tempVar=(Math.random() * 80) + 10;
			else
				tempVar=Math.floor(Math.random() * 40) + 10;
		}
		else			
			tempVar=Math.floor(Math.random() * 80) + 10;
		if(CricketGame.uniqueAnswers.includes(tempVar))
			continue;
		else
			CricketGame.uniqueAnswers.push(tempVar);
	}
	
	CricketGame.setAnswersOption();
}

//set option to div
CricketGame.setAnswersOption=function()
{
	var i=0,testTemp=0;tempArray=[];
	$('#queOptionDiv').show();
	for(i=0;i<4;i++)
	{
		testTemp=Math.floor(Math.random() * 4) + 1;
		if(tempArray.includes(testTemp))
		{
			i--;
			continue;
		}
		else
		{
			tempArray.push(testTemp);
			if(Number(CricketGame.uniqueAnswers[i]) === CricketGame.uniqueAnswers[i] && CricketGame.uniqueAnswers[i] % 1 !== 0)
				document.getElementById("options"+(testTemp)).innerHTML=CricketGame.uniqueAnswers[i].toFixed(1);
			else
				document.getElementById("options"+(testTemp)).innerHTML=CricketGame.uniqueAnswers[i];
			document.getElementById("options"+(testTemp)).setAttribute("dataValue",i);
		}	
	}
}

//check answer and then call for play shot
CricketGame.checkAnswerAndPlayShot=function(ansDivId)
{
	var dataValue=0,ans;
	clearInterval(CricketGame.stopTimer);
	dataValue=document.getElementById(ansDivId).getAttribute("dataValue");
	CricketGame.clickedAnswer=document.getElementById(ansDivId).innerHTML;
	ans=CricketGame.uniqueAnswers[dataValue];
	indexValue=CricketGame.actualAnswers.indexOf(ans);
	console.log(indexValue);
	console.log(dataValue);
	console.log(ans);
	
	if(CricketGame.batFlag==true)
	{
		if(indexValue == 0 && CricketGame.actualAnswers[0] == parseFloat(CricketGame.firstOperand)/parseFloat(CricketGame.secondOperand))
		{
			CricketGame.ckeckShot=6;
		}
		else if(indexValue == 1)
			CricketGame.ckeckShot=4;
		else if(indexValue == 2)
			CricketGame.ckeckShot=2;
		else if(indexValue == 3)
			CricketGame.ckeckShot=1;
		else
			CricketGame.ckeckShot=0;
	}
	else
	{
		if(indexValue == 0)
			CricketGame.ckeckShot=1;
		else
			CricketGame.ckeckShot=0;
	}	
	
	CricketGame.playShot(CricketGame.scoreList[CricketGame.ckeckShot]);
}

//play shot according to run
CricketGame.playShot=function(stringForShot)
{
	$('#scoreBoardDiv').hide();
	$('#questionBoard').hide();
	$('#queOptionDiv').hide();	
	if(CricketGame.ckeckShot!=0)
	{
		document.getElementById("firstValue").innerHTML=CricketGame.firstOperand;
		document.getElementById("sign").innerHTML=CricketGame.cricketers[CricketGame.selectedPlayer].answerImages[stringForShot].sign;
		document.getElementById("secondValue").innerHTML=CricketGame.secondOperand
		document.getElementById("ansValue").innerHTML=Number(CricketGame.clickedAnswer);
		$('#equationDiv').show();
	}
	CricketGame.sixBallCount+=0.1;
	if(CricketGame.batFlag==true)
	{
		CricketGame.updateScoreForPlayer(stringForShot);
	}
	else
	{
		CricketGame.updateScoreForDummyPlayer(stringForShot);
	}
}

//score update for player one
CricketGame.updateScoreForPlayer=function(stringForShot)
{
	var soundIndex,timeOut=3000;
	document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].answerImages[stringForShot].img + "?id="+ CricketGame.playerOneBalls +"" +")";
	scoredMarks=CricketGame.cricketers[CricketGame.selectedPlayer].answerImages[stringForShot].score;
	console.log(scoredMarks);
	setTimeout(function()
	{
		soundIndex=Math.floor(Math.random() * CricketGame.cricketSound[stringForShot].length);
		if(stringForShot!=="out")
		{
			document.getElementById("playSoundSecond").src="sound/twoRuns.mp3";
			document.getElementById("playSoundSecond").play();
		}
		setTimeout(function()
		{
			document.getElementById("playSound").src="sound/"+CricketGame.cricketSound[stringForShot][soundIndex];
			document.getElementById("playSound").play();
		},700)
		
	},CricketGame.cricketers[CricketGame.selectedPlayer].answerImages[stringForShot].time)
	if(CricketGame.ckeckShot!=0)
	{
		CricketGame.score+=CricketGame.ckeckShot;
		CricketGame.playerOneScore+=CricketGame.ckeckShot;
		CricketGame.playerOneBalls++;
		CricketGame.strRate=((CricketGame.playerOneScore*100)/CricketGame.playerOneBalls);
		if(CricketGame.ckeckShot>=4)
		{
			CricketGame.checkForChangeLevel++;
			if(CricketGame.checkForChangeLevel>=2)
			{
				CricketGame.questionDifficultyLevel++;
				CricketGame.checkForChangeLevel=0;
			}
		}
		else
		{
			CricketGame.checkForChangeLevel=0;
		}
	}
	else
	{
		CricketGame.winFlag=false;
		CricketGame.stopFlag=true;
		setTimeout(function()
		{
			CricketGame.playerOutOrWinUpdate();
		},4000);
	}
	if(CricketGame.playerOneScore>=100)
	{
		CricketGame.winFlag=true;
		CricketGame.stopFlag=true;
		setTimeout(function()
		{
			CricketGame.playerOutOrWinUpdate();
		},6000);
	}
	else if(CricketGame.winFlag==false)
	{
		setTimeout(function()
		{
			if(CricketGame.stopFlag==false)
			{
				if(CricketGame.ckeckShot==1)
				{
					timeOut=3000;
					CricketGame.batFlag=false;
					document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].dummyPlayerStansSource+ "?id="+ CricketGame.playerOneBalls +"" +")";	
					document.getElementById("message").innerHTML=CricketGame.dummyPlayerArray[0]+" is On Strike";
					$('#equationDiv').hide();
					$('#showMsgDiv').show();
					$("#showMsgDiv").addClass('animated fadeInDown');
					setTimeout(function()
					{
						$('#equationDiv').hide();
						$('#showMsgDiv').hide();
						$("#showMsgDiv").removeClass('animated fadeInDown');
						
					},2000)
				}
				else
				{
					timeOut=500;
					document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].startingPosition+")";
				}
				setTimeout(function()
				{
					CricketGame.nextBallCall();
					
				},timeOut)
				
			}
		},6000);
	}
}

// when player is out
CricketGame.playerOutOrWinUpdate=function()
{
	document.body.style.backgroundImage="url("+Utils.Path+"images/Back.png"+")";
	$('#scoreBoardDiv').hide();
	$('#questionBoard').hide();	
	$('#equationDiv').hide();
	document.getElementById("playSoundSecond").pause();
	document.getElementById("playSound").pause();
	document.getElementById("playSoundInLoop").pause();
	if(CricketGame.winFlag==false)
		document.getElementById("resultText").innerHTML="Opps!! You Lost.";
	else
		document.getElementById("resultText").innerHTML="Wow!! You won.";
	document.getElementById("playerImage").src=Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].LastImgSource;
	document.getElementById("plyerInfo11").innerHTML="Player";
	document.getElementById("plyerInfo12").innerHTML="Runs";
	document.getElementById("plyerInfo13").innerHTML="Balls";
	document.getElementById("plyerInfo14").innerHTML="StrRate";
	document.getElementById("plyerInfo15").innerHTML=CricketGame.cricketers[CricketGame.selectedPlayer].country;
	
	document.getElementById("plyerInfo21").innerHTML=CricketGame.cricketers[CricketGame.selectedPlayer].Name;
	document.getElementById("plyerInfo22").innerHTML=CricketGame.playerOneScore;
	document.getElementById("plyerInfo23").innerHTML=CricketGame.playerOneBalls;
	document.getElementById("plyerInfo24").innerHTML=(((CricketGame.playerOneScore*100)/CricketGame.playerOneBalls)).toFixed(1);
	document.getElementById("plyerInfo25").innerHTML=CricketGame.score+"/"+CricketGame.wickets;
		
	$('#lastPage').show();
}
//score update for dummy player
CricketGame.updateScoreForDummyPlayer=function(stringForShot)
{
	console.log(stringForShot);
	setTimeout(function()
	{
		soundIndex=Math.floor(Math.random() * CricketGame.cricketSound[stringForShot].length);
		if(stringForShot!=="out")
		{
			document.getElementById("playSoundSecond").src="sound/twoRuns.mp3";
			document.getElementById("playSoundSecond").play();
		}
		setTimeout(function()
		{
			
			document.getElementById("playSound").src="sound/"+CricketGame.cricketSound[stringForShot][soundIndex];
			document.getElementById("playSound").play();
		},700)
		
	},CricketGame.cricketers[CricketGame.selectedPlayer].answerImages[stringForShot].time)
	if(CricketGame.ckeckShot!=0)
	{
		scoredMarks=10;
		document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].dummyPlayerRunSource+")";
		CricketGame.score+=CricketGame.ckeckShot;
		CricketGame.playerTwoScore+=CricketGame.ckeckShot;
		CricketGame.playerTwoBalls++;
		CricketGame.strRate=((CricketGame.playerTwoScore*100)/CricketGame.playerTwoBalls);
		CricketGame.batFlag=true;
		setTimeout(function()
		{
			document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].startingPosition+")";
			document.getElementById("message").innerHTML=CricketGame.cricketers[CricketGame.selectedPlayer].Name+" is On Strike";
			$('#equationDiv').hide();
			$('#showMsgDiv').show();
			$("#showMsgDiv").addClass('animated fadeInDown');
			setTimeout(function()
			{
				$('#equationDiv').hide();
				$('#showMsgDiv').hide();
				$("#showMsgDiv").removeClass('animated fadeInDown');
				
			},2000)
			
			setTimeout(function()
			{
				CricketGame.nextBallCall();
				
			},3000)
		},6000)
	}
	else
		CricketGame.dummyPlayerOutUpdate();
		
}


CricketGame.dummyPlayerOutUpdate=function()
{
	scoredMarks=0;
	document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].dummyPlayerOutSource+")";
	CricketGame.dummyPlayerArray.shift();
	CricketGame.wickets++;
	CricketGame.batFlag=false;
	if(CricketGame.wickets==11)
	{
		
		setTimeout(function()
		{
			CricketGame.winFlag=false;
			CricketGame.playerOutOrWinUpdate();
		},5000);
	}
	else
	{
		setTimeout(function()
		{
			document.getElementById("dummyPlayername").innerHTML=CricketGame.dummyPlayerArray[0];
			CricketGame.playerTwoScore=0;
			CricketGame.playerTwoBalls=0;
			CricketGame.strRate=0;
			document.getElementById("dummyPlayerScore").innerHTML=CricketGame.playerTwoScore+"("+CricketGame.playerTwoBalls+")";
			document.body.style.backgroundImage="url("+Utils.Path+"images/"+CricketGame.cricketers[CricketGame.selectedPlayer].dummyPlayerStansSource+")";
			CricketGame.nextBallCall();
		},6000);	
	}
}

CricketGame.nextBallCall=function()
{
	console.log(scoredMarks);
	$('#equationDiv').hide();
	$("#nextBallImg").css({pointerEvents:'auto'});
	if(CricketGame.batFlag==true)
	{
		CricketGame.strRate=((CricketGame.playerOneScore*100)/CricketGame.playerOneBalls);
		document.getElementById("playerScore").innerHTML=CricketGame.playerOneScore+"("+CricketGame.playerOneBalls+")"+"*";
		$("#playerScore").addClass("boldScore");
		$("#dummyPlayerScore").removeClass("boldScore");
		document.getElementById("dummyPlayerScore").innerHTML=CricketGame.playerTwoScore+"("+CricketGame.playerTwoBalls+")";
	}
	else
	{
		CricketGame.strRate=((CricketGame.playerTwoScore*100)/CricketGame.playerTwoBalls);
		document.getElementById("dummyPlayerScore").innerHTML=CricketGame.playerTwoScore+"("+CricketGame.playerTwoBalls+")"+"*";
		$("#dummyPlayerScore").addClass("boldScore");
		$("#playerScore").removeClass("boldScore");
		document.getElementById("playerScore").innerHTML=CricketGame.playerOneScore+"("+CricketGame.playerOneBalls+")";
	}
	CricketGame.strRate=Math.round(CricketGame.strRate * 100) / 100;
	if(CricketGame.batFlag==false && CricketGame.playerTwoScore==0)
		CricketGame.strRate=0;
	document.getElementById("strikeRate").innerHTML=(CricketGame.strRate).toFixed(1);
	document.getElementById("questionValue1").style.backgroundImage="url("+Utils.Path+"images/ball2.jpg"+")";
	document.getElementById("questionValue2").style.backgroundImage="url("+Utils.Path+"images/ball2.jpg"+")";
	document.getElementById("question1").innerHTML="";
	document.getElementById("question2").innerHTML="";
	document.getElementById("score").innerHTML=CricketGame.score+"/"+CricketGame.wickets;
	if(CricketGame.sixBallCount<0.6)
		document.getElementById("oversCount").innerHTML=(CricketGame.overs + CricketGame.sixBallCount)
	else
	{
		CricketGame.overs++;
		document.getElementById("oversCount").innerHTML=CricketGame.overs;
		CricketGame.sixBallCount=0;
	}
	$('#scoreBoardDiv').show();
	$('#questionBoard').show();
	$('#queOptionDiv').hide();	
	$("#questionBoardDiv").addClass('magictime puffIn');
	$('#nextBallDiv').show();
	$('#timerDiv').hide();	
}

//show dot ball message
CricketGame.showDotBallMsg=function()
{
	ctx.clearRect(0,0, canvas.width, canvas.height);
	$('#scoreBoardDiv').hide();
	$('#questionBoard').hide();
	document.getElementById("message").innerHTML="Dot Ball";
	$('#showMsgDiv').show();
	$("#showMsgDiv").addClass('animated fadeInDown');
	setTimeout(function()
	{
		$("#showMsgDiv").removeClass('animated fadeInDown');
		setTimeout(function()
		{
			startAngle=0;
			$('#showMsgDiv').hide();
			CricketGame.sixBallCount+=0.1;
			if(CricketGame.batFlag==true)
				CricketGame.playerOneBalls++;
			else
				CricketGame.playerTwoBalls++;
			CricketGame.nextBallCall();
		},1000)
	},1500)
}

//canvas animation for timer
CricketGame.showTimer=function()
{   
	var x=0,y=0;
	ctx.clearRect(0,0, canvas.width, canvas.height);
	x=canvas.width/2;
	y=canvas.height/2;
	startAngle=0;
	endAngle=30;
	CricketGame.stopTimer=setInterval(function()
	{	
		CricketGame.drawArc(x,y,50, startAngle,endAngle, false, "#AED6F1");
		startAngle=endAngle;
		endAngle=endAngle+30;
	},1000);
}

CricketGame.drawArc=function(x, y,r,startAngle, endAngle,anticlockwise,lineColor,fillColor)
{
	var sAngle = startAngle * (Math.PI/180);
	var eAngle = endAngle   * (Math.PI/180);
	ctx.strokeStyle = lineColor;
	ctx.fillStyle   = fillColor;
	ctx.lineWidth   =100;
	ctx.beginPath();
	ctx.arc(x, y,r,sAngle, eAngle,anticlockwise);
	ctx.stroke();
	if(startAngle>=335)
	{
		clearInterval(CricketGame.stopTimer);
		CricketGame.showDotBallMsg();
	}
}
function StopWheel()
{	
	//questionId++;
	var d=new Date();
	startTime=d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
	$( '.poster1').show();
	$( '.poster2').show();
	$("#playerScore").removeClass('magictime swashIn');
	$("#runs").removeClass('magictime swashIn');
	$("#playerScore").css('color','white');
	$("#runs").css('color','white');
	var countForFirst=1;
	while(countForFirst<=24)
	{
		document.getElementById("p"+countForFirst).innerHTML=Math.floor(Math.random() * 25) + 1;
		countForFirst++;
	}
	$('#questionBoardDiv').removeClass('magictime puffIn');
	$("#buttondiv").hide();
	document.getElementById("ring-2").classList.remove("stop");
	document.getElementById("ring-1").classList.remove("stop");
	document.getElementById("ring-2").classList.add("fastring");
	setTimeout(function()
	{
		document.getElementById("ring-2").classList.remove("fastring");
		document.getElementById("ring-2").classList.add("slowring");
	},500);
	document.getElementById("ring-1").classList.add("slowring");
	document.getElementById("ring-2").classList.add("ring2");
	document.getElementById("ring-1").classList.add("ring1");
	setTimeout(function()
	{
		$( '.poster1').not("#d1").hide();
		$( '.poster2').not("#d13").hide();
		$('#questionBoard').show();
		$('#divshowingCricketBall').hide();
		CricketGame.showTimer();
		document.getElementById("ring-2").classList.remove("ring2");
		document.getElementById("ring-1").classList.remove("ring1");
		document.getElementById("ring-2").classList.remove("slowring");
		document.getElementById("ring-1").classList.remove("slowring");			
	},4000);
	
}
