
var Classification={};
Classification.level=0;
Classification.imageArray=[];
Classification.imageArrayPNG=[];
$(document).ready(function(){
	$(".se-pre-con").fadeOut("slow");
	setTimeout(function(){
	document.body.style.backgroundImage="url(images/BG.png)";
	document.getElementById('coverpage').style.display="block";
	document.getElementById('gamapage').style.display="none";
	document.getElementById('homeDiv').style.visibility="hidden";
	Classification.setImage();
	},200);
});

Classification.playGame=function()
{
	document.body.style.backgroundImage="url('images/BG.png')";
	document.getElementById('gamapage').style.display="block";
	document.getElementById('coverpage').style.display="none";
	document.getElementById('homeDiv').style.visibility="visible";
	Classification.createDiv();
}

Classification.setImage=function()
{
	document.getElementById('logo').src="Logos/logo.png";
	document.getElementById('play').src="images/Play.png";
	document.getElementById('home').src="images/Home.png";
//	document.getElementById('next').src="images/Next.png";
}

Classification.createDiv=function()
{
	var divDragElm=0,imgDragElm=0,parentElement=0,i=0,j=0,cnt=0;
	for(var i=1;i<=3;i++)
	{
		parentElement=document.createElement('div');
		parentElement.setAttribute('id','parentDiv'+i);
		parentElement.setAttribute('class','col-xs-12 col-sm-12 col-lg-12 col-md-12');
	 	for(var j=1;j<=3;j++)	
		{			
		 	divDragElm=document.createElement('div');
			divDragElm.setAttribute('id','divDrag'+i+j);
			divDragElm.setAttribute('class','marginTop noPaddingcls col-sm-2 col-lg-2 col-md-2 col-xs-2 col-sm-offset-1 col-lg-offset-1 col-md-offset-1 col-xs-offset-1');
			imgDragElm=document.createElement('img');
			imgDragElm.setAttribute('id','imgDrag'+i+j);
			imgDragElm.setAttribute('class','noPaddingcls img-responsive col-sm-12 col-lg-12 col-md-12 col-xs-12');
			$(imgDragElm).draggable(
			{revert:'invalid'});
			$('.dropBox').droppable({
			drop:Classification.checkElements});
			divDragElm.append(imgDragElm);		
			parentElement.append(divDragElm);
			dragBox.append(parentElement);
		}
	}
	Classification.getMainLevel();
}
Classification.getMainLevel=function()
{
	var randomMainLevel=0,object='';
	Classification.randomMainLevel=Math.floor(Math.random() * (Classification.shapeAndColor.length));//shape or color
	console.log(Classification.shapeAndColor[Classification.randomMainLevel]);
	object=Classification.shapeAndColor[Classification.randomMainLevel].level;
	document.getElementById('instuctionDiv').innerHTML=Classification.hardcoded.question+ " " +object;
	Classification.playLevelWise();
}
Classification.playLevelWise=function()
{
	var colorCnt=0,objectCnt=0,object='',randomImageIndex='';
	colorCnt=Classification.shapeAndColor[Classification.randomMainLevel].data[Classification.level].colorCnt;
	objectCnt=Classification.shapeAndColor[Classification.randomMainLevel].data[Classification.level].objectCnt;
	if(objectCnt != null)
	{
		for(var i=0;i<objectCnt;i++)
		{
			randomImageIndex=Math.floor(Math.random() * 3);
			flag=Classification.checkData(randomImageIndex,Classification.imageArray);
			if(!flag)
				Classification.imageArray.push(randomImageIndex);
		} 
		console.log(colorCnt);
		console.log(objectCnt);
		console.log(Classification.imageArray);
	}
	Classification.createImages(colorCnt,objectCnt)
}
Classification.createImages=function(colorCnt,objectCnt)
{
	var index=0,cnt=0,str='';
	for(var i=0;i<Classification.imageArray.length;i++)
	{
		index=Classification.imageArray[i];
		for(j=0;j<colorCnt;j++)
		{	
			str=Classification.imageData[j].imageNames[index] +'.png';
			if(objectCnt == 1)
			{
				Classification.imageArrayPNG.push(str);
				Classification.imageArrayPNG.push(str);
				Classification.imageArrayPNG.push(str);
				
			}

		}
	}
	console.log(Classification.imageArrayPNG);
	Classification.shuffleImageData();
}
Classification.checkData=function(data,tempArray)
{
	var flag=0;
	if(tempArray.length==0)
		return 0;
	for(var j=0;j<tempArray.length;j++)
	{
		if(tempArray[j]==data)
		{
			flag=1;
			break;
		}
	}
	return flag;
}
Classification.shuffleImageData=function()
{
	var randomVar=0,temp=0;
	Classification.imageArray=Classification.imageData.slice();
	for(var i=0;i<Classification.imageArrayPNG.length;)
	{
		randomVar=Math.floor(Math.random() * (Classification.imageArrayPNG.length));
		if(i!=randomVar)
		{
			temp =Classification.imageArrayPNG[randomVar];
			Classification.imageArrayPNG[randomVar] = Classification.imageArrayPNG[i];
			Classification.imageArrayPNG[i] = temp;
			i++;
		}
	}
	console.log(Classification.imageArrayPNG);
	Classification.setAllImages();
}

Classification.setAllImages=function()
{
	var cnt=0;
	for(var i=1;i<=3;i++)
	{
		for(j=1;j<=3;j++)
		{
			document.getElementById('imgDrag'+i+j).src="images/"+Classification.imageArrayPNG[cnt];
			/* $('#imgDrag'+i+j).data("color",Classification.imageArrayPNG[cnt].color);
			$('#imgDrag'+i+j).data("shape",Classification.imageArrayPNG[cnt].shape); */
			cnt++;
		}
	}
	//Classification.playInstruction();
}
/*
Classification.checkElements=function(event,ui)
{
	var obj,dropData,dropid;
	if(Classification.object == "shape")
		obj=$(ui.draggable).data("shape");
	else
		obj=$(ui.draggable).data("color");
	
	dropid=$(this).prop("id");
	dropData=document.getElementById(dropid).getAttribute("boxdata");

	if(obj != dropData)
	{
		ui.draggable.draggable({
			revert: true
					});
	}
	else
	{
		ui.draggable.draggable({
			revert: false
					});
	}
	
}
Classification.playInstruction=function()
{
	var randomNumber=0,object='',instruction='separate out images by';
	randomVar=Math.floor(Math.random() * (Classification.shapeAndColor.length));
	Classification.object=Classification.shapeAndColor[randomVar];
	if(Classification.object=="color")
	{
		randomVar=Math.floor(Math.random() * (Classification.color.length));
		instruction=instruction+" "+Classification.object;
	}
	else
	{
		randomVar=Math.floor(Math.random() * (Classification.shape.length));
		Classification.innerObject=Classification.shape[randomVar];
		instruction=instruction+" "+Classification.object;
	}
	instuctionDiv.append(instruction);
	if(Classification.object=="color")
	{
		for(var i=1;i<=3;i++)
		{
			document.getElementById('para'+i).innerHTML=Classification.color[i-1];
			document.getElementById('dropBox'+i).setAttribute("boxdata",Classification.color[i-1]);
		}
	}
	else
	{
		for(var i=1;i<=3;i++)
		{
			document.getElementById('para'+i).innerHTML=Classification.shape[i-1];
			document.getElementById('dropBox'+i).setAttribute("boxdata",Classification.shape[i-1]);

		}
	}
}
 */var arr=[]
arr.push( {firstName:"John", lastName:"Doe", age:46});
arr.push( {firstName:"John", lastName:"Doe", age:49});
document.getElementById("demo").innerHTML = arr.length;