/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (dave@gazingus.org)
 * Modified by Kent Rauch (kent@restekcorp.com)
	* menu activation based on mouseover, not click
	* introduced onmouseout, delays, and event handlers for the menu items
	* menu/submenu alignment can be right or left
	* dynamic submenus -- currentMenu is an array now, global var Depth indexes it
 */

var currentMenu = new Object;
var Depth = null;

if (!document.getElementById)
{
    document.getElementById = function() { return null; }
}

function initializeMenu(Id, leftOff, Depth)
{
    var menuId = Id + "Menu";
    var actuatorId = Id + "Actuator";
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
    var navlinkId = Id + "Link";
    menu && (menu.navlink = document.getElementById(navlinkId));
    menu && (menu.recall = new Image);

    if (menu == null || actuator == null) return;

    if (window.opera) return; // I'm too tired

    // positioning the submenu indicators...
    var bloop = document.getElementById(Id+"Bloop");
    if (bloop)
    {
        bloop.style.top = actuator.offsetTop + 1 + "px";
        bloop.style.left = actuator.offsetLeft + menu.parentNode.parentNode.offsetWidth - 14 + "px";
        menu.bloop = bloop;
    }

    actuator.alignRight = leftOff;

    actuator.onmouseover = function()
    {
        if (currentMenu[Depth] == null)
        {
            this.showMenu();
        }
        else
        {
	        var i = Depth;
	        while (currentMenu[i])
	        {
	            eval("clearTimeout(byebye"+i+");");
	            hidemenu(i);
                /*	    
                currentMenu[i].style.visibility = "hidden";
                if (currentMenu[i].navlink){currentMenu[i].navlink.src = currentMenu[i].recall.src;}
	            */
	            ++i;
	        }
            this.showMenu();
        }
        return false;
    }

    actuator.onmouseout = function()
    {
        eval("byebye"+Depth+" = setTimeout('hidemenu("+Depth+");', 300);");
    }

    actuator.showMenu = function()
    {
	    if (menu.navlink) {
	        menu.navlink.src = "/nav_graphics/" + Id + "B.jpg";
	        menu.recall.src = "/nav_graphics/" + Id + "A.jpg";
	    }
	    /*if (menu.bloop) {menu.bloop.src = "/graphics/bloopb.gif";}*/
	    if (this.alignRight)
	    {
	        if(Depth)
	        {
	            // does not work with Netscape 6.2...
	            menu.style.left = this.offsetLeft - menu.offsetWidth - 1 + "px";
	        }
	        else
	        {
	            if(document.all)
	            {
	                //We have an IE based browser - add the left offset to the parent leftoffset to get the true left offset
	                IEoffwidth = this.parentNode.offsetLeft + this.offsetLeft - this.offsetWidth;
                    menu.style.left = IEoffwidth + "px";
	            }
	            else
	            {
	                menu.style.left = this.offsetLeft - menu.offsetWidth  + this.offsetWidth + "px";
	            }
	        }
	    }
	    else
	    {
	        if(Depth)
	        {
	            menu.style.left = this.offsetLeft + this.offsetWidth - 1 + "px";
	        }
	        else
	        {
	            if(document.all)
	            {
	                //We have an IE based browser - add the left offset to the parent leftoffset to get the true left offset
	                IEoffwidth = this.parentNode.offsetLeft + this.offsetLeft;
                    menu.style.left = IEoffwidth + "px";
                }
                else
                {
                    menu.style.left = this.offsetLeft + "px";
                }
	        }
	    }
	    if (Depth)
	    {
	        menu.style.top = this.offsetTop - 1 + "px";
        }
	    else
	    {
            //menu.style.top = this.offsetTop + this.offsetHeight - 1 + "px";
	        menu.style.top = "85px";
    	}
        menu.style.visibility = "visible";
        currentMenu[Depth] = menu;
    }

    menu.onmouseover = function()
    {
        eval("clearTimeout(byebye"+Depth+");");
        this.style.bgcolor = "#ffff66";
    }
    menu.onmouseout = function()
    {
        eval("byebye"+Depth+" = setTimeout('hidemenu("+Depth+");', 300);");
    }
    
}
//end func initializeMenu


function hidemenu(deep)
{
    if (currentMenu[deep])
    {
	    currentMenu[deep].style.visibility = "hidden";
	    if (currentMenu[deep].navlink)
	    {
	        currentMenu[deep].navlink.src = currentMenu[deep].recall.src;
	    }
        /*
        if (currentMenu[deep].bloop) {currentMenu[deep].bloop.src = "/graphics/bloop.gif";}
        */
	    currentMenu[deep] = null;
    }
}

/* what it still needs:
 * NS fix for left-hanging submenus

*/