/*

===================================================
XHTML/CSS/DHTML Semantically correct drop down menu 
===================================================
Author: Sam Hampton-Smith
Site: http://www.hampton-smith.com

Description:	This script takes a nested set of <ul>s
		and turns it into a fully functional
		DHTML menu. All that is required is 
		the correct use of class names, and
		the application of some CSS.
		
Use:	Please leave this information at the
		top of this file, and it would be nice
		if you credited me/dropped me an email
		to let me know you have used the menu.
		sam AT hampton-smith.com


---------------------------------------------------
Credits: 	Inspiration/Code borrowed from Dave Lindquist (http://www.gazingus.org)
		Menu hide functionality was aided by some code I found on http://www.jessett.com/


Amended by Kevin Rattan Oct 2006 to produce three different menus

I leave the header in place as a grateful credit to Mr Hampton-Smith.

*/

	
	//var myoffset;
	//var fixedoffset = null;
	var opera = window.opera ? true : false;
	
	var currentMenu = null;
	var mytimer = null;
	var timerOn = false;
	
	var currentMenu2 = null;
	var mytimer2 = null;
	var timerOn2 = false;
	
	var currentMenu3 = null;
	var mytimer3 = null;
	var timerOn3 = false;
		

	if (!document.getElementById)
		document.getElementById = function() { return null; }
		


	function getMenus(elementItem, root) {
		var selectedItem;
		var menuStarter;
		var menuItem;
		//alert("in getmenus");
		//alert(elementItem.childNodes.length);
		for (var x=0;x<elementItem.childNodes.length;x++) {
			//alert(elementItem.childNodes[x].nodeName);
			if (elementItem.childNodes[x].nodeName=="LI") {
				//alert("Yes!");
				if (elementItem.childNodes[x].getElementsByTagName("UL").length>0) {
					//alert("Set up");
					menuStarter = elementItem.childNodes[x].getElementsByTagName("A").item(0);
					menuItem = elementItem.childNodes[x].getElementsByTagName("UL").item(0);
					getMenus(menuItem, root);
					initialiseMenu(menuItem, menuStarter, root);
				}
			}
		}
		//return true;
	}
		

	function initialiseMenu(menu, starter, root) {
	//		var menuId = menu.attributes(0).value;
		var leftstarter = false;

		if (menu == null || starter == null) return;
			currentMenu = menu;

		starter.onmouseover = function() {
			if (currentMenu) {
				//alert(this.parentNode.parentNode.id + ' ' + currentMenu.id);
				if (this.parentNode.parentNode!=currentMenu) {
					currentMenu.style.visibility = "hidden";
				}
				if (this.parentNode.parentNode==root) {
					tempCurrentMenu = currentMenu
					while (tempCurrentMenu.parentNode.parentNode!=root) {
						tempCurrentMenu.parentNode.parentNode.style.visibility = "hidden";
						tempCurrentMenu = tempCurrentMenu.parentNode.parentNode;
					}
				}
				currentMenu = null;
				this.showMenu();
				if (document.getElementById("Util1")) {
					document.getElementById("Util1").style.visibility = "hidden";
				}
				if (document.getElementById("Util2")) {
					document.getElementById("Util2").style.visibility = "hidden";
				}				
			}
		}

		menu.onmouseover = function() {
			if (currentMenu) {
				currentMenu = null;
				this.showMenu();
				}
		}	

		starter.showMenu = function() {
			if (!opera) {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetTop + this.offsetHeight + "px";				
				}
				else {
					menu.style.left = this.offsetLeft + this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px";
				}
			}
			else {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetHeight + "px";
				}
				else {
					menu.style.left = this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px"; 
				}

			}


			menu.style.visibility = "visible";
			currentMenu = menu;
		}

		starter.onfocus	 = function() {
			starter.onmouseover();
		}

		menu.onfocus	 = function() {
	//			currentMenu.style.visibility="hidden";
		}

		menu.showMenu = function() {
			if (this == document.getElementById("menu1")) {
			// this works around ie problem where does not position child pages index correctly if not started by menu1 but by navig
			// can safely check menu1, as is menu1 there, so is c4Menu
				var myElm = document.getElementById("c4Menu");
				menu.style.left = myElm.offsetLeft + "px";
				menu.style.top = myElm.offsetTop + myElm.offsetHeight + "px";
				//alert("here");
			}		
			menu.style.visibility = "visible";
			currentMenu = menu;
			stopTime();
		}

		menu.hideMenu = function()  {
			if (!timerOn) {
				mytimer = setInterval("killMenu('" + this.id + "', '" + root.id + "');", 2000);
				timerOn = true;
				for (var x=0;x<menu.childNodes.length;x++) {
					if (menu.childNodes[x].nodeName=="LI") {
						if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
							menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
							menuItem.style.visibility = "hidden";
						}
					}
				}
			}
		}

		menu.onmouseout = function(event) {
			this.hideMenu();
		}

		starter.onmouseout = function() {
			for (var x=0;x<menu.childNodes.length;x++) {
				if (menu.childNodes[x].nodeName=="LI") {
					if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
						menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
						menuItem.style.visibility = "hidden";
					}
				}
			}
			menu.style.visibility = "hidden";
			menu.hideMenu();
		}
	}

	function killMenu(menu, root) {
		var menu = document.getElementById(menu);
		var root = document.getElementById(root);
		menu.style.visibility = "hidden";
		for (var x=0;x<menu.childNodes.length;x++) {
			if (menu.childNodes[x].nodeName=="LI") {
				if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
					menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
					menuItem.style.visibility = "hidden";
				}
			}
		}
		while (menu.parentNode.parentNode!=root) {
			menu.parentNode.parentNode.style.visibility = "hidden";
			menu = menu.parentNode.parentNode;
		}
		stopTime();
	}
	function stopTime() {
		if (mytimer) {
		 		clearInterval(mytimer);
				mytimer = null;
				timerOn = false;
		}
	} 





	function getMenus2(elementItem, root) {
		var selectedItem;
		var menuStarter;
		var menuItem;
		for (var x=0;x<elementItem.childNodes.length;x++) {
			if (elementItem.childNodes[x].nodeName=="LI") {
				if (elementItem.childNodes[x].getElementsByTagName("UL").length>0) {
					menuStarter = elementItem.childNodes[x].getElementsByTagName("A").item(0);
					menuItem = elementItem.childNodes[x].getElementsByTagName("UL").item(0);
					getMenus2(menuItem, root);
					initialiseMenu2(menuItem, menuStarter, root);
				}
			}
		}
		//return true;
	}
	function initialiseMenu2(menu, starter, root) {
	//		var menuId = menu.attributes(0).value;
		var leftstarter = false;

		if (menu == null || starter == null) return;
			currentMenu2 = menu;

		starter.onmouseover = function() {
			if (currentMenu2) {
				if (this.parentNode.parentNode!=currentMenu2) {
					currentMenu2.style.visibility = "hidden";
				}
				if (this.parentNode.parentNode==root) {
					tempCurrentMenu = currentMenu2
					while (tempCurrentMenu.parentNode.parentNode!=root) {
						tempCurrentMenu.parentNode.parentNode.style.visibility = "hidden";
						tempCurrentMenu = tempCurrentMenu.parentNode.parentNode;
					}
				}
				currentMenu2 = null;
				this.showMenu();
				}
		}

		menu.onmouseover = function() {
			//alert(this.id);
			if (currentMenu2) {
				currentMenu2 = null;
				this.showMenu();
			//	if (this.id == "Navig1" && document.getElementById("menu1")) {
			//		document.getElementById("menu1").showMenu();
			//	}
			}
		}	

		starter.showMenu = function() {
			if (!opera) {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetTop + this.offsetHeight + "px";
				}
				else {
					menu.style.left = this.offsetLeft + this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px";
				}
			}
			else {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetHeight + "px";
				}
				else {
					menu.style.left = this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px"; 
				}

			}
			menu.style.visibility = "visible";
			currentMenu2 = menu;
		}

		starter.onfocus	 = function() {
			starter.onmouseover();
		}

		menu.onfocus	 = function() {
	//			currentMenu2.style.visibility="hidden";
		}

		menu.showMenu = function() {
		//	alert(menu.id);
			menu.style.visibility = "visible";
			currentMenu2 = menu;
			stopTime2();
		}

		menu.hideMenu = function()  {
			if (!timerOn2) {
			//	alert(this.id);
				mytimer2 = setInterval("killMenu2('" + this.id + "', '" + root.id + "');", 2000);
				timerOn2 = true;
				for (var x=0;x<menu.childNodes.length;x++) {
					if (menu.childNodes[x].nodeName=="LI") {
						if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
							menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
							menuItem.style.visibility = "hidden";
						}
					}
				}
			}
		}

		menu.onmouseout = function(event) {
			this.hideMenu();
				if (this.id == "Navig1" && document.getElementById("menu1")) {
					document.getElementById("menu1").hideMenu();
				}			
		}

		starter.onmouseout = function() {
			for (var x=0;x<menu.childNodes.length;x++) {
				if (menu.childNodes[x].nodeName=="LI") {
					if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
						menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
						menuItem.style.visibility = "hidden";
					}
				}
			}
			menu.style.visibility = "hidden";
			menu.hideMenu();
		}
	}

	function killMenu2(menu, root) {
		var menu = document.getElementById(menu);
		var root = document.getElementById(root);
		menu.style.visibility = "hidden";
		for (var x=0;x<menu.childNodes.length;x++) {
			if (menu.childNodes[x].nodeName=="LI") {
				if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
					menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
					menuItem.style.visibility = "hidden";
				}
			}
		}
		while (menu.parentNode.parentNode!=root) {
			menu.parentNode.parentNode.style.visibility = "hidden";
			menu = menu.parentNode.parentNode;
		}
		stopTime2();
	}
	function stopTime2() {
		if (mytimer2) {
		 		clearInterval(mytimer2);
				mytimer2 = null;
				timerOn2 = false;
		}
	} 
	


	var currentMenu2Static = null;
	var mytimer2Static = null;
	var timerOn2Static = false;


	function getMenus2Static(elementItem, root) {
		var selectedItem;
		var menuStarter;
		var menuItem;
		for (var x=0;x<elementItem.childNodes.length;x++) {
			if (elementItem.childNodes[x].nodeName=="LI") {
				if (elementItem.childNodes[x].getElementsByTagName("UL").length>0) {
					menuStarter = elementItem.childNodes[x].getElementsByTagName("A").item(0);
					menuItem = elementItem.childNodes[x].getElementsByTagName("UL").item(0);
					getMenus2Static(menuItem, root);
					initialiseMenu2Static(menuItem, menuStarter, root);
				}
			}
		}
		//return true;
	}
	function initialiseMenu2Static(menu, starter, root) {
	//		var menuId = menu.attributes(0).value;
		var leftstarter = false;

		if (menu == null || starter == null) return;
			currentMenu2Static = menu;

		starter.onmouseover = function() {
			if (currentMenu2Static) {
				if (this.parentNode.parentNode!=currentMenu2Static) {
					currentMenu2Static.style.visibility = "hidden";
				}
				if (this.parentNode.parentNode==root) {
					tempCurrentMenu = currentMenu2Static
					while (tempCurrentMenu.parentNode.parentNode!=root) {
						tempCurrentMenu.parentNode.parentNode.style.visibility = "hidden";
						tempCurrentMenu = tempCurrentMenu.parentNode.parentNode;
					}
				}
				currentMenu2Static = null;
				this.showMenu();
				}
		}

		menu.onmouseover = function() {
			//alert(this.id);
			if (currentMenu2Static) {
				currentMenu2Static = null;
				this.showMenu();

			}
		}	

		starter.showMenu = function() {
			if (!opera) {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px";
				}
				else {
					menu.style.left = this.offsetLeft + this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px";
				}
			}
			else {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetHeight + "px";
				}
				else {
					menu.style.left = this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px"; 
				}

			}
			menu.style.visibility = "visible";
			currentMenu2Static = menu;
		}

		starter.onfocus	 = function() {
			starter.onmouseover();
		}

		menu.onfocus	 = function() {
				currentMenu2Static.style.visibility="visible";
		}

		menu.showMenu = function() {
		//	alert(menu.id);
			menu.style.visibility = "visible";
			currentMenu2Static = menu;
			stopTime2Static();
		}

		menu.hideMenu = function()  {
			if (!timerOn2Static) {
				//alert(this.id);
				mytimer2Static = setInterval("killMenu2Static('" + this.id + "', '" + root.id + "');", 1500);
				timerOn2Static = true;
				for (var x=0;x<menu.childNodes.length;x++) {
					if (menu.childNodes[x].nodeName=="LI") {
						if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
							menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
							menuItem.style.visibility = "hidden";
						}
					}
				}
			}
		}

		menu.onmouseout = function(event) {
			this.hideMenu();
				if (this.id == "Navig1" && document.getElementById("menu1")) {
					document.getElementById("menu1").hideMenu();
				}			
		}

		starter.onmouseout = function() {
			for (var x=0;x<menu.childNodes.length;x++) {
				if (menu.childNodes[x].nodeName=="LI") {
					if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
						menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
						menuItem.style.visibility = "hidden";
					}
				}
			}
			//menu.style.visibility = "hidden";
			menu.hideMenu();
		}
	}

	function killMenu2Static(menu, root) {
		var menu = document.getElementById(menu);
		var root = document.getElementById(root);
		menu.style.visibility = "hidden";
		for (var x=0;x<menu.childNodes.length;x++) {
			if (menu.childNodes[x].nodeName=="LI") {
				if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
					menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
					menuItem.style.visibility = "hidden";
				}
			}
		}
		while (menu.parentNode.parentNode!=root) {
			menu.parentNode.parentNode.style.visibility = "hidden";
			menu = menu.parentNode.parentNode;
		}
		stopTime2Static();
	}
	function stopTime2Static() {
		if (mytimer2Static) {
		 		clearInterval(mytimer2Static);
				mytimer2Static = null;
				timerOn2Static = false;
		}
	} 

	
	function getMenus3(elementItem, root) {
		var selectedItem;
		var menuStarter;
		var menuItem;
		for (var x=0;x<elementItem.childNodes.length;x++) {
			if (elementItem.childNodes[x].nodeName=="LI") {
				if (elementItem.childNodes[x].getElementsByTagName("UL").length>0) {
					menuStarter = elementItem.childNodes[x].getElementsByTagName("A").item(0);
					menuItem = elementItem.childNodes[x].getElementsByTagName("UL").item(0);
					getMenus3(menuItem, root);
					initialiseMenu3(menuItem, menuStarter, root);
				}
			}
		}
		//return true;
	}
	function initialiseMenu3(menu, starter, root) {

		if (menu == null || starter == null) return;
			currentMenu3 = menu;

		starter.onmouseover = function() {
			if (currentMenu3) {
				if (this.parentNode.parentNode!=currentMenu3) {
					currentMenu3.style.visibility = "hidden";
				}
				if (this.parentNode.parentNode==root) {
					tempCurrentMenu = currentMenu3
					while (tempCurrentMenu.parentNode.parentNode!=root) {
						tempCurrentMenu.parentNode.parentNode.style.visibility = "hidden";
						tempCurrentMenu = tempCurrentMenu.parentNode.parentNode;
					}
				}
				currentMenu3 = null;
				this.showMenu();
				}
		}

		menu.onmouseover = function() {
			//alert("here");
			if (currentMenu3) {
				currentMenu3 = null;
				this.showMenu();
				}
		}	

		starter.showMenu = function() {
			if (!opera) {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetTop + this.offsetHeight + "px";
				}
				else {
					menu.style.left = this.offsetLeft + this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px";
				}
			}
			else {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetHeight + "px";
				}
				else {
					menu.style.left = this.offsetWidth + "px";
					menu.style.top = this.offsetTop + "px";
				}

			}
			menu.style.visibility = "visible";
			currentMenu3 = menu;
		}

		starter.onfocus	 = function() {
			starter.onmouseover();
		}

		menu.onfocus	 = function() {
	//			currentMenu3.style.visibility="hidden";
		}

		menu.showMenu = function() {
			//alert(this.id);
			menu.style.visibility = "visible";
			currentMenu3 = menu;
			stopTime3();
		}

		menu.hideMenu = function()  {
			if (!timerOn3) {
			//	alert(this.id);
				mytimer3 = setInterval("killMenu3('" + this.id + "', '" + root.id + "');", 2000);
				timerOn3 = true;
				for (var x=0;x<menu.childNodes.length;x++) {
					if (menu.childNodes[x].nodeName=="LI") {
						if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
							menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
							menuItem.style.visibility = "hidden";
						}
					}
				}
			}
		}

		menu.onmouseout = function(event) {
			this.hideMenu();
		}

		starter.onmouseout = function() {
			for (var x=0;x<menu.childNodes.length;x++) {
				if (menu.childNodes[x].nodeName=="LI") {
					if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
						menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
						menuItem.style.visibility = "hidden";
					}
				}
			}
			menu.style.visibility = "hidden";
			menu.hideMenu();
		}
	}

	function killMenu3(menu, root) {
		var menu = document.getElementById(menu);
		var root = document.getElementById(root);
		menu.style.visibility = "hidden";
		for (var x=0;x<menu.childNodes.length;x++) {
			if (menu.childNodes[x].nodeName=="LI") {
				if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
					menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
					menuItem.style.visibility = "hidden";
				}
			}
		}
		while (menu.parentNode.parentNode!=root) {
			menu.parentNode.parentNode.style.visibility = "hidden";
			menu = menu.parentNode.parentNode;
		}
		stopTime3();
	}
	function stopTime3() {
		if (mytimer3) {
		 		clearInterval(mytimer3);
				mytimer3 = null;
				timerOn3 = false;
		}
	} 
	


	window.onload = function() {
		if (document.getElementById("menuList")) {
			var root = document.getElementById("menuList");
			getMenus(root, root);
		}
		
		if (document.getElementById("NavigList")) {
			var root2 = document.getElementById("NavigList");
			getMenus2(root2, root2);
		}		
	
		if (document.getElementById("NavigListStatic")) {
			var root2 = document.getElementById("NavigListStatic");
			getMenus2Static(root2, root2);
		}	
		if (document.getElementById("UtilList")) {
			var root3 = document.getElementById("UtilList");
			getMenus3(root3, root3);
		}

	}	
	
	
// this is where onmouseover function to show child pages from fixed side nav will go
	function showChildPages(menu) {

	}		