/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 * Modified: Dave Watkins (Aug 05)
 * Modified: Dave Watkins (Sep 05)
 */

var currentMenu = null;
var noHide = true;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function Timer_Elapsed()
{
	if(!noHide && currentMenu != null)
		currentMenu.style.visibility = 'hidden';
}

window.setInterval('Timer_Elapsed()', 100);

function initializeMenu(menuName) {
	var menuId = menuName + 'Menu';
	var actuatorId = menuName + 'Actuator';
	
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) {
		return;
    }
    
    if(menu.children.length == 0) {
		actuator.onmouseover = function() { noHide = false; }
		return
	}
            
    menu.onmouseover = function() {
		noHide = true;
	}
    
    menu.onmouseout = function() {
		noHide = false;
    }
    
    actuator.onmouseover = function() {
		if(currentMenu != null)
		{
			currentMenu.style.visibility = 'hidden';
			currentMenu = null;
			noHide = false;	
		}
		
        this.showMenu();
    }

    actuator.showMenu = function() {
		var negativeBuffer = 0;
		if(document.all)
			negativeBuffer = 20;
		
        menu.style.left = (this.offsetLeft - negativeBuffer) + "px";
        menu.style.top = this.offsetTop + this.offsetHeight + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
        
        noHide = true;
    }
}