/* /////////////////////////////////////////////////////////////////////

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 = 800; 	// number of millisecond delay before menu closes
var offsetY = 2; 			// X- and Yoffset of the submenus
var offsetX = 0 			//-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;
	}
}

/*	
/////////////////////////////////////////////////////////////////////// 

LEFT-NAVIGATION
///////////////////////////////////////////////////////////////////////  */	


var leftOpen = null;
var leftOpenActuator = null;

// Usage: initLeftNav(subnavId, leftnavId);
function initLeftNav(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
	var stayOpen = false;
	
    
    if (menu == null || actuator == null) return;
    actuator.style.backgroundRepeat = "no-repeat";
	actuator.style.backgroundPosition = "right";	
		
	//is the submenu expanded by default?
	if (actuator.parentNode.className == "on" || actuator.parentNode.className == "open") {  // Changed Aslak
		actuator.style.backgroundImage = "url(images/mnuarrowon.gif)";
		menu.style.display = "block"
		//stayOpen = true;
		leftOpen = menu;
		leftOpenActuator = actuator;
	} 
	else {
		actuator.style.backgroundImage = "url(images/mnuarrow.gif)";
		menu.style.display = "none";
	}
    
    // blurs the links onfocus...  
    actuator.onfocus = function() {
    	actuator.blur();
    }
    
    actuator.onclick = function() {
    	var display = menu.style.display; 
    	
    	//this handles the foldin/foldout thingy
    	if (display == "block") {
    		 //if (!stayOpen) {
				 this.parentNode.className = "";
				 this.style.backgroundImage = "url(images/mnuarrow.gif)";
				 menu.style.display = "none";
				 leftOpen = null;
			//}
		}
    	else {
    		menu.style.display = "block";
    		this.parentNode.className = "open";
    		this.style.backgroundImage = "url(images/mnuarrowon.gif)";
    		
    		
    		
    		if (leftOpen != null) {
    			leftOpen.parentNode.className = "";
				leftOpen.style.display = "none";
				
				leftOpenActuator.style.backgroundImage = "url(images/mnuarrow.gif)";
				
			}
			leftOpen = menu;
			leftOpenActuator = actuator;
    	}
        return false;
    }
}


/*	
/////////////////////////////////////////////////////////////////////// 

TAB-NAVIGATION
///////////////////////////////////////////////////////////////////////  */	

var tabNavOn = null;
var tabTextOn = null;


// Usage: initTabNav(tabtextId, tabId);
function initTabNav(tabtextId, actuatorId) {
    var tabtext = document.getElementById(tabtextId);
    var actuator = document.getElementById(actuatorId);
	
    if (tabtext == null || actuator == null) return;
    
   	tabtext.style.display = "none";
    
	//is the tab selected by default?
	if (actuator.className == "on") {
		
		tabtext.style.display = "block";
		tabNavOn = actuatorId;
		tabTextOn = tabtextId;
	} 
    
    
    // blurs the links onfocus...  
    actuator.onfocus = function() {
    	actuator.blur();
    }
    
    actuator.onclick = function() {
    	if (tabNavOn != null) {
    		document.getElementById(tabNavOn).className = "";
    		document.getElementById(tabTextOn).style.display = "none";	
    		
    	}
    	
    	tabtext.style.display = "block";
    	actuator.className = "on";
    	
    	tabNavOn = actuatorId;
		tabTextOn = tabtextId;
    		
        return false;
    }
    
}

/*	
/////////////////////////////////////////////////////////////////////// 

TOOLTIP
///////////////////////////////////////////////////////////////////////  */	

//variables for mouse positioning
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
	if (document.all) { 
		
		var scrollPos = (!document.documentElement.scrollTop) ? document.body.scrollTop : document.documentElement.scrollTop;
		tempX = window.event.clientX + document.body.scrollLeft;
		tempY = window.event.clientY + scrollPos;
		
	}
	else { 
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	//window.status= 'x:' + tempX + ', Y:' + tempY; 
}



function doTooltip(obj) {
	if (!document.getElementById('tltp')) return false;
	var theEnd = '<br /><br /> klik for at lukke...';
	
	var newText = (obj.title != null) ? obj.title : document.getElementById(obj).innerHTML; 
	
	var exbox = document.getElementById('tltp');
	var txt = document.getElementById('tltpTxt');
	
	exbox.style.left = tempX + "px";
    exbox.style.top = tempY + "px";
    
	txt.innerHTML = newText + theEnd;
	exbox.style.visibility='visible';
}


function hideTooltip() {
	document.getElementById('tltp').style.visibility = 'hidden';
}

//not neccessary since were not implementing any support for NS4
//if (!document.all) document.captureEvents(Event.MOUSEMOVE)

//if there's a tooltip div present on the page, catch the mouseposition
if (document.getElementById('tltp')) document.onmousemove = getMouseXY;

/*	
/////////////////////////////////////////////////////////////////////// 

END.
///////////////////////////////////////////////////////////////////////  */	

