// JavaScript Document
var xmlHttp,afterLoad,Img1,Img2,timer,lastLeft,lastLeft2,movLeft,lastTop,lastTop2,movTop,shotsArr,currID,currCount,timeImg,loaded,currImg;
function GetXmlHttpObject()//XML HTTP Object
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp;
}

function showInfo(x)
{
	var url="get_info.php";
	url=url+"?id="+x;
	currID=x;
	document.getElementById("infoDetails").style.overflow="auto";
	document.getElementById("infoDetails").innerHTML="<table cellpadding='0' cellspacing='0' border='0' width='310' height='180'><tr><td valign='middle' align='center' width='310'><img src='"+LoadImgSRC+"' /></td></tr></table>";
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=stateChangedInfo;
	xmlHttp.open("GET",url,true);
	lastLeft=-320; lastLeft2=0;
	movLeft=-320/15;
	document.getElementById("leftInfo").style.zIndex=1;
	document.getElementById("infoText").style.top="31px";
	document.getElementById("infoShots").style.top="321px";	
	document.getElementById("ButtonShots").style.visibility="hidden";
	document.getElementById("screen1").innerHTML="<img src='"+LoadImgSRC+"' />";document.getElementById("screen2").innerHTML="<img src='"+LoadImgSRC+"' />";
	Img1=document.getElementById("rollingblock"); Img2=document.getElementById("infoScreen");
	timer=setInterval("Animate(0)",12);
	loaded=new Array();
	xmlHttp.send(null);
}
function stateChangedInfo()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("infoDetails").innerHTML=xmlHttp.responseText;
		var url="get_screenshot.php?id="+currID;
		xmlHttp=GetXmlHttpObject();
		xmlHttp.onreadystatechange=stateChangedShots;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}
function stateChangedShots()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		shotsArr=xmlHttp.responseText.split("#");
		if(parseInt(shotsArr[0])>0)
		{
			preloadShots();
			document.getElementById("ButtonShots").style.visibility="visible";
		}
		document.getElementById("totalNo").innerHTML=shotsArr[0];
		document.getElementById("currNo").innerHTML="0";
	}
}
function preloadShots()
{
	if(document.images){
		document.PS=new Array();
		var i,j=parseInt(shotsArr[0]),k=0;
		for(i=1;i<=j;i++) {
			document.PS[k]=new Image;
			document.PS[k].src=shotsArr[i];
			loaded[k++]=false;
		}
		currCount=0;
		clearInterval(timeImg);
		timeImg=setInterval("checkLoad()",20);
		checkLoad();
	}
}
function checkLoad() {
	for (i = 0; i <= document.PS.length; i++) {
		if (loaded[i] == false && document.PS[i].complete) {
			loaded[i] = true;
			currCount++;
		}
	}
	if(currCount==document.PS.length)
		clearInterval(timeImg);
}

function Animate(type)
{
	var the_style,the_style2;
	the_style=Img1.style;
	the_style2=Img2.style;
	the_style.left = ""+(parseFloat(the_style.left) + movLeft)+"px";
	the_style2.left= ""+(parseFloat(the_style2.left) + movLeft)+"px";
	//alert("here");
  	if((parseInt(the_style.left)<=lastLeft&&!type)||(parseInt(the_style.left)>=lastLeft&&type))
	{
		the_style.left=""+lastLeft+"px"; 
		the_style2.left=""+lastLeft2+"px";
		clearInterval(timer);
		return;
	}
}
function UpAnimate(type)
{
	var the_style,the_style2;
	the_style=Img1.style;
	the_style2=Img2.style;
	the_style.top = ""+(parseFloat(the_style.top) + movTop)+"px";
	the_style2.top= ""+(parseFloat(the_style2.top) + movTop)+"px";
  	if((parseInt(the_style.top)<=lastTop&&!type)||(parseInt(the_style.top)>=lastTop&&type))
	{
		the_style.top=""+lastTop+"px"; 
		the_style2.top=""+lastTop2+"px";
		clearInterval(timer);
		//alert("here");
		return;
	}
}
function goBack()
{
	lastLeft=0; lastLeft2=320;
	movLeft=320/15;
	document.getElementById("leftInfo").style.zIndex=-1;
	document.getElementById("infoDetails").style.overflow="visible";
	Img1=document.getElementById("rollingblock"); Img2=document.getElementById("infoScreen");
	timer=setInterval("Animate(1)",12);
}
function screenShots()
{
	lastTop=-259; lastTop2=31;
	movTop=-290/12;
	Img1=document.getElementById("infoText"); Img2=document.getElementById("infoShots");
	document.getElementById("screen1").style.left="0px"; document.getElementById("screen2").style.left="0px";
	currImg=0;
	if(shotsArr.length>0)
	{
		if(parseInt(shotsArr[0])>0)
		{
			document.getElementById("currNo").innerHTML="1";
			currImg=1;
			if(loaded[0]==true)
				document.getElementById("screen1").innerHTML="<img src='"+shotsArr[1]+"' />";
			else
			{
				clearTimeout(shotsTimer);
				getShotsImg(1);
			}
		}
		else
			document.getElementById("screen1").innerHTML="No ScreenShots Available";
	}
	timer=setInterval("UpAnimate(0)",10);
}
function screenInfo()
{
	lastTop=31; lastTop2=321;
	movTop=290/12;
	Img1=document.getElementById("infoText"); Img2=document.getElementById("infoShots");
	timer=setInterval("UpAnimate(1)",10);
}
function nextShot()
{
	if(shotsArr.length>0)
	{
		var c=parseInt(shotsArr[0]);
		if(c>1)
		{
			if(currImg==c)
				return;
			currImg++;
			document.getElementById("currNo").innerHTML=currImg;
			Img1=document.getElementById("screen1"); Img2=document.getElementById("screen2");
			if(currImg%2==0)
			{
				lastLeft=lastLeft2=-320;
				Img1.style.left="0px"; Img2.style.left="0px";
				document.getElementById("screen2").innerHTML="<img src='"+LoadImgSRC+"' />";
			}
			else
			{
				lastLeft=0; lastLeft2=-640;
				Img1.style.left="320px"; Img2.style.left="-320px";
				document.getElementById("screen1").innerHTML="<img src='"+LoadImgSRC+"' />";
			}
			getShotImg(currImg);
			movLeft=-320/15;
			//alert("here");
			timer=setInterval("Animate(0)",12);
		}
	}
}
function prevShot()
{
	if(shotsArr.length>0)
	{
		var c=parseInt(shotsArr[0]);
		if(c>1)
		{
			if(currImg==1)
				return;
			currImg--;
			document.getElementById("currNo").innerHTML=currImg;
			Img1=document.getElementById("screen1"); Img2=document.getElementById("screen2");
			if(currImg%2==0)
			{
				lastLeft=320;lastLeft2=-320;
				Img1.style.left="0px"; Img2.style.left="-640px";
				document.getElementById("screen2").innerHTML="<img src='"+LoadImgSRC+"' />";
			}
			else
			{
				lastLeft=lastLeft2=0;
				Img1.style.left="-320px"; Img2.style.left="-320px";
				document.getElementById("screen1").innerHTML="<img src='"+LoadImgSRC+"' />";
			}
			getShotImg(currImg);
			movLeft=320/15;
			timer=setInterval("Animate(1)",12);
		}
	}
}
function getShotImg(i)
{
	var x=((i+1)%2)+1;
	if(loaded)
	{
		if(loaded[i-1]==false)
		{
			clearTimeout(shotsTimer);
			shotsTimer=setTimeout("getShotsImg("+i+")",100);
		}
		else
			document.getElementById("screen"+x).innerHTML="<img src='"+shotsArr[i]+"' />";
	}
	else
	{
		clearTimeout(shotsTimer);
		shotsTimer=setTimeout("getShotsImg("+i+")",100);
	}
}
function changeCat(catId)
{
	if(catId==0)
	{
		for(i=0;i<appsArr.length;i++)
			document.getElementById("app"+appsArr[i]).style.display="block";
		return;
	}
	var i,url="get_catapp.php?cat_id="+catId;
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=stateChangedCat;
	document.getElementById("LoadCover").style.display="block";
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function stateChangedCat()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		for(i=0;i<appsArr.length;i++)
			document.getElementById("app"+appsArr[i]).style.display="none";
		var catArr=xmlHttp.responseText.split("#");
		document.getElementById("LoadCover").style.display="none";
		for(i=0;i<catArr.length;i++)
		{
			if(catArr[i])
				document.getElementById("app"+catArr[i]).style.display="block";
		}
	}
}
