/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (dave@gazingus.org)
 */

var currentMenu = null;
var TOpoint = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }
    
function timeOut(){
   	if (currentMenu) {
		currentMenu.style.visibility = "hidden";
		currentMenu = null;
	}
}

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    //if (window.opera) return; // I'm too tired

    actuator.onmouseover = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden"; 
        } 
        this.showMenu();
        
        if(TOpoint){
        	clearTimeout(TOpoint);
        }
        TOpoint = setTimeout('timeOut()', 5000); 
        //alert("menu");
    }
  
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
            if(TOpoint){
				clearTimeout(TOpoint);
			}
			TOpoint = setTimeout('timeOut()', 5000); 
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }
        return false;
    }

    actuator.showMenu = function() {
        //menu.style.left = (this.offsetLeft - 5 ) + "px";
        //menu.style.top = this.offsetTop + this.offsetHeight + "px";
        //menu.style.top = this.offsetTop + "px";
    	
		menu.style.visibility = "visible";
       	currentMenu = menu;
    }
}