	
var intImage = 0; //Current Image
var intImages = 6; //Images per page
var xmlDoc; //XML document object

//Navigate to previous image set
function previous()
{
	intImage = intImage - intImages; //Increment Current Image
	loadXML(); //Call loadXML
}

//Navigate to next image set
function next()
{
	intImage = intImage + intImages; //Increment Current Image
	loadXML(); //Call loadXML
}

//Function to load XML data
function loadXML()
{
	//Relative location of image XML file
	var url = "./photos/photos.xml";

	if (window.ActiveXObject) // IE/ActiveX
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlDoc)
		{
			xmlDoc.onreadystatechange = XMLreturn; //Call XMLreturn when data is gathered
			xmlDoc.open("GET", url, true);
			xmlDoc.send();
		}
	}
	else //if (window.XMLHttpRequest) // Mozilla/Firefox
	{
		xmlDoc = new XMLHttpRequest();
		xmlDoc.open('GET', url, true);
		xmlDoc.onreadystatechange = XMLreturn; //Call XMLreturn when data is gathered
		xmlDoc.send(null);
	}
}

//Function to use XML data
function XMLreturn()
{
	var strOut = ""; //String for collecting output
	var i; //Increment variable

	// Continue if xmlDoc is "loaded"
	if (xmlDoc.readyState == 4)
	{
		// Continue if xmlDoc status is "OK"
		if (xmlDoc.status == 200)
		{
			//Ensure we are not out of the image count boundries
			if (intImage >= xmlDoc.responseXML.getElementsByTagName("photo").length)
			{
				intImage = intImage - intImages; //Increment Current Image
			}
			if (intImage < 0)
			{
				intImage = intImage + intImages; //Increment Current Image
			}

			//Set the current display limit (less then the intImages count if we are at the end of a set)
			if ((intImage+intImages)>xmlDoc.responseXML.getElementsByTagName("photo").length)
			{
				intLimit = xmlDoc.responseXML.getElementsByTagName("photo").length;
			}
			else
			{
				intLimit = intImage + intImages
			}

			//Display current images (intImage to intLimis)
			for (i=intImage; i<intLimit; i++)
			{
				strOut += '<div class="imageitem">';
				strOut += '<img class="image" src="./photos/' + xmlDoc.responseXML.getElementsByTagName("photo")[i].getElementsByTagName("src")[0].firstChild.data + '" alt="' + xmlDoc.responseXML.getElementsByTagName("photo")[i].getElementsByTagName("caption")[0].firstChild.data + '" />';
				strOut += '<p class="caption">' + xmlDoc.responseXML.getElementsByTagName("photo")[i].getElementsByTagName("caption")[0].firstChild.data + '</p>';
				strOut += '</div>';
			}

			//Put image content into imagearea div
			document.getElementById("imagearea").innerHTML = strOut;
		}
		else
		{
			//Error
			imagearea.innerHTML = "There was a problem retrieving the XML data: " + xmlDoc.statusText;
		}
	}
}
