
initMenus = function(){
	initMenu("sub_menu");
	initMenu("menu");
	setSelected();
}

initMenu = function(menu_id) {

	//Set up dropdown/popout menu system

	var nav_items = getElementsBySelector("#" + menu_id + " li");
	
	for (i=0; i<nav_items.length; i++) {
		node = nav_items[i];
		if (node.nodeName=="LI") {
			
			if(node.getElementsByTagName("UL").length > 0){
				node.className += " has_sub";
				node.hasSub = true;
				uls = node.getElementsByTagName("UL");
				
				for(var j = 0; j<uls.length; j++){
					var lc = uls[j].lastChild;
					while(lc.tagName != "LI")
						lc = lc.previousSibling;
						
					lc.className += " last";
				}
			}

			node.onmouseover=function() {

				if(this.hasSub)
					this.className+=" has_sub_over";
				else
					this.className+=" over";
					
			}
			node.onmouseout=function() {
				this.className=this.className.replace("has_sub_over", "");					
				this.className=this.className.replace("over", "");			
			}
  	}
	}
}

function setSelected(){
		//Open current location in menu
	var loc = window.location.toString().replace(window.location.hash, "");


	var menu_items = getElementsBySelector("a");
	for(var i=0; i<menu_items.length; i++){
		var m = menu_items[i];
		if(m.href == loc){
			m.className += "selected";
		}
	}
}

EventUtils.addEventListener(window,'load',initMenus);

