
	selectedTabItemNo = new Array("0", "0", "0", "0", "0", "0");
	selectedPage = "";
	selectedMenuItem = 0;
	tabStart = 0;
	divWidth = 0;
	mainDivNo = 0;
	totPics = 0;
	direction = "";
	imageList = "NO";
	var textDescription = new Array();
	var pics = new Array();
	var thumbs = new Array();

	function setContent() {
		// Get the url string
		var str = window.location.toString();
		
		// Set up the selected menu number
		var start = str.indexOf("menu=",1);
		var end = str.indexOf("page=",1);

		if (start > 0) {
			selectedMenuItem = str.substr(start + 5,1);
		
			// Set up the selected page
			start = str.indexOf("page=",1) + 5;
			end = str.indexOf("tabno=",1) - 1;
			
			if (end > 1) {
				len = end - start;
				selectedPage = str.substr(start, len);
			} else {
				selectedPage = str.substr(start);
			}

			//Set up the selected tab
			start = str.indexOf("tabno=",1);
			if (start > 0) {
				selectedTabItemNo[selectedMenuItem] = str.substr(start + 6);
			}
		} else {
			selectedMenuItem = 0;
		}
		
		// Set the default
		document.getElementById("mainContent").innerHTML = "Please wait while the content loads";
		if (selectedPage == "") {
			selectedPage = "home";
		}
		
		// Build the menu
		buildMenu();

		// Build the content from the XML
		buildContent();		
	}
	
	function setClass(e, c) {
		document.getElementById(e).className = c;
	}
	
	function setDocument() {
		window.toolbar = 'no';
		doc=location.search.substr(5);
		doc='docs/' + doc;
		docHolder.innerHTML = "<a href='" + doc + "'></a>";
	}
	
	function buildMenu() {
		// Create the string object to hold the HTTP text
		var menuHTML = "<table cellpadding=0 cellspacing=0 border=0><tr><td class=MenuTop>&nbsp;</td></tr>";
		
		// Get the menu items from the XML 
		xml=openXML("xml/gmba_pages.xml");
		
		// Each item in the xml object is a menu item
		for (menuIndex = 0; menuIndex < xml.childNodes[0].childNodes.length; menuIndex ++) {
			menuItem = xml.childNodes[0].childNodes[menuIndex].childNodes;
			menuHTML += "<tr><td class=MenuButtonSpace>&nbsp;</td></tr>";
			if (selectedPage == menuItem[0].text) {
				menuHTML += "<tr><td class=MenuButtonSelected>" + menuItem[1].text + "</td></tr>";
			} 
			else {
				menuHTML += "<tr><td id='" + menuItem[0].text + "'";
				menuHTML += " class=MenuButton";
				menuHTML += " onClick=changeItem('" + menuIndex + "','" + menuItem[0].text + "')";
				menuHTML += " onMouseOver=setClass('" + menuItem[0].text + "','MenuButtonHi')";
				menuHTML += " onMouseOut=setClass('" + menuItem[0].text + "','MenuButton')";
				menuHTML += ">" + menuItem[1].text + "</td></tr>";
			}
		}
		
		// complete the menu table and insert into document
		menuHTML += "<tr><td class=MenuBottom>&nbsp;</td></tr></table>";
		document.getElementById("Menu").innerHTML = menuHTML;
	}
	
	function buildContent() {
		imageList = "NO";
	
		// open the selected xml doc
		xml = openXML("xml/gmba_" + selectedPage + ".xml");

		// build the tabs
		buildTabs(xml);
		
		// build the selected tabs content
		contentHTML = "<table cellpadding=0 cellspacing=0 border=0><tr><td width=800>&nbsp;</td></tr>";
		tabItem = xml.childNodes[0].childNodes[selectedTabItemNo[selectedMenuItem]].childNodes;
		
		// Each item in the content element is a table
		for (tableIndex = 0; tableIndex < tabItem[1].childNodes.length; tableIndex ++) {
			contentTable = tabItem[1].childNodes[tableIndex];
			contentHTML += "<tr><td><table cellspacing='1' cellpadding='0' border='0'>";
			
			// Each item in the table element is a row
			for (rowIndex = 0; rowIndex < contentTable.childNodes.length; rowIndex++) {
				contentRow = contentTable.childNodes[rowIndex];
				contentHTML += "<tr><td width='23'>&nbsp;</td>";
				
				// Each item in the row element is a column (cell)
				for (columnIndex = 0; columnIndex < contentRow.childNodes.length; columnIndex ++ ) {
					contentColumn = contentRow.childNodes[columnIndex];
					className = contentColumn.childNodes[0].text;
					
					// set up alternating classes for content lines
					if (contentColumn.childNodes[0].text == "Content") {
						if ((rowIndex % 2) > 0) {
							className = contentColumn.childNodes[0].text + "Alt";
						} 
					}
					
					// check cell type
					switch (contentColumn.childNodes[2].nodeName) {
						case "IMAGE":
							contentHTML += "<td class='ImageCenter' width='750'><img src='" + contentColumn.childNodes[2].text + "' /></td>";
							break;
						case "DOC":
							contentHTML += "<td class='" + contentColumn.childNodes[0].text + "' width='" + contentColumn.childNodes[1].text + "' onclick=" + contentColumn.childNodes[2].text + ">View</td>";
							break;
						case "LINK":
							contentHTML += "<td class='" + contentColumn.childNodes[0].text + "' width='" + contentColumn.childNodes[1].text + "' onclick=" + contentColumn.childNodes[2].text + ">View</td>";
							break;
						case "IMAGELIST":
							contentHTML += "<td class='" + contentColumn.childNodes[0].text + "' width='" + contentColumn.childNodes[1].text + "'><TABLE cellpadding=0 cellspacing=0 border=0><TR><TD width=750 id=photoHeading class=contentCenter></TD></TR><TR><TD><TABLE cellpadding=0 cellspacing=5 border=0><TR><TD align=center><TABLE cellpadding=0 cellspacing=0 border=0><TR><TD width=50 height=50 id=thumb1 background=''></TD></TR></TABLE></TD><TD align=center><TABLE cellpadding=0 cellspacing=0 border=0><TR><TD width=50 height=50 id=thumb2 background=''></TD></TR></TABLE></TD><TD onclick=changeImage('previous') class=photoControl align=center><img src=images/previous.jpg alt=previous></TD><TD height=500 width=500 id=mainPicHolder style='text-align: center'><TABLE cellpadding=0 cellspacing=0 border=0><TR><TD><IMG class=mainImage id=mainPrevious /></TD><TD><IMG class=mainImage id=mainPic /></TD><TD><IMG class=mainImage id=mainNext /></TD></TR></TABLE></TD><TD onclick=changeImage('next') align=center class=photoControl><img src=images/next.jpg alt=next></TD><TD align=center><TABLE cellpadding=0 cellspacing=0 border=0><TR><TD width=50 height=50 id=thumb3 background=''></TD></TR></TABLE></TD><TD align=center><TABLE cellpadding=0 cellspacing=0 border=0><TR><TD width=50 height=50 id=thumb4 background=''></TD></TR></TABLE></TD></TR></TABLE></TD></TR></TABLE>";
							imageList = "YES";
							break;
						default:
							contentHTML += "<td class=" + className + " width=" +  contentColumn.childNodes[1].text + ">" +  contentColumn.childNodes[2].text + "</td>";
					}
				}
				contentHTML += "</tr>";
			}
			contentHTML += "</table></td></tr>";
		}
		contentHTML += "</tr></table>";
		document.getElementById("mainContent").innerHTML = contentHTML;
		if (imageList == "YES") {
			buildPicArray();
		}
	}
	
	function buildTabs (xml) {
		
		var tabCount = 0;
		tabHTML = "<table cellpadding=0 cellspacing=0 border=0><tr><td class=TabFront>&nbsp;</td>";
		tabWidth = 1000 - ((xml.childNodes[0].childNodes.length + 1) * 150);
		for (itemIndex=tabStart; itemIndex<xml.childNodes[0].childNodes.length; itemIndex++) { 
			if ((tabStart > 0) && ((tabCount % 6) == 0)) {
				tabHTML += "<td class=tabControl onclick=changeTabStart(" + (itemIndex - 5) + ")><img src='images/previous.jpg' alt='Get previous 5'/></td>";
			}
			tabCount += 1;
			if ((tabCount > 1) && ((tabCount % 6) == 0)) {
				tabHTML += "<td class=tabControl onclick=changeTabStart(" + itemIndex + ")><img src='images/next.jpg' alt='Get next 5'/></td>";
				break;
			}
			tabItem = xml.childNodes[0].childNodes[itemIndex].childNodes;
			
			// the selected tab is shown as selected
			if (selectedTabItemNo[selectedMenuItem] == itemIndex) {
				tabHTML += "<td class=TabSelected>" + tabItem[0].text + "</td>";
			} else {
				tabHTML += "<td class=TabUnselected onClick=changeTab('" + itemIndex + "')>" + tabItem[0].text + "</td>";
			}
		}
		tabHTML += "<td class=TabEnd width=" + tabWidth + ">&nbsp;</td></tr></table>";
		document.getElementById("tabContent").innerHTML = tabHTML;
	}
	
	function changeItem(menuNo, tabNo) {
		window.location.assign("index.php?menu=" + menuNo + "&tab=" + tabNo);
	}
	
	function changeTabStart(tabIndex) {
		tabStart = tabIndex;
		setContent();
	}

	function openXML(xmlDoc) {
	
		// set the xml requestor object reference
		if (window.XMLHttpRequest)	  {
			xhttp=new XMLHttpRequest()
		}
		else {
			xhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
		xhttp.open("GET", xmlDoc ,false);
		xhttp.send("");
		xmlDoc=xhttp.responseXML;
		return xmlDoc;
	}
	
	function go(docName) {
		window.open(docName, "_blank");
	}
	
	function buildPicArray() {
		xml = openXML("xml/gmba_photos.xml")
		il = xml.childNodes[0].childNodes[selectedTabItemNo[selectedMenuItem]].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[2];
		for (x=0;x<il.childNodes.length;x++) {
			textDescription[x] = il.childNodes[x].childNodes[0].text;
			pics[x] = il.childNodes[x].childNodes[1].text;
			thumbs[x] = il.childNodes[x].childNodes[2].text;
		}
		totPics = x-1;
		divWidth = 400;
		setDiv();
	}
			
	function setDiv() {
		// Set the heading
		document.getElementById("photoHeading").innerHTML = "Photo no: " + (mainDivNo + 1) + " - " + textDescription[mainDivNo];
		
		// Set thumb 1
		var t1 = document.getElementById("thumb1");
		if (mainDivNo == 0) {
			t1.background = thumbs[totPics-1];
		} else if (mainDivNo == 1) {
			t1.background = thumbs[totPics];
		} else {
			t1.background = thumbs[mainDivNo - 2];
		}
		
		// Set thumb 2 and maintop
		var t2 = document.getElementById("thumb2");
		if (mainDivNo == 0) {
			t2.background = thumbs[totPics];
		} else {
			t2.background = thumbs[mainDivNo - 1];
		}

		// Set the main pics
		document.getElementById("mainPrevious").width = 1;
		document.getElementById("mainPic").src = pics[mainDivNo];
		document.getElementById("mainPic").width = 1;
		
		// Set thumb 3
		var t3 = document.getElementById("thumb3");
		if (mainDivNo == totPics) {
			t3.background = thumbs[0];
		} else {
			t3.background = thumbs[mainDivNo + 1];
		}
		
		// Set thumb 4
		var t4 = document.getElementById("thumb4");
		if (mainDivNo == totPics) {
			t4.background = thumbs[1];
		} else if (mainDivNo == totPics - 1) {
			t3.background = thumbs[0];
		} else {
			t4.background = thumbs[mainDivNo + 2];
		}

		setTimeout("waitForImage()",5);
		
		showImage();
	}
	
	function waitForImage() {
		for (wait = 0; wait <1000; wait++) {
			if (document.getElementById("mainPic").complete == true) {
				break;
			}
		}
		if (document.getElementById("mainPic").complete == false) {
			setTimeout("waitForImage()",5);
		}
	}
	
	function changeImage(d) {
		direction = d;
		if (direction == "previous") {
			document.getElementById("mainPrevious").src = pics[mainDivNo];
			document.getElementById("mainPrevious").width = 400;
			if (mainDivNo == 0) {
				mainDivNo = totPics;
			} else {
				mainDivNo--;
			}
		}
		if (direction == "next") {
			document.getElementById("mainNext").src = pics[mainDivNo];
			document.getElementById("mainNext").width = 400;
			if (mainDivNo == totPics) {
				mainDivNo = 0;
			} else {
				mainDivNo++;
			}
		}
		divWidth = 1;
		setDiv();
	}
	
	function showImage() {
		var mp = document.getElementById("mainPrevious");
		var main = document.getElementById("mainPic");
		var mn = document.getElementById("mainNext");
		main.width = divWidth;
		main.style.textalign = "right";
		if (divWidth < 400) {
			if (direction == "previous") {
				mp.width = 400 - divWidth;
			}
			if (direction == "next") {
				mn.width = 400 - divWidth;
			}
			divWidth = divWidth + 5;
			setTimeout("showImage()",1);
		} else {
			mp.width = "";
			mn.width = "";
		}
	}
