var xmlImages; // set global XML image array
var step = 0; // location in XML photo tree - default is the first photo
var isIE = false;
var xmlReq; // global XML request
var xDoc;
var prevcol;
var imgN;
var imgU;

function swapImage(imgN,imgU)
	{
	if(document.images)document.images[imgN].src=imgU;
	}

function initLoad(objectID)
	{
	step = 0;
	if (objectID == "women")
		{
	    fetchXML('../xml/women.xml');	
		}
	if (objectID == "beauty")
		{
	    fetchXML('../xml/beauty.xml');	
		}
	if (objectID == "fashion")
		{
	    fetchXML('../xml/fashion.xml');	
		}	
	if (objectID == "covers")
		{
	    fetchXML('../xml/covers.xml');	
		}		
	if (objectID == "p1")
		{
	    fetchXML('../xml/gqb.xml');	
		}		
	if (objectID == "p2")
		{
	    fetchXML('../xml/voguela.xml');	
		}
	if (objectID == "p3")
		{
	    fetchXML('../xml/brakeup.xml');	
		}
	if (objectID == "p4")
		{
	    fetchXML('../xml/femme.xml');	
		}
	if (objectID == "p5")
		{
	    fetchXML('../xml/surface.xml');	
		}
	if (objectID == "p6")
		{
	    fetchXML('../xml/lindac.xml');	
		}
	if (objectID == "p7")
		{
	    fetchXML('../xml/filippa.xml');	
		}
	if (objectID == "p8")
		{
	    fetchXML('../xml/personal.xml');	
		}
	if (objectID == "p9")
		{
	    fetchXML('../xml/lingerie.xml');	
		}
	if (objectID == "p10")
		{
	    fetchXML('../xml/montauk.xml');	
		}		
	if (objectID == "bts")
		{
	    fetchXML('../xml/bts.xml');
	}
	if (objectID == "p11") {
	    fetchXML('../xml/bondgirl.xml');
	}			
	}
	

/*XML Fetching Function*/
function fetchXML(myXMLdoc)
	{
	if (window.XMLHttpRequest) // if mozilla / firefox etc
		{
		xmlReq = new XMLHttpRequest();
		xmlReq.onreadystatechange = checkReqChange;
		xmlReq.open("GET", myXMLdoc, true);
		xmlReq.send(null);
		}
	else if (window.ActiveXObject) // if MSIE- use active X object
		{
		isIE = true; // this is IE
		xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlReq) 
			{
			xmlReq.onreadystatechange = checkReqChange;
			xmlReq.open("GET", myXMLdoc, true);
			xmlReq.send();
			}
		}
	}

/*XML Handling Function*/
function checkReqChange() 
	{
	if (xmlReq.readyState == 4) 
		{
		if (xmlReq.status == 200)
			{
			xDoc = xmlReq.responseXML;
	    	xmlImages = xDoc.getElementsByTagName("image");	// get the image name from the XML file
     		firstImage();  // Execute inserting first image into HTML document
			}
		else if (xmlReq.status == 404) 
			{
			alert("Oops, couldn't retrieve the XML data:\n" + xmlReq.statusText);
			}
		}
	}
	
function firstImage() 
	{
	buildPhotoPage(); // get the photos url, credit etc
	}
	
function buildPhotoPage()
	{
	var imgcount = step +1;
	var myPhoto = xmlImages[step].getAttribute("imagename");// get image name	
	var myText = xmlImages[step].getAttribute("credit");// get image text
    var countstring = "<a>" + imgcount + " / " + xmlImages.length + "</a>";	
	var scrtext = "<a>" + myText + "</a>";	
	document.getElementById('currenttext').innerHTML = scrtext;	
	document.getElementById('currentcount').innerHTML = countstring;
	document.images[1].src = myPhoto; // force into old image
	}
	
function nextPhoto() /* next photo in XML tree */
	{
	step++;
	if (step == xmlImages.length) 
		{
		// circle back to the beginning of the XML file
		step = 0;
		} 
	buildPhotoPage();
	}
	
function prevPhoto() 	/*  previous photo in xml tree */
	{
	if (step != 0)
		{
		step--;
		}	
	else 
		{
		step = (xmlImages.length - 1);
		}	
	buildPhotoPage();	
	}

function remById(thisId) 
	{
	/*Remove an element from the page - Untested*/
	var t = document.getElementById(thisId);
	alert(t);
	t.parentNode.removeChild();
	}
/*EOF*/