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

var currentMenu = null;

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

function initializeLeftMenu(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();
        }
    }
  
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
    }

    actuator.showMenu = function() {
    	var leftPos		= 25 + this.offsetLeft + document.getElementById("contentCell").offsetLeft;
    	var topPos		= 20 + this.offsetTop + this.offsetHeight;
        menu.style.left	= leftPos + "px";
        menu.style.top	= topPos + "px";
        menu.style.visibility = "visible";
        currentMenu		= menu;
    }
}

function initializeRightMenu(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();
        }
    }
  
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
    }

    actuator.showMenu = function() {
    	var leftPos		= 25 + this.offsetLeft + document.getElementById("contentCell").offsetLeft - 165 + this.offsetWidth;
    	var topPos		= 20 + this.offsetTop + this.offsetHeight;
        menu.style.left	= leftPos + "px";
        menu.style.top	= topPos + "px";
        menu.style.visibility = "visible";
        currentMenu		= menu;
    }
}

