if (!document.getElementById)
    document.getElementById = function() { return null; }	

var currentMenu = null;


// set up the onmouseout-functionality
var mouseOverItem = null;
var mouseOverTimer = null;
var mouseOverDelay = 800; 	// number of millisecond delay before menu closes
var offsetY = -12; 			// X- and Yoffset of the submenus
var offsetX = -12; 			//-8;	



function initTopNav(menuId, actuatorId) {
    if (menuId == "sub") return;
	
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
	
	//if there's no toplevel node defined, then stop this nonsense.
	if (actuator == null) return;
     
	actuator.onmouseover = function() {
		if (currentMenu) {
			currentMenu.style.visibility = "hidden";
			this.showMenu();
			
		} 
		else {
			 this.showMenu(); 	 
		}
		if (menu != null) menu.onmouseover();
	}
	
	
	actuator.onmouseout = function(e) {
		if (menu != null) menu.onmouseout();
	}
	
	// hide these functions in case there is no sublevels
	if (menu != null) {
		
		menu.onmouseout = function() {
			if (currentMenu != null) {
				actuator.setMouseOverMenu(null);
				mouseOverTimer = setTimeout('if (currentMenu != null) currentMenu.tryHideMenu()', mouseOverDelay);
			}
			return true;
		}
		
		menu.onmouseover = function() {
			clearTimeout(mouseOverTimer);
			if (currentMenu != null) {
				actuator.setMouseOverMenu(this);
				
			}
			return true;
		}
		
		menu.tryHideMenu = function() {
			if (mouseOverItem == null) {
				if (currentMenu != null) actuator.hideMenu();
			}
			return true;
		}

	}
	//end hide 'menu' events...
	
	
	
	actuator.setMouseOverMenu = function(item) {
		mouseOverItem = item;
	}
	
   
   
	actuator.onclick = function() {
		
		//topnav link is only clickable when there's no sublevels
		//return (menu == null); 	
		//if the link url is just a # then return false, that is, do nothing 
		//when the top menu is clicked, otherwise go to the url specified...
		//return (this.href.indexOf('#') == 1);
		return true
	}
	
	
	actuator.showMenu = function() {
		if (menu != null) {
			menu.style.left = this.offsetLeft + offsetX + "px";
			//menu.style.top = this.offsetTop + offsetY + this.offsetHeight + "px";
			menu.style.visibility = "visible";
			currentMenu = menu;
		}
	}
	
	
	actuator.hideMenu = function() {
		 currentMenu.style.visibility = "hidden";
		 currentMenu = null;
	}
	
	
	actuator.onfocus = function() {
		actuator.blur();
	}
	
	
	// catch clicks and hide submenu if clicked elsewhere on page...
	document.body.onclick = function() {
		if (currentMenu != null) actuator.hideMenu();
		return true;
	}
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
