function loadXMLDoc(dname)
	{
	if (window.XMLHttpRequest)
		{
		xhttp=new XMLHttpRequest();
		}
	else
		{
		xhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	xhttp.open("GET",dname,false);
	xhttp.send();
	return xhttp.responseXML;
	}

function fillMenu()					//Fills out the menu table
	{
	menu=loadXMLDoc("menu.xml");
	x=menu.getElementsByTagName("item");		//x is an array of all item nodes in order
	document.write('<table id="menu" cellpadding="0" cellspacing="0">');
	for (i=0;i<x.length;i++)				//writes horizontal menu
		{
		a=x[i].getAttribute("name");		//a is the name attribute of a particular node
		e=x[i].getAttribute("link");		//e is the link attribute of a particular node
		if (e==null)
			{
			document.write("<tr class='menuitemrow'><td class='menuitem nonlinkmenu' id='"+a+"' onmouseover='revealMenu(event)'>");
			a=a.replace(/_/gi," ");
			a=a.replace(/%/gi,"<br />");
			document.write(a);
			document.write("</td></tr>");
			}
		else
			{
			document.write("<tr class='menuitemrow'><td class='menuitem linkmenu' id='"+a+"'><a href='"+e+"' class='blocklink' onmouseover='revealMenu(event)'>");
			a=a.replace(/_/gi," ");
			a=a.replace(/%/gi,"<br />");
			document.write(a);
			document.write("</a></td></tr>");
			}
		}
	document.write('</table>');
	for (i=0;i<x.length;i++)
		{
		y=x[i].getElementsByTagName("subitem");					//y is an array of the subitems of a particular item (in order)
		a=x[i].getAttribute("name");
		w=document.getElementById('menu').offsetWidth-1+"px";			//w is width of menu
		h=document.getElementById(a).offsetTop+"px";					//h is height of menu
		document.write("<table class='submenu' id='sub"+a+"' style='left:"+w+"; top:"+h+"' cellpadding='0' cellspacing='0'>");
		for (j=0;j<y.length;j++)
			{
			a=y[j].getAttribute("name");
			e=y[j].getAttribute("link");
			if (e==null)
				{
				document.write("<tr><td class='submenuitem' id='"+a+"'>");
				a=a.replace(/_/gi," ");
				a=a.replace(/%/gi,"<br />");
				document.write(a);
				document.write("</td></tr>");
				}
			else
				{
				document.write("<tr><td class='submenuitem' id='"+a+"'><a href='"+e+"' class='blocklink'>");
				a=a.replace(/_/gi," ");
				a=a.replace(/%/gi,"<br />");
				document.write(a);
				document.write("</a></td></tr>");
				}
			}
		document.write('</table>');
		}
	}

function expandSpacer()
	{
	foobar = document.getElementById("footercontainer").offsetTop-document.getElementById("content").offsetTop;
	if(foobar<document.getElementById("menu").offsetHeight)
		{
		document.getElementById("footercontainer").style.paddingTop=document.getElementById("menu").offsetHeight-foobar+"px";
		}
	}

function revealMenu(event)
	{
	var z=false;
	var p=event.target||event.srcElement;
	for (i=0;i<x.length;i++)
		{
		var a=x[i].getAttribute("name");
		var e=x[i].getAttribute("link");
		document.getElementById("sub"+a).style.display="none";
		if (a==p.id)
			{
			if (e==null)
				{
				z=true;			//If z=true, the item that was moused-over needs to be expanded
				}
			}
		}
	if (z==true)
		{
		document.getElementById("sub"+p.id).style.display="block";
		}
	}

function hideMenu()
	{
	for (i=0;i<x.length;i++)
		{
		a=x[i].getAttribute("name");
		document.getElementById("sub"+a).style.display="none";
		}
	}

function dynamicHeader()			//Changes the header image at set intervals
	{
	ms=10000;								//ms is the milliseconds between image changes
	d=7;									//images is the number of different images available
	c=new Array();							//c is an array of header images. Each value corresponds to an image number
	for (k=0;k<d;k++)
		{
		c[k]=k+1;
		}
	document.getElementById("header").innerHTML="<img id='dynamicheader' />";
	changeHeader();
	}

function changeHeader()					//Changes the header image, images is the number of different images available
	{
	b=Math.floor(Math.random()*c.length)			//b is a random number corresponding to an element of the array c
	document.getElementById("dynamicheader").src="http://www.smithandgeorg.com.au/header"+c[b]+".png";
	c.splice(b,1);
	if (c.length==0)
		{
		for (k=0;k<d;k++)
			{
			c[k]=k+1;
			}
		}
	t=setTimeout("changeHeader()",ms);
	}
