var hideMsgID = 0;

function hideAllMenus()
{
    // Since we are hiding all menus, we can cancel any hide messages in transit.
    if ( hideMsgID != 0 )
    {
        clearTimeout( hideMsgID );
        hideMsgID = 0;
    }

    var mySubmenus = document.getElementById("menu_main").getElementsByTagName("ul");
    for ( menu in mySubmenus )
    {
        if ( ( mySubmenus[menu] != null ) && ( mySubmenus[menu].style != null ) )
        {
            // Hide this submenu itself
            mySubmenus[menu].style.display="none";

            // Un-'hover' its parent list item ('tab').
            var ancestorLI = YAHOO.util.Dom.getAncestorByTagName(mySubmenus[menu], "li" );
            YAHOO.util.Dom.removeClass(ancestorLI, "hovered");
        }
    }

    // Finally, set the submenu bar back to its default state. 
    YAHOO.util.Dom.removeClass(YAHOO.util.Dom.get("menubar_sub"), "hovered");
}

function showMenu(tabID)
{
    // Hide all the menus. This also clears any hide messages in transit.
    hideAllMenus();
    
    // Grab the submenu we need to show. 
    var currentSubMenu = document.getElementById(tabID);
    
    // Show it!    
    currentSubMenu.style.display="inline";

    // And color the menus to let users know what they are seeing. 
    // That includes the submenu bar and the list item ('tab') that is the parent of the current submenu.
    // Note that we skip this for the default menu.
    if ( tabID != "menu_default" )
    {
        YAHOO.util.Dom.addClass(document.getElementById("menubar_sub"), "hovered");
        var ancestorLI = YAHOO.util.Dom.getAncestorByTagName(currentSubMenu, "li" );
        YAHOO.util.Dom.addClass(ancestorLI, "hovered");
    }
}

function delayedHideMenu(tabID)
{
    // Don't bother trying to hide the default menu.
    if ( tabID != "menu_default" )
    {
        hideMsgID = setTimeout(hideMenu, 2000);
    }
}

function hideMenu()
{
    // The message arrived! No need to keep tracking it.
    hideMsgID = 0;

    // Hide all the menus. 
    hideAllMenus();
    
    // Show the default menu. 
    document.getElementById("menu_default").style.display="inline";
}
