var XHR = false;
var arrParam;
var arrByline;
var arrFilename;
var arrThumbnail;
var arrAlttext;
var i=0;//Page number
var j=0;//Number of screenshots

if (window.XMLHttpRequest)
{
	XHR = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{		
	XHR = new ActiveXObject("Msxml2.XMLHTTP");	
}

//ScreenShots Popup
function popUpSS(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=0,width=472,height=580');");
}

function getScreenShots(dataSource,page)
{		
	if (XHR)
	{	
		XHR.open("GET",dataSource);
	
		XHR.onreadystatechange = function()
		{
			if (XHR.readyState==4 && XHR.status==200)
			{
				var xmlDocument=XHR.responseXML;
				arrParam=xmlDocument.getElementsByTagName("param");
				arrByline=xmlDocument.getElementsByTagName("byline");
				arrFilename=xmlDocument.getElementsByTagName("filename");
				arrThumbnail=xmlDocument.getElementsByTagName("thumbnail");
				arrAlttext=xmlDocument.getElementsByTagName("alttext");
				
				//set the number of screenshots
				j=arrParam.length;
				displayScreenShot(page);
			}
		}
		XHR.send(null);
	}
	else
	{
		document.getElementById("byline").innerHTML="Failed to create XHR";
	}
}

function displayScreenShot(page)
{
	var previousButton=document.getElementById("btnPrevious");
	var nextButton=document.getElementById("btnNext");
	var screenshotThumbnail=document.getElementById("thumbnail");
	var screenShotHref=document.getElementById("screenshot");
	var byLine=document.getElementById("byline");
		
	if(page=="previous")
	{		
		if(i==0)
		{			
			previousButton.src="community/previousdis.jpg";
			previousButton.alt="";	
		}
		else
		{
			i=i-1;	
			if(i==0)
			{				
				previousButton.src="community/previousdis.jpg";
				previousButton.alt="";	
			}
			else
			{
				previousButton.src="community/previous.jpg";
				previousButton.alt="previous";
			}
		}
		
		nextButton.src="community/next.jpg";
		nextButton.alt="next";
	}
	
	if(page=="next")
	{	
		if(i==(j-2))
		{
			i=i+1;
			nextButton.src="community/nextdis.jpg";
			nextButton.alt="";
		}
		else
		{
			i=i+1;
			nextButton.src="community/next.jpg";
			nextButton.alt="next";
		}
		
		previousButton.src="community/previous.jpg";
		previousButton.alt="previous";
		
	}
	
	
	screenShotHref.href="javascript:popUpSS('screenshotspop.php?ss=" + arrFilename[i].firstChild.data + "&by=" + arrParam[i].firstChild.data + "')";			
	screenshotThumbnail.src="community/screenshots/" + arrThumbnail[i].firstChild.data;
	byLine.innerHTML=arrByline[i].firstChild.data;
		
}


       