/* /////////////////////////////////////////////////////////////////////

Dropdown menu / onmouseout hiding of sublevels
by Bj&#353;rn Carlsson (bjorn.carlsson@creuna.dk) &  Martin M&#376;ntzing

dropdowns and left navigation is based on a script 
by Dave Lindquist (dave@gazingus.org)
	
/////////////////////////////////////////////////////////////////////// 

INIT AND TEST...
/////////////////////////////////////////////////////////////////////// */	

// old browsers; fade out in style
if (!document.getElementById)
    document.getElementById = function() { return null; }	
	// the following check is not needed, since opera7 will display the menus correctly, 
	// and it's still usable (but somewhat buggy) on older versions...
	// var oprah = navigator.userAgent.indexOf('Opera')!=-1;



/*	
/////////////////////////////////////////////////////////////////////// 

TOP-NAVIGATION
/////////////////////////////////////////////////////////////////////// */

var currentMenu = null;


// set up the onmouseout-functionality
var mouseOverItem = null;
var mouseOverTimer = null;
var mouseOverDelay =200; 	// number of millisecond delay before menu closes
var offsetY =3; 			// X- and Yoffset of the submenus
var offsetX =-6; 			//-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;
	}
}

