var PizzaParty={};
PizzaParty.countElement1=[];
PizzaParty.countElement2=[];
var value1=0,value2=0;
PizzaParty.init=function()
{
	document.body.style.backgroundImage = "url(images/"+PizzaParty.hardCodedData.cover_page+")";					
}

PizzaParty.playgame=function()
{
	submitbtn.style.visibility="visible";
	outerDiv.style.display="block";
	PizzaParty.setImages();
	PizzaParty.setDragedImages();
	PizzaParty.setQuestion();
	PizzaParty.designPizza();
}

PizzaParty.setImages=function()
{
	correctWrongAnimationImage.src="images/think.png";
	pizzaImage.src="images/Pizza.png";
	fridgeDiv.style.backgroundImage="url(images/Fridge_2Items.png)";
	objectCountDiv.style.backgroundImage="url(images/Recipe.png)";
	submitbtn.src="images/checkBtn.gif";
	document.getElementById("palyBtnDiv").style.display="none";
}

PizzaParty.setDragedImages=function()
{
	var i=0,img1,img2;
	for(i=0;i<12;i++)
	{
		img1=document.createElement('img');
		img1.setAttribute("id","imgItem"+i);
		img1.setAttribute("class","nopadding fruits innerImg");
		img1.setAttribute("index",1);
		img1.setAttribute("counter",i);
		img1.setAttribute("src","images/Pineapple.png");
		items.appendChild(img1);
		
		img2=document.createElement('img');
		img2.setAttribute("id","imgItem1_"+i);
		img2.setAttribute("class","nopadding fruits innerImg1");
		img2.setAttribute("index",2);
		img2.setAttribute("counter",i);
		img2.setAttribute("src","images/Pepper.png");
		items1.appendChild(img2);
	}
}

PizzaParty.setQuestion=function()
{
	value1=(Math.floor(Math.random() *10) + 1);
	value2=(Math.floor(Math.random() *10) + 1);
	objText1.innerHTML=value1;
	objText2.innerHTML=value2;
	objImage1.src="images/Pineapple.png";
	objImage2.src="images/Pepper.png";
}

PizzaParty.designPizza=function()
{
	$(".fruits").draggable({revert:"invalid"});
	$("#pizzaImageDiv").droppable(
	{
		accept:'.fruits',
		drop:function(event,ui)
		{	
			var draggableId=0,counter=0;
			draggableIndex = ui.draggable.attr("index");
			counter = ui.draggable.attr("counter");
			if(draggableIndex==1 && PizzaParty.countElement1.includes(counter)==false)
			{
				PizzaParty.countElement1.push(counter);
			}
			if(draggableIndex==2 && PizzaParty.countElement2.includes(counter)==false)
			{
				PizzaParty.countElement2.push(counter);
			}
		}	
	});
	
	$(".itemClass").droppable(
	{
		accept:'.fruits',
		drop:function(event,ui)
		{
			var draggableId=0,counter=0,arrayIndex=0;
			draggableIndex = ui.draggable.attr("index");
			counter = ui.draggable.attr("counter");
			if(draggableIndex==1 && PizzaParty.countElement1.includes(counter)==true)
			{
				arrayIndex = PizzaParty.countElement1.indexOf(counter);
				if (arrayIndex > -1)
				{
				  PizzaParty.countElement1.splice(arrayIndex, 1);
				}
			}
			if(draggableIndex==2 && PizzaParty.countElement2.includes(counter)==true)
			{
				arrayIndex = PizzaParty.countElement2.indexOf(counter);
				if (arrayIndex > -1)
				{
				  PizzaParty.countElement2.splice(arrayIndex, 1);
				}
			}
		}
	});
}

PizzaParty.checkAnswer=function()
{
	var ans=value1+value2;
	
	if(value1==PizzaParty.countElement1.length && value2==PizzaParty.countElement2.length)
	{
		Answer.innerHTML=value1+"&nbsp&nbsp+&nbsp&nbsp"+value2+"&nbsp&nbsp=&nbsp&nbsp"+ans;
		correctWrongAnimationImage.src="images/happy1.gif";
		setTimeout(function()
		{
			location.reload();
		},3000);
	}
	else
	{
		correctWrongAnimationImage.src="images/nooo.gif";
		setTimeout(function()
		{
			correctWrongAnimationImage.src="images/think.png";
		},3000);
	}
}
