<!--
var imageArray=new Array();

//load the XML Doc
function loadXMLDoc(dname)
	{
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject)
		{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
		{
		xmlDoc=document.implementation.createDocument("","",null);
		}
	else
		{
		alert('This browser cannot handle this script');
		}
	xmlDoc.async=false;
	xmlDoc.load(dname);
	return(xmlDoc);
	}

/*
1. Calls the function, loadXMLDoc(dname), to get the XML doc 
2. For a category it takes the data from the XML doc and stores it in the array, imageArray
3. Calls the function, buildThumbs(imageArray), and passes the array imageArray
*/
function gallery(category)
	{
	xmlDoc=loadXMLDoc("gallery.xml");
	var x=xmlDoc.getElementsByTagName('title');
	imageArray=imageArray.splice(imageArray.length,imageArray.length);

	//for the number of title elements in the XML doc do this	
	for (i=0; i<=x.length-1; i++)
		{
		piece=(x.item(i).parentNode.childNodes);
		//if the node type is an ELEMENT_NODE
		if (x.item(i).nodeType==1)
			{
			//if the XML data matches the category choice add it to imageArray[]
			if (x.item(i).parentNode.getAttribute('category') == category)
				{
				//IE handles white space differently then the other browsers so... 
				//if IE read the XML doc and and the data to imageArray[]
				if (window.ActiveXObject)
					{
					imageArray.push(category, piece.item(0).childNodes.item(0).nodeValue, piece.item(1).childNodes.item(0).childNodes.item(0).nodeValue, piece.item(1).childNodes.item(1).childNodes.item(0).nodeValue);
					//if there is data in the link and linktext cells add it to imageArray[]
					try
					   {
						if (piece.item(2).childNodes.item(0).nodeType)
						   {
						   imageArray.push(piece.item(2).childNodes.item(0).childNodes.item(0).nodeValue, piece.item(2).childNodes.item(0).getAttribute('link'));
						   }							   
						}
					//if there is no data in the link and linktext cells add "null" to imageArray[] in it's place.
					catch (e) 
						{ 
						imageArray.push("null", "null");
						}
					imageArray.push(piece.item(2).childNodes.item(1).childNodes.item(0).nodeValue, piece.item(2).childNodes.item(2).childNodes.item(0).nodeValue, piece.item(2).childNodes.item(3).childNodes.item(0).nodeValue, piece.item(2).childNodes.item(4).childNodes.item(0).nodeValue);
					}    
				//else if not IE read the XML doc and and the data to imageArray[]
				else
					{					  		   
					imageArray.push(category, piece.item(1).childNodes.item(0).nodeValue, piece.item(3).childNodes.item(1).childNodes.item(0).nodeValue, piece.item(3).childNodes.item(3).childNodes.item(0).nodeValue, piece.item(5).childNodes.item(1).childNodes.item(0).nodeValue, piece.item(5).childNodes.item(1).getAttribute('link'), piece.item(5).childNodes.item(3).childNodes.item(0).nodeValue, piece.item(5).childNodes.item(5).childNodes.item(0).nodeValue, piece.item(5).childNodes.item(7).childNodes.item(0).nodeValue, piece.item(5).childNodes.item(9).childNodes.item(0).nodeValue);	
					}    
				}	
			}
		}
	//Calls the functions to build the thumbnails based on the data added to  imageArray[] from the XML doc
	buildThumbs(imageArray);		
	}  

/*
1. Loads the default large image for that category by passing the fist set of data in  the array, imageArray, to the function, swapImg(imageLargeSrc, imageName, imageLinkText, theLink, imageText, imageMedia, imageMethod, imageSize)
2. Builds the thumbs from the data in the imageArray or calls the function to build multiple pages of thumbs
*/
function buildThumbs(thumbArray) //loads thumbnails and defalt image
	{
	/*
	Sets the page title anddefault Large picture when each section loads
	swapImg(imageLargeSrc, imageName, imageLinkText, theLink, imageText, imageMedia, imageMethod, imageSize)
	*/
	document.title="Angryteeth.net - Gallery: " + thumbArray[0];
	swapImg(thumbArray[2], thumbArray[1], thumbArray[4], thumbArray[5], thumbArray[6], thumbArray[7], thumbArray[8], thumbArray[9]);

	// call the fuction to build the Thumbs and passes the variables
	// if only one page of images do this
	var thumbnailNumber=1;
	var numberOfImages=thumbArray.length/10;
	if (thumbArray.length/10<=10) 
		{	
		var theCount=0;
		for(i=0; i<(thumbArray.length/10); i++)
			{
			document.getElementById('thumblink'+thumbnailNumber).setAttribute("href","javascript:swapImg(\'"+ thumbArray[(2+theCount)] + "\', \'" + thumbArray[(1+theCount)] + "\', \'" + thumbArray[(4+theCount)] + "\', \'" + thumbArray[(5+theCount)] + "\', \'" + thumbArray[(6+theCount)] + "\', \'" + thumbArray[(7+theCount)] + "\', \'" + thumbArray[(8+theCount)] + "\', \'" + thumbArray[(9+theCount)] + "\');");
			var thumbImg = document.getElementById('thumblink'+thumbnailNumber).firstChild;
			thumbImg.setAttribute("src", thumbArray[(3+theCount)]);
			thumbImg.setAttribute("name", thumbArray[(1+theCount)]);
			thumbImg.setAttribute("alt", thumbArray[(1+theCount)]);
			//thumbImg.setAttribute("style", "text-align:left;");
			//document.getElementById("thumblink" + (thumbnailNumber)).firstChild.style.text-align='left'; //this does not work 
			document.getElementById("thumblink" + (thumbnailNumber)).firstChild.style.display='inline';
			theCount+=10;
			thumbnailNumber++;
			}
		//This while loop hides any extra thumbnails if there are less then ten images in this catigory or on this page.	
		while(thumbnailNumber<=10)
			{
			document.getElementById("thumblink" + (thumbnailNumber)).firstChild.style.display='none';
			thumbnailNumber++;
			}
	    // this clears the next/back page link(s) if there is only one page.
		if((imageArray.length)/10<10)
			{
			document.getElementById("imagePageNav").style.display='none';
			}
		// this shows the next/back page link(s) if there is more than one page.
		else
			{
			document.getElementById("imagePageNav").style.display='inline';
			}
		}
//else  if more then 1 page of images  while (imageArray.length)/10 is  > then 10 create create x dynamic page links... 	
	else 
		{
		var pageNumber=1;
		buildThumbPages(pageNumber);
		}		
	}	

//if there are more 10 image this function creates pages for each set of 10 or less images.
function buildThumbPages(pageNumber)
	{	
	var numberOfPages=Math.ceil((imageArray.length/10)/10);
	var galleryPageNav=document.getElementById('imagePageNav');
		
	//if it's not the first or last page
	if(pageNumber!=numberOfPages)
		{
		var startSet = (pageNumber*100)-100;
		var endSet = (pageNumber*100)-1;
		var pageX = imageArray.slice(startSet, endSet);
		buildThumbs(pageX);
		if(pageNumber==1 && numberOfPages>1)
			{
			galleryPageNav.innerHTML="<a href=\"javascript:buildThumbPages("+(pageNumber+1)+");\"> Next Page</a>";
			}
		else //(pageNumber!=numberOfPages)
			{
			galleryPageNav.innerHTML="<a href=\"javascript:buildThumbPages("+(pageNumber-1)+");\">Previous Page</a>";
			galleryPageNav.innerHTML+=" || ";
			galleryPageNav.innerHTML+="<a href=\"javascript:buildThumbPages("+(pageNumber+1)+");\">Next Page</a>";
			}
		}
	else //if(pageNumber==numberOfPages) the last page, which may have less then 10 images
		{
		var pageX = imageArray.slice((pageNumber*100)-100, imageArray.length);
		buildThumbs(pageX);
		galleryPageNav.innerHTML="<a href=\"javascript: buildThumbPages(" +(pageNumber-1)+") ;\">Previous Page</a>";
		}
	}

//This function is used to swap the large image and the text that goes along with it to the large image that corelates to the thumb nail that was clicked.
function swapImg(imageLargeSrc, imageName, linkText, theLink, imageText, imageMedia, imageMethod, imageSize)
	{
	//swaps the image and image alt
	document.getElementById('largeimg').src=imageLargeSrc;
	document.getElementById('largeimg').setAttribute('alt', imageName);
	//if the text descriptions is without links add the description without the link
	if (linkText==" " || linkText=="null")
		{
			document.getElementById('pictureTxt').innerHTML=imageText;
			/*var a = document.getElementById('descriptionLink')
			if(document.getElementById('descriptionLink')){document.getElementById('pictureTxt').removeElement(true);}
			alert(document.getElementById('pictureTxt').firstChild.nodeValue)
			document.getElementById('pictureTxt').firstChild.nodeValue;
			var txtP = document.getElementById('pictureTxt').firstChild.nodeValue;
			txtP.parentNode.removeChild(txtP);	*		
			document.getElementById('pictureTxt').firstChild.nodeValue=imageText;	*/		
		}
	else //else if the text descriptions has a link add it to the begining of the description.
		{			
			document.getElementById('pictureTxt').innerHTML=imageText +"<br />" + "<a href=\"" + theLink +"\">"+ linkText +"</a>";
			/*var txtP = document.getElementById('pictureTxt');
			var link = document.createElement('a');
			link.setAttribute('href', theLink);
			link.setAttribute('id', 'descriptionLink');
			txtP.appendChild(link);
			var txtLink = document.createTextNode(linkText);
			link.appendChild(txtLink);
			//var txt = document.createTextNode(" " + imageText);
			//txtP.appendChild(txt);
			document.getElementById('pictureTxt').firstChild.nodeValue=imageText;	*/
		}	
	//The media, method and Size	
	document.getElementById('pictureMedia').firstChild.nodeValue=imageMedia;
	document.getElementById('pictureName').firstChild.nodeValue=imageName;
	document.getElementById('pictureMethod').firstChild.nodeValue=imageMethod;
	document.getElementById('pictureSize').firstChild.nodeValue=imageSize;	
	}
//-->