
var Profession = {};
var Utils = {};
Utils.Path = "";
var questionId = 0, startTime = 0, scoredMarks = 0, totalMarks = 10, resId = 0, label = '', level = 1;
var clickflag = false, correctOptionId = '';

//15 mar 2025
Profession.goBack = null;
Profession.bodyPartArray = [];							//body parts array
Profession.thali_array=[];
Profession.personId = 0;								//girl or boy id
Profession.homeFlag = false;
var openModalFlag = false, pantFlag = false, muteFlag = false, drawFlag = false, clearCanvasFlag = false, dimensionArr=[];
var clickItemDesc = '';
var imgCnt = 0, arrayimgcnt = 0, drawImgX = 0, drawImgY = 0, randomImgArray = [], raw_imgCtr=0;
var questionId = 0, startTime = 0, scoredMarks = 0, resId = 0, totalMarks = 10;
var fix_image_timer = 0,  plate_image_timer = 0;
Profession.tipCtr=0;
tipFlag=false, tableFlag=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; */
    if ((navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) && !(window.location.href.includes('http')))
        Utils.mobileDeviceFlag = true;
    else
        Utils.mobileDeviceFlag = false;
    setTimeout(function () {
        Profession.init();
    });
}, 200);

Profession.init = function () {
    $("#home,#gamePage, #finalPage, #responseBoxDiv,#instrPage,#tablePage").hide();
    $("#personPage,#finalThali,#finalPage,#screen3div,#home").hide();
	$("#prevScreenDiv, #clearButtonDiv, #nextScreenDiv").css("visibility", "hidden");
    document.title = Profession.hardCodedData.nameOfGame;
    document.getElementById("playImage").classList.add('pulse');
    Profession.setImages();
    Profession.initVariables();
    Profession.createButtons();         //For Screen-3
    //Profession.createPersonDivs();      //For Screen-3
    Profession.playCoverPageMusic();
    // Profession.createAcknowledgementDivs();
	Profession.createTable();
}

Profession.playCoverPageMusic = function()
{
    document.getElementById("playSound").src = Utils.Path + "sounds/instructions/Row0.mp3";      
    // document.getElementById("playSound").play();
}

Profession.setImages = function () {
    document.body.style.backgroundImage = Utils.Path + "url('images/skin/Cover.gif')";
    document.getElementById("home").src = Utils.Path + "images/skin/Home.png";
    // document.getElementById("logo").src = Utils.Path + "images/skin/logo.png";
    // document.getElementById("prevScreenImg").src = Utils.Path + "images/skin/pre_level.png";
    // document.getElementById("nextScreenImg").src = Utils.Path + "images/skin/next_level.png";
    document.getElementById("playImage").src = Utils.Path + "images/skin/Play.png";
    document.getElementById("playImage1").src = Utils.Path + "images/skin/Play.png";
    // document.getElementById("soundImage").src = Utils.Path + "images/skin/instructions.png";
    document.getElementById("nextImage").src = Utils.Path + "images/skin/Next.png";
    document.getElementById("muteImg").src = Utils.Path + "images/skin/sound.png";
    document.getElementById("muteBtnImg").src = Utils.Path + "images/skin/sound.png";
    document.getElementById("set").src = Utils.Path + "images/skin/Next.png";
    document.getElementById("clearButton").src = Utils.Path + "images/skin/replay.png";
    document.getElementById("playAgainBtn").src = Utils.Path + "images/skin/replay.png";
    // document.getElementById("creditbtn").src = Utils.Path + "images/skin/Credits.png";
    document.getElementById("gameOverTextDiv").innerHTML = Profession.hardCodedData.gameOver;
    document.getElementById("textDiv").innerHTML = Profession.tableText;
}

Profession.initVariables = function () {
    Profession.noOfDiv = 0;
    Profession.correctCnt = 0;
    Profession.questionCnt = 0;
    Profession.soundFlag = false;
    Profession.queArray = [];
    Profession.toolsArray = [];
    Profession.randomNoArray = [];
    Profession.profShowNoArray = [];
    Profession.correctToolsNameArray = [];
    Profession.attemptFlag = false;
    Profession.correctQueTimer = null;
    Profession.wrongQuestionTimer = null;
}

Profession.play = function () {
    $("#home, #gamePage").show();
    $("#playImage, #coverPage, #finalPage,#instrPage").hide();
    $("#screen1Div").css('display', 'block');
    $("#prevScreenDiv, #nextScreenDiv").css("visibility", "visible");   //For Screen-2 & screen-3
    document.getElementById("playImage").classList.remove('pulse');
    d = new Date();
    startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();

    // Profession.showProfessionPage();      //Screen - 1
    //Profession.callNext();              //Screen - 2
    Profession.playGame();              //Screen - 3
}

Profession.showProfessionPage = function()      //Screen - 1  //show all profession
{
    var professionArray = [];
    clickflag = false;
    Profession.attemptFlag = false;

    document.body.style.backgroundImage = Utils.Path + "url('images/skin/BG_Level_1.jpg')";
    $("#widges").show();
    $("#nextBtn, #screen3Div").hide();
    $("#screen1Div").css('display', 'block');
    $("#screen2Div").css('display', 'none');
    $("#prevScreenDiv, #clearButtonDiv, #setButton, #soundBtn").css("visibility", "hidden");
    $("#nextScreenSpan").text('Screen 2');
    document.getElementById("playSound").pause();
    
    for(i=0; i<Profession.dataArray.length; i++){
        professionArray.push(Profession.dataArray[i]);
    }
    shuffle(professionArray);
    Profession.noOfDiv = professionArray.length;
    Profession.makeProfessionGrid(professionArray);

    for(j=0; j<Profession.profShowNoArray.length; j++)
    {
        document.getElementById('profession'+Profession.profShowNoArray[j]).setAttribute('onclick','Profession.showModal(this.id)');
        $("#profession"+Profession.profShowNoArray[j]).data('professionImg', professionArray[j].queGif);
        $("#profession"+Profession.profShowNoArray[j]).data('professionName', professionArray[j].profession);
        $("#profession"+Profession.profShowNoArray[j]).data('professionNameAudio', professionArray[j].queImgAudio);      

        $('#professionImg'+Profession.profShowNoArray[j]).prop('src',Utils.Path + "images/professionImages/" + professionArray[j].queImg);  
        $('#professionImg'+Profession.profShowNoArray[j]).css('visibility', 'hidden');
    } 
    for(i=1; i<=Profession.noOfDiv; i++){                   //Hide the Div who don't have images.
        if(!Profession.profShowNoArray.includes(i)){
            $("#profession"+i).css('visibility', 'hidden');
        }
    }  
    Profession.showLoader();
}

Profession.showLoader = function()      /* Function to check all images are loaded or not */
{
    var imgs = document.images,
    len = imgs.length,
    counter = 0;
    $(".loader").show();
	$('.loader').css('display', 'flex');
    [].forEach.call( imgs, function( img ) {
        if(img.complete)
            incrementCounter();
        else
            img.addEventListener( 'load', incrementCounter, false );
    } );
    function incrementCounter() {
        counter++;
        if ( counter === len ) {
            $(".loader").hide();
            console.log( 'All images loaded!' );
            Profession.soundFlag = true;
            $('.profImgCss').css('visibility', 'visible');
            setTimeout(() => {
                // document.getElementById('playSound').src = Utils.Path + 'sounds/instructions/screen1_complete_Instr.mp3';
                // document.getElementById('playSound').play();
            },1000);
            if(!muteFlag){
                document.getElementById('playSoundInLoop').src = Utils.Path + "sounds/instructions/Classical_Carnivale.mp3";
                document.getElementById('playSoundInLoop').loop = true;
                document.getElementById('playSoundInLoop').play();
            }
        }
    }
}
/* //Function is for loader & Page load
$(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("MakeUpShakeUp");  
	setTimeout(function () {
		$("#coverpage").show(); 
		$("#personPage,#setButton,#frame,#endpage,#screen3div,#home").hide();
		$("#clearButtonDiv").css("visibility", "hidden");
		Profession.init();
	}, 300);
});

Profession.init = function () {
	Profession.createButtons();
} */


Profession.createButtons = function () {							//create body part buttons
	var buttonDiv;
	for (var i = 0; i < 8; i++) {
		if (i < 4)
			buttonDiv = document.getElementById('buttonDiv1');
		else
			buttonDiv = document.getElementById('buttonDiv2');
		Profession.createDivs(buttonDiv, i, "Profession.openModal(this)", Profession.buttonImages.imgname + i + Profession.buttonImages.imgtype, '');
		$("#buttonimg" + i).data("ans", Profession.Data[Profession.personId].data[i].id);
	}
	raw_imgCtr=0;
}
Profession.createNutritionSpans=function(){
	parentDiv=document.getElementById("nutrientBox");
	for(i=0;i<4;i++){
		newDiv = document.createElement("div");
		newDiv.setAttribute("id", "nutriDiv" + i);
		newDiv.setAttribute("class", "nutriDivs noPadding col-sm-12 col-lg-12 col-md-12 col-xs-12");
		parentDiv.appendChild(newDiv);
	}
}

Profession.showInstructions=function(){
    $("#coverPage").hide();
    $("#instrPage").show();
    document.body.style.backgroundImage = Utils.Path + "url('images/skin/BG_Level_3.png')";
	document.getElementById("mainInstr").innerHTML=Profession.Message[0].mainInstr;
	var Instructions = Profession.Instructions;
	var cont = document.getElementById('InstructionDesc');
    var ul = document.createElement('ul');
    ul.setAttribute('id', 'instructionList');
    for (var i = 0; i < Instructions.length; i++) {
		var li = document.createElement('li');   // create li element.
		li.innerHTML = Instructions[i]; 
		//li.innerHTML = Instructions[i]+"।"; //Add | to each sentence at last for Hindi text.
        ul.appendChild(li);     			
    }
    cont.appendChild(ul); 
	document.getElementById("playSound").src = Utils.Path + "sounds/instructions/Create your own plate.mp3";
    document.getElementById("playSound").play(); 
}

Profession.openModal = function (element) {							//shows modal
	var modalDiv, id; arrayimgcnt = 0, randomImgArray = [];
	$(".modal-css").css("visibility", "hidden");
	id = element.id;
	Profession.clickedButtonData = $("#" + id).data("ans");			//get data of clicked button
	//imgCnt = 0;
	switch(id){
		case 'buttonimg0':
			selectedIcon = 0;
			break;
		case 'buttonimg1':
			selectedIcon = 1;
			break;
		case 'buttonimg2':
			selectedIcon = 2;
			break;
		case 'buttonimg3':
			selectedIcon = 3;
			break;
		case 'buttonimg4':
			selectedIcon = 4;
			break;
		case 'buttonimg5':
			selectedIcon = 5;
			break;
		case 'buttonimg6':
			selectedIcon = 6;
			break;
		case 'buttonimg7':
			selectedIcon = 7;
			break;	
	} 

	while(randomImgArray.length != Profession.Data[Profession.personId].data[selectedIcon].selectedModalImg.length){
		randomimgCnt = Math.floor(Math.random() * Profession.Data[Profession.personId].data[selectedIcon].selectedModalImg.length);
		while(randomImgArray.includes(randomimgCnt)){
			randomimgCnt = Math.floor(Math.random() * Profession.Data[Profession.personId].data[selectedIcon].selectedModalImg.length);
		}
		randomImgArray.push(randomimgCnt);
	}
	arrayimgcnt = randomImgArray[imgCnt];
	$(".modal-css").empty();									//empty elements in the modal
	if ($("#" + id).data("ans") < 4)
		modalDiv = document.getElementById("modalDiv1");
	else
		modalDiv = document.getElementById("modalDiv2");
	
	if(!openModalFlag){
		openModalFlag = true;
		$(modalDiv).css("visibility", "visible");
		//number of rows you want to create
		for (var i = 0; i < Math.ceil(Profession.Data[Profession.personId].data[selectedIcon].imgCnt / 2); i++)
			Profession.createDivs(modalDiv, i, 'Profession.fix_plate_image(this)', '', $("#" + id).data("ans"));
		raw_imgCtr=0;
	}
	else{
		imgCnt = 0;
		openModalFlag = false;
		$(modalDiv).css("visibility", "hidden");
	}
}
Profession.createDivs = function (parentDiv, idName, onclickfun, img, No) {   //Divs for modal & body part buttons
	var buttonnewDiv, buttonImg, newDiv, subDiv, subImage, ctr=0;
	if (parentDiv == modalDiv1 || parentDiv == modalDiv2) {
		newDiv = document.createElement("div");
		newDiv.setAttribute("id", "passage" + idName);
		newDiv.setAttribute("class", "marginClass noPadding col-sm-12 col-lg-12 col-md-12 col-xs-12");
		parentDiv.appendChild(newDiv);
		for (var j = 0; j < 2; j++) {
			if (Profession.Data[Profession.personId].data[No].imgCnt > arrayimgcnt) {
				subDiv = document.createElement("div");
				subDiv.setAttribute("id", "subPassage" + idName + j);
				subDiv.setAttribute("class", " leftClass noPadding  col-sm-6 col-lg-6 col-md-6 col-xs-6");
				newDiv.appendChild(subDiv);

				subImage = document.createElement("img");
				subImage.setAttribute("class", "img-responsive col-sm-12 col-lg-12 col-md-12 col-xs-12 noPadding heightClass");
				subImage.setAttribute("onclick", onclickfun);
				subImage.setAttribute("id", "modalimg" + idName + j);
				// subImage.setAttribute("src", Utils.Path + Profession.Data[Profession.personId].data[No].imgname + arrayimgcnt + Profession.Data[Profession.personId].data[No].imgtype);
				subImage.setAttribute("src", Utils.Path+"images/thali_images/"+Profession.Data[Profession.personId].data[No].selectedModalImg[arrayimgcnt].rawImg);
				subDiv.appendChild(subImage);

				lableDiv = document.createElement("div");
				lableDiv.setAttribute("id", "lableDiv" + idName + j);
				lableDiv.setAttribute("class", " labels noPadding  col-sm-12 col-lg-12 col-md-12 col-xs-12");
				subDiv.appendChild(lableDiv);
				// lableDiv.innerHTML=Profession.Data[Profession.personId].data[No].selectedModalImg[arrayimgcnt].rawImg.slice(0,-4)
				lableDiv.innerHTML=Profession.Data[Profession.personId].data[No].selectedModalImg[arrayimgcnt].name

				
				$("#modalimg" + idName + j).data("ans", Profession.Data[Profession.personId].data[No].selectedModalImg[arrayimgcnt].id);
				$("#modalimg" + idName + j).data("description", Profession.Data[Profession.personId].data[No].selectedModalImg[arrayimgcnt].name);
				imgCnt++;
				arrayimgcnt = randomImgArray[imgCnt];
				raw_imgCtr++;
			}
		}
	}
	else {
		buttonnewDiv = document.createElement("div");
		buttonnewDiv.setAttribute("id", "button" + idName);
		buttonnewDiv.setAttribute("class", "buttonCss noPadding col-sm-12 col-lg-12 col-md-12 col-xs-12");
		parentDiv.appendChild(buttonnewDiv);

		buttonImg = document.createElement("img");
		//if(idName<4)
			buttonImg.setAttribute("class", "img-responsive col-sm-8 col-lg-10 col-md-10 col-xs-8 col-sm-offset-2 col-lg-offset-1 col-md-offset-1 col-xs-offset-2 noPadding");
		// else
		// buttonImg.setAttribute("class", "img-responsive col-sm-10 col-lg-10 col-md-10 col-xs-10 col-sm-offset-2 col-lg-offset-2 col-md-offset-2 col-xs-offset-2 noPadding");

		buttonImg.setAttribute("onclick", onclickfun);
		buttonImg.setAttribute("id", "buttonimg" + idName);
		buttonImg.setAttribute("src", Utils.Path + img);
		buttonnewDiv.appendChild(buttonImg);
	}
}
Profession.playGame = function () 								//Function called on button click to show screen-3
{
	Profession.thali_array=[];
	document.getElementById("playSound").pause();
	Profession.goBack = null;
	if(!Profession.attemptFlag){
		scoredMarks = -1;
		// Profession.calculateScore();
		Profession.createNutritionSpans()
	}
	$("#screen1Div").css('display', 'none');
	document.body.style.backgroundImage = Utils.Path + "url('images/skin/BG_Level_3.png')";
	if(muteFlag == false){
		document.getElementById("muteImg").src = Utils.Path + "images/skin/sound.png";
		document.getElementById("playSoundInLoop").src = Utils.Path + "sounds/instructions/Classical_Carnivale.mp3";
		document.getElementById("playSoundInLoop").loop = true;
		document.getElementById("playSoundInLoop").play()
	}
	// document.getElementById("playSound").src = Utils.Path + "sounds/instructions/screen3_complete_Instr.mp3";
    // document.getElementById("playSound").play(); 
	//getDuration(Utils.Path + 'sounds/instructions/screen3_makeprofe_instr.mp3');
	
	document.getElementById('set').setAttribute('onclick', "Profession.setPicture()");
	//document.body.style.backgroundImage = "url(" + Utils.Path + "Images/professionMakingImages/background2.png)";
	$("#personPage,#finalThali,#endpage,#acknowledgementDiv,#nextBtn, #finalPage, #widges").hide();
	$("#screen2Div").css('display', 'none');
	$("#buttonDiv1,#buttonDiv2,#modalDiv1,#screen3div,#modalDiv2").show();
	$("#nextScreenDiv, #clearButtonDiv, #soundBtn, .modal-css").css("visibility", "hidden");
	$("#setButton, #muteButton").css("visibility", "visible");
	Profession.canvas = document.getElementById("myCanvas");	
	Profession.context = Profession.canvas.getContext("2d");
	Profession.selectPerson();
}

Profession.selectPerson = function (element) {											//selects Gender
	//Profession.personId = $(element).data("ans");
	Profession.personId = 0;							//Choose Girl or Boy
	Profession.homeFlag = false;
	document.getElementById('clearButtonDiv').style.visibility = "visible";
	//document.body.style.backgroundImage = "url(" + Utils.Path + "Images/professionMakingImages/background3.png)";
	// width = 170;												//width of body image
	// height = 350; 		
	width = 900;												//width of body image
	height = 650;										//height of body image
	Profession.context.clearRect(0, 0, 200, 400);
	/* $("#personPage").hide();
	$("#buttonDiv1,#muteButton,#setButton,#buttonDiv2,#modalDiv1,#screen3div,#modalDiv2").show(); */
	Profession.createBody();
}
Profession.createBody = function () {													//show human body
	Profession.bodyPartArray = [];
	Profession.sourceArr=[];
	Profession.goBack = "personMenu";
	
	// Profession.fix_plate_image();
	Profession.context.clearRect(0,0,1200,800);
	const plateImage = new Image();
	plateImage.src = Utils.Path + Profession.bodyImages.imgname + Profession.bodyImages.imgtype;
	plateImage.onload = function () {
		Profession.context.drawImage(plateImage,drawImgX, drawImgY, width, height);
	};
}

Profession.fix_plate_image = function(element){
	Profession.context.clearRect(0,0,1200,1000);
	const plateImage = new Image();
	plateImage.src = Utils.Path + Profession.bodyImages.imgname + Profession.bodyImages.imgtype;
	plateImage.onload = function () {
		Profession.context.drawImage(plateImage,drawImgX, drawImgY, width, height);
	};

	// fix_image_timer = setTimeout(Profession.fixImage(element), 500);
	Profession.fixImage(element);
}

Profession.fixImage = function (element) {									//push selected body part items into Array

	var x, y, width, height;
	drawFlag = true;
	Profession.homeFlag = true;
	document.getElementById("playSound").src = Utils.Path + "sounds/instructions/propDrag.mp3";
	document.getElementById("playSound").play();
	let plate_obj = {}
	plate_obj.x = Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].x;
	plate_obj.y = Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].y;
	plate_obj.width = Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].width;
	plate_obj.height = Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].height;
	plate_obj.Carbs = Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].Carbs;
	plate_obj.Protien = Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].Protien;
	plate_obj.Fats = Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].Fats;
	plate_obj.Fibre = Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].Fibre;
	

	// vegetableImage.src = Utils.Path+"images/thali_images/"+Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].plateImg;
	Profession.thali_array[Profession.clickedButtonData] = plate_obj;
	Profession.sourceArr[Profession.clickedButtonData] = Utils.Path+"images/thali_images/"+Profession.Data[Profession.personId].data[Profession.clickedButtonData].selectedModalImg[$("#" + element.id).data("ans")].plateImg
	console.log('Profession.thali_array', Profession.thali_array);

	// To draw image when click on image. issue-not able to clear the particular image
	/* let vegetableImage = new Image();
	vegetableImage.onload = function () {
		Profession.context.drawImage(vegetableImage,x, y, width, height);
	}; */
	
	// To draw images using array and erase using array.
	/* for(let i=0; i<Profession.thali_array.length; i++)
	{
		let vegetableImage = new Image();
		vegetableImage.src = Profession.sourceArr[i]
		vegetableImage.onload = function () {
			eval(Profession.thali_array[i])
		};	
	} */


	for(let i=0; i<Profession.thali_array.length; i++){
		if(Profession.thali_array[i])
			drawImagesSequentially(Profession.sourceArr[i], Profession.thali_array[i]);
	}
}

async function drawImagesSequentially(src, plate_obj) {
	await drawImage(src, plate_obj.x, plate_obj.y, plate_obj.width, plate_obj.height); // Draw one image at a time
	await delay(600); // Optional: Add delay (500ms) between images for smooth transition
}
function drawImage(src, x, y, width, height) {
	return new Promise((resolve) => {
		let img = new Image();
		img.src = src;
		img.onload = function () {
			Profession.context.drawImage(img, x, y, width, height);
			resolve(); // Proceed to next image once current image is drawn
		};
	});
}
function delay(ms) {
	return new Promise(resolve => setTimeout(resolve, ms)); // Helper function for delay
}


Profession.setPicture = function () {                                           //creates copy of  human body
    $("#finalThali, #nutrientBox").show();
    $("#endpage,#screen3div").hide();
    $("#prevScreenDiv, #nextScreenDiv, #muteButton, #clearButtonDiv").css("visibility", "hidden");
	protien=0,fats=0,carbs=0,fibre=0
    for(i=0;i<Profession.thali_array.length;i++){
		if(Profession.thali_array[i]){
			protien=protien+Profession.thali_array[i].Protien
			fats=fats+Profession.thali_array[i].Fats
			carbs=carbs+Profession.thali_array[i].Carbs
			fibre=fibre+Profession.thali_array[i].Fibre
		}
	}
	document.getElementById("nutriDiv0").innerHTML="प्रथिने: "+protien.toFixed(2)+" ग्रॅम";
	document.getElementById("nutriDiv1").innerHTML="स्निग्ध पदार्थ: "+fats.toFixed(2)+" ग्रॅम";
	document.getElementById("nutriDiv2").innerHTML="कर्बोदके: "+carbs.toFixed(2)+" ग्रॅम";
	document.getElementById("nutriDiv3").innerHTML="तंतूमय पदार्थ: "+fibre.toFixed(2)+" ग्रॅम";
	cloneCanvas(Profession.canvas);
	Profession.showTips()
	$("#prevTip").css("opacity",0.5);
}

Profession.clickTip=function(ele){
	var data= parseInt(document.getElementById(ele).getAttribute("data"))
	$("#prevTip").css("opacity",1);
	$("#nextTip").css("opacity",1);

	if(data){
		if(Profession.tipCtr<(Profession.tipsArray.length-1))
			Profession.tipCtr++;
		if(Profession.tipCtr==Profession.tipsArray.length-1)
			$("#nextTip").css("opacity",0.5);
	}
	else{
		if(Profession.tipCtr>0)
			Profession.tipCtr--;
		if(Profession.tipCtr==0)
			$("#prevTip").css("opacity",0.5);
	}
	Profession.showTips()
}
Profession.showTips=function(){
	document.getElementById("tipSpan").innerHTML= Profession.tipsArray[Profession.tipCtr];
}

function cloneCanvas(oldCanvas) {                                   //creates clone for human body
    var newCanvas, newContext, newDiv;
    //document.body.style.backgroundImage = "url(" + Utils.Path + "images/professionMakingImages/background4.png)";
    document.getElementById("photographDiv").innerHTML = "";
    newCanvas = document.createElement('canvas');         //create a new canvas
    newContext = newCanvas.getContext('2d');
    newCanvas.setAttribute("class", "col-lg-12 col-md-12 col-xs-12 col-sm-12 noPadding");
    newCanvas.width = 600;                    //set dimensions   
    newCanvas.height = 500;
    newContext.drawImage(oldCanvas, 0, 0,oldCanvas.width,oldCanvas.height,0,60,600,500);              //apply the old canvas to the new one
    photographDiv.append(newCanvas);
    Profession.photoFrame();
}
Profession.photoFrame = function () {
    Profession.homeFlag = false;
    // document.getElementById("playSound").src = Utils.Path + "sounds/instructions/Row23.mp3";
    // document.getElementById("playSound").play();
    document.getElementById("message").innerHTML = Profession.Message[0].message;
    $("#frame").addClass("animated zoomIn");
    document.getElementById('set').setAttribute('onclick', "Profession.gameOver()");

		if(drawFlag)								//last page photo frame
		scoredMarks = 10;
	else if(clearCanvasFlag)
		scoredMarks = -1;
	else
		scoredMarks = -1;
	drawFlag = false;
	clearCanvasFlag = false;
	// Profession.calculateScore();
}

/* Profession.callHome = function () {								//home click function
	document.getElementById("playSound").pause();
	if (Profession.goBack == "personMenu")
		Profession.playGame();
	else {
		Profession.homeFlag = false;
		location.reload(true);
	}
	if (Profession.homeFlag == true) {
		scoredMarks = 0;
		Profession.calculateScore();
	}
} */

Profession.muteBgSound = function()
{
    var displayScreen3 = document.getElementById("screen3Div").style.display;

	if(!muteFlag){
		muteFlag = true;
		$('#muteImg').prop("src",Utils.Path+"images/skin/sound_off.png");		//Screen-3
		$('#muteBtnImg').prop("src",Utils.Path+"images/skin/sound_off.png");	//Screen-1 & Screen-2
		document.getElementById('playSoundInLoop').pause();
	}
	else{
		muteFlag = false;
		$('#muteImg').prop("src",Utils.Path+"images/skin/sound.png");		//Screen-3
		$('#muteBtnImg').prop("src",Utils.Path+"images/skin/sound.png");	//Screen-1 & Screen-2
		if(displayScreen3 == 'block'){				//Screen-3
			document.getElementById('playSoundInLoop').src = Utils.Path + "sounds/instructions/Classical_Carnivale.mp3";
			document.getElementById('playSoundInLoop').loop = true;
			document.getElementById('playSoundInLoop').play();
		}
		else{										//Screen-1 & Screen-2
			document.getElementById('playSoundInLoop').src = Utils.Path + "sounds/instructions/Classical_Carnivale.mp3";
			document.getElementById('playSoundInLoop').loop = true;
			document.getElementById('playSoundInLoop').play();
		}
	}
}

Profession.calculateScore = function () {										//calculates score
	console.log(resId, questionId, scoredMarks, totalMarks, 1, startTime, label);
	if (Utils.mobileDeviceFlag)
		Android.addScore(resId, questionId, scoredMarks, totalMarks, 1, startTime, label);
}

Profession.showCredits = function () {
	document.getElementById("acknowledgementDiv").style.display = "block";
	document.getElementById("gameOverTextDiv").style.display = "none";
	var video = document.getElementById("ackVideo");
  	video.src =Utils.Path+ "images/skin/Pradigi-Siemens_MR_July_25.mp4";
  	video.load(); 
  	video.play(); 
}

Profession.gameOver = function () {
	if(tableFlag)
		tableFlag=false
	else
		tableFlag=true
	if(tableFlag==false){
		$("#finalThali, #acknowledgementDiv, #nutrientBox, #tablePage").hide();
		$("#finalPage").show();
		// $("#prevScreenDiv").css("visibility", "visible");
		$("#nextScreenDiv, #widgesScreen3, #setButton").css("visibility", "hidden");
		Profession.goBack = null;
		document.getElementById("playSound").pause();
		document.getElementById("playSoundInLoop").pause();
		setTimeout(function()
		{
			Profession.showCredits();
		},1000);
	}
	else{
		$("#finalThali, #acknowledgementDiv, #nutrientBox").hide();
		$("#tablePage").show()
	}
}

Profession.callHome = function () {
    document.getElementById("playSound").pause();
    document.getElementById("playSoundInLoop").pause();
    if (Profession.attemptFlag) {
        Profession.calculateScore();
        Profession.attemptFlag = false;
    }
    location.reload();
}

Profession.playAgain = function () {
    $("#finalPage, #acknowledgementDiv").hide();
    $("#gamePage,#gameOverTextDiv").show();
    $("#soundBtn").css("visibility", "visible");
    document.getElementById("screen1Div").innerHTML = '';
    document.getElementById("nextBtn").classList.remove('blink_me');
    Profession.initVariables();
    Profession.play();
}

Profession.callSound = function () {
    var displayScreen2 = document.getElementById("screen2Div").style.display;
    if(displayScreen2 == 'block'){             //When displaying Screen - 1
        document.getElementById("playSound").src = Utils.Path + "sounds/audios/" + Profession.randomQue.queImgInstrAudio;      
        document.getElementById("playSound").play();
    }
} 


Profession.showAcknowledgement = function () {
    $("#acknowledgementDiv").show();
}

function shuffle(randomArray) {
    var arrayLength = randomArray.length;
    var temp, random_index;
    while (arrayLength > 0) {
        random_index = Math.floor(Math.random() * arrayLength);
        arrayLength--;
        temp = randomArray[arrayLength];
        randomArray[arrayLength] = randomArray[random_index];
        randomArray[random_index] = temp;
    }
    return (randomArray);
}

Profession.createTable=function(){
	const foodData = [
		{ foodGroup: "धान्ये /मिलेटस्", year1: { girls: "240 ग्रॅ", boys: "300 ग्रॅ" }, year2: { girls: "330 ग्रॅ", boys: "420 ग्रॅ" }, year3: { girls: "330 ग्रॅ", boys: "450 ग्रॅ" } },
		{ foodGroup: "डाळी", year1: { girls: "60 ग्रॅ", boys: "60 ग्रॅ" }, year2: { girls: "60 ग्रॅ", boys: "75 ग्रॅ" }, year3: { girls: "75 ग्रॅ", boys: "90 ग्रॅ" } },
		{ foodGroup: "दूध आणि दुग्धजन्य पदार्थ", year1: { girls: "500 मिली ग्रॅ", boys: "500 मिली ग्रॅ" }, year2: { girls: "500 मिली ग्रॅ", boys: "500 मिली ग्रॅ" }, year3: { girls: "500 मिली ग्रॅ", boys: "500 मिली ग्रॅ" } },
		{ foodGroup: "कंदमुळे व कंदभाज्या", year1: { girls: "100 ग्रॅ", boys: "100 ग्रॅ" }, year2: { girls: "100 ग्रॅ", boys: "150 ग्रॅ" }, year3: { girls: "150 ग्रॅ", boys: "200 ग्रॅ" } },
		{ foodGroup: "हिरव्या पाले भाज्या", year1: { girls: "100 ग्रॅ", boys: "100 ग्रॅ" }, year2: { girls: "100 ग्रॅ", boys: "100 ग्रॅ" }, year3: { girls: "100 ग्रॅ", boys: "100 ग्रॅ" } },
		{ foodGroup: "इतर भाज्या ", year1: { girls: "200 ग्रॅ", boys: "200 ग्रॅ" }, year2: { girls: "200 ग्रॅ", boys: "200 ग्रॅ" }, year3: { girls: "200 ग्रॅ", boys: "200 ग्रॅ" } },
		{ foodGroup: "फळे", year1: { girls: "100 ग्रॅ", boys: "100 ग्रॅ" }, year2: { girls: "100 ग्रॅ", boys: "100 ग्रॅ" }, year3: { girls: "100 ग्रॅ", boys: "100 ग्रॅ" } },
		{ foodGroup: "साखर", year1: { girls: "30 ग्रॅ", boys: "30 ग्रॅ" }, year2: { girls: "25 ग्रॅ", boys: "25 ग्रॅ" }, year3: { girls: "25 ग्रॅ", boys: "30 ग्रॅ" } },
		{ foodGroup: "स्निग्ध पदार्थ /तेल (दृश्यमान)", year1: { girls: "30 ग्रॅ", boys: "35 ग्रॅ" }, year2: { girls: "35 ग्रॅ", boys: "40 ग्रॅ" }, year3: { girls: "35 ग्रॅ", boys: "50 ग्रॅ" } }
	  ];
  
	  const tbody = document.querySelector("#data-table tbody");
  
	  foodData.forEach(food => {
		const row = document.createElement("tr");
		row.innerHTML = `
		  <td>${food.foodGroup}</td>
		  <td>${food.year1.girls}</td>
		  <td>${food.year1.boys}</td>
		  <td>${food.year2.girls}</td>
		  <td>${food.year2.boys}</td>
		  <td>${food.year3.girls}</td>
		  <td>${food.year3.boys}</td>
		`;
		tbody.appendChild(row);
	  });
}