/*
	Expandable Listmenu Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
	
	Modified by Joel Dueck (jadueck@eml.cc): opening one node closes all other nodes.
	To remove this feature, comment out the vars othernode, othermenu, and the
	for(var m) loop.
*/

function initMenus() {
	if (!document.getElementsByTagName) return;
	
	var aMenus = document.getElementsByTagName("LI");
	for (var i = 0; i < aMenus.length; i++) {
		var mclass = aMenus[i].className;
		if (mclass.indexOf("treenode") > -1) {
			var submenu = aMenus[i].childNodes;
			for (var j = 0; j < submenu.length; j++) {
				if (submenu[j].tagName == "A") {
					
					submenu[j].onclick = function() {
						var node = this.nextSibling;
						var othernodes = this.parentNode.parentNode.childNodes;
						var othermenu;
						
						for(var m = 0; m < othernodes.length; m++) {
							if( (othernodes[m].tagName == "LI") && (othernodes[m].className.indexOf("treenode") > -1)) {
								othermenu = othernodes[m].childNodes;
								for(var k=0; k < othermenu.length; k++) {
									if((othermenu[k].tagName == "UL") && (othermenu[k] != this.nextSibling)) {
										othermenu[k].style.display = "none";
									} else if ((othermenu[k].tagName == "A") && (othermenu[k] != this)) {
										othermenu[k].className = "treeclosed";
									}
								}
							}
						}
							
						while (1) {
							if (node != null) {
								if (node.tagName == "UL") {
									var d = (node.style.display == "none")
									node.style.display = (d) ? "block" : "none";
									this.className = (d) ? "treeopen" : "treeclosed";
									return false;
								}
								node = node.nextSibling;
							} else {
								return false;
							}
						}
						return false;
					}
					
					submenu[j].className = (mclass.indexOf("open") > -1) ? "treeopen" : "treeclosed";
				}
				
				if (submenu[j].tagName == "UL")
					submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";
			}
		}
	}
	
	startList();
}

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

window.onload = initMenus;