function getCorrectedYear(year) {
    year = year - 0;
    if (year < 70) return (2000 + year);
    if (year < 1900) return (1900 + year);
    return year;
}

function displayDate(){
	var lastModDate = new Date(document.lastModified);

    var result="Last updated on ";
    result = result + getDayOfTheWeek(lastModDate.getDate())+", "+ lastModDate.getDate()+" "+getTheMonth(lastModDate.getMonth())+" "+getCorrectedYear(lastModDate.getYear());
    return result;
}

function getDayOfTheWeek(day){
	if(day=0)return "Sunday";
	if(day=1)return "Monday";
	if(day=2)return "Tuesday";
	if(day=3)return "Wednesday";
	if(day=4)return "Thrusday";
	if(day=5)return "Friday";
	if(day=6)return "Saturday";
}

function getTheMonth(month){
	if(month="0")return "January";
	if(month="1")return "February";
	if(month="2")return "March";
	if(month="3")return "April";
	if(month="4")return "May";
	if(month="5")return "June";
	if(month="6")return "July";
	if(month="7")return "August";
	if(month="8")return "September";
	if(month="9")return "October";
	if(month="10")return "November";
	if(month="11")return "December";
}

var pic=new Array(100);
var thumbs = new Array(100)
var names=new Array(100);
var strengths=new Array(100);
var weaknesses=new Array(100)

function SwapImage(image) {
   document.getElementById("mainImage").src = pic[image].src;
   document.getElementById("mainImage").alt = names[image];
   document.getElementById("name").firstChild.nodeValue = names[image];
   document.getElementById("powers").firstChild.nodeValue = strengths[image];
   document.getElementById("weakness").firstChild.nodeValue = weaknesses[image];
}

function importXML()
{
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = createData;
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) createData()
		};
 	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
	xmlDoc.load("http://www.gaywood.com/jacob/bionicles.xml");
	
}

function createData()
{
	var x = xmlDoc.getElementsByTagName('bionicle');
	var newEl = document.createElement('TABLE');
	newEl.setAttribute('cellPadding',0);
	var tmp = document.createElement('TBODY');
	newEl.appendChild(tmp);

	var row = document.createElement('TR');
	for (j=0;j<x.length;j++)
	{
		if (x[j].childNodes[0].nodeType != 1) continue;
		var container = document.createElement('TH');
		var imgData = document.createElement(	"<img border='0' onmouseover='SwapImage("+j+"); void 0' src='http://www.gaywood.com/images/bionicle/"
												+x[j].childNodes[0].firstChild.nodeValue+"' width='100' height='100'>"
											)
		container.appendChild(imgData);
		row.appendChild(container);
	}
	tmp.appendChild(row);
	document.getElementById('image-index').appendChild(newEl);

    
    
	for (i=0;i<x.length;i++)
	{
	  	pic[i]=new Image();
		pic[i].src="http://www.gaywood.com/images/bionicle/"+x[i].childNodes[1].firstChild.nodeValue;
		thumbs[i]=new Image();
		thumbs[i].src="http://www.gaywood.com/images/bionicle/"+x[i].childNodes[0].firstChild.nodeValue;
		names[i]=x[i].childNodes[2].firstChild.nodeValue;
		strengths[i]=x[i].childNodes[3].firstChild.nodeValue;
		weaknesses[i]=x[i].childNodes[4].firstChild.nodeValue;
	}
}

