//startingDate:17-01-2019
var Business={};
var Utils = {};
Utils.Path='';
Utils.mobileDeviceFlag=false;
var questionId=0,startTime=0,scoredMarks=0,totalMarks=40,resId=0,level=0;

$(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("Business");  */
	setTimeout(function()
	{
		Business.init();
	},100);
});

Business.init=function()
{
	$("#coverPage").show();
	$("#gamePage").hide();
	$("#endPage").hide();
	$(".header").not("#logo").css("visibility","hidden");
	document.body.style.backgroundImage = "url("+Utils.Path+"images/image.jpg";
	Business.initializeVariables();
	Business.setAllImages();
	Business.setBusinessListImages();
	Business.createOptionDivs();
}
Business.initializeVariables=function()
{
	Business.index=0;
	Business.ansCounter=0;
}
Business.setAllImages=function()
{
	document.getElementById("homeImage").src=Utils.Path+"images/Home.png";
	document.getElementById("logoImage").src=Utils.Path+"images/logo.png";
	document.getElementById("playImg").src=Utils.Path+"images/playButton.png";
	document.getElementById("gameOver").innerHTML=Business.hardCodedData.gameOver;
	//document.getElementById("homeLogo").src=Utils.Path+"images/Home_button.png";
}

Business.setBusinessListImages=function()
{
	var i=0,parentDiv,image;
	parentDiv=document.getElementById("businessList");
	for(i=0;i<Business.businessImgArr.length;i++)
	{
		image=document.createElement("IMG");
		image.setAttribute("id","businessImg"+(i+1));
		image.setAttribute("class","businesses nopadding img-responsive");
		image.setAttribute("index",i);
		image.setAttribute("onclick","Business.selectBusiness(this.id);");
		image.setAttribute("src",Utils.Path+"images/"+Business.businessImgArr[i]);
		parentDiv.appendChild(image);
	}
}

Business.createOptionDivs=function()
{
	var i=0,parentDiv,option;
	parentDiv=document.getElementById("option");
	for(i=0;i<2;i++)
	{
		option=document.createElement("DIV");
		option.setAttribute("id","option"+(i+1));
		option.setAttribute("class","options nopadding col-xs-6 col-md-6 col-lg-6 col-sm-6");
		option.setAttribute("onclick","Business.checkAnswer(this.id);");
		parentDiv.appendChild(option);
	}
}

Business.playGame=function()
{
	$("#coverPage").hide();
	$("#gamePage").show();
	Business.ShowBusinessList();
}

Business.ShowBusinessList=function()
{
	$("#businessList").show();
	$("#questionDiv").hide();
	$("#activityDiv").hide();
}

Business.selectBusiness=function(img)
{
	document.body.style.backgroundImage = "url("+Utils.Path+"images/Bg.png";
	Business.index=document.getElementById(img).getAttribute("index");
	Business.playActivity();
	
}
Business.playActivity=function()
{
	$("#businessList").hide();
	$("#questionDiv").hide();
	$("#activityDiv").show();
	document.getElementById("gif").src=Utils.Path+"images/"+Business.businessVideoArr[Business.index];
	setTimeout(function()
	{
		Business.displayQuestion();
	},5000);
}

Business.displayQuestion=function()
{
	document.body.style.backgroundImage = "url("+Utils.Path+"images/Bg.png";
	$("#businessList").hide();
	$("#questionDiv").show();
	$("#activityDiv").hide();
	Business.rNo=Math.floor(Math.random()*Business.Questions.length);
	document.getElementById("question").innerHTML=Business.Questions[Business.rNo].question;
	Business.setOptions();
}

Business.setOptions=function()
{
	var i=0;
	for(i=0;i<2;i++)
	{
		console.log(Business.Questions[Business.rNo].options[i]);
		document.getElementById("option"+(i+1)).innerHTML=Business.Questions[Business.rNo].options[i];
	}
}

Business.checkAnswer=function(option)
{
	$("#questionDiv").hide();
	$("#activityDiv").show();
	if(document.getElementById(option).innerHTML==Business.Questions[Business.rNo].ans)
	{
		document.getElementById("gif").src=Utils.Path+"images/"+Business.activityArr[Business.index].images[Business.ansCounter];
		Business.ansCounter++;
	}
	else
	{
		document.getElementById("gif").src=Utils.Path+"images/wrong.png";
	}
	if(Business.ansCounter==Business.activityArr[Business.index].images.length)
	{
		setTimeout(function()
		{	
			Business.endGame();
		},2000);
	}
	setTimeout(function()
	{
		Business.displayQuestion();
	},3000);
}
Business.endGame=function()
{
	$("#endPage").show();
	$("#gamePage").hide();

}
