//Variables
var strHideMenu;
var iHideTimeout;
var arrMenuTitles = new Array();
var arrMenus = new Array();
var objMenu;


//-------------------------------Show/hide menu--------------------------------

/**
 * Shows the menu
 * @param menuID - the ID of the menu to show.
 */
function showMenu(menuID) {
    disappearMenu();
    document.getElementById(menuID).style.visibility = "visible";
    document.getElementById(menuID).style.display = "block";
}

/**
 * Sets up the call to the hide function.
 * @param menuID - the menu to hide.
 */
function hideMenu(menuID) {
    strHideMenu = menuID;
    iHideTimeout = setTimeout("disappearMenu()", 100);
}

/**
 * Cancels the call to the hide function.
 */
function cancelHide()
{
    clearTimeout(iHideTimeout);
    strHideMenu = "";
}

/**
 * Does the work of hiding the menu.
 */
function disappearMenu()
{
    if(null == strHideMenu || "" == strHideMenu)
    {
        clearTimeout(iHideTimeout);
        return;
    }
    clearTimeout(iHideTimeout);
    document.getElementById(strHideMenu).style.visibility = "hidden";
    document.getElementById(strHideMenu).style.display = "none";
}



//------------------Move the dropdowns to the correct location-----------------

/**
 * Removes the drop down menus and places them at the end of the document.
 */
function ReplaceMenus()
{

    objMenu = document.getElementById("menu");

    if(null != objMenu && is_ie7)
    {
        var arrDropDown = objMenu.getElementsByTagName("div");
        var objBody = document.getElementsByTagName("body")[0];

        for(var i=0; i<arrDropDown.length; i++)
        {
            if("dropdown" == arrDropDown[i].className)
            {
                //Get the element
                var objDropdown = document.getElementById(arrDropDown[i].id);
                arrMenus[arrMenus.length] = objDropdown;
                arrMenuTitles[arrMenuTitles.length] = objDropdown.parentNode;
                try
                {
                    //Remove the node from the menu and put it at the end of the page
                    objDropdown.parentNode.removeChild(objDropdown);
                    objBody.insertBefore(objDropdown, objBody.lastChild);
                }catch(Err){alert(Err);}

                objDropdown.style.display = 'none';
                objDropdown.style.position = 'absolute';
                objDropdown.style.zIndex = '90';
                objDropdown.style.float = 'none';
            }
        }
        placeMenus();
        AddResizeHandler(placeMenus);
    }
}

/**
 * Places the menus at the correct position on the screen.
 */
function placeMenus()
{
    for(var i=0; i<arrMenus.length && is_ie7; i++)
    {
    if (i != 3)
    {
    if (i == 6)
    {
    var iLeft, iTop;
        iTop = 245;
        iLeft = objMenu.offsetLeft + objMenu.parentNode.offsetLeft + arrMenuTitles[3].offsetLeft;
        arrMenus[i].style.top = ""+iTop;
        arrMenus[i].style.left = ""+iLeft;
    }
    else
    {
    var iLeft, iTop;
        iTop = 245;
        iLeft = objMenu.offsetLeft + objMenu.parentNode.offsetLeft + arrMenuTitles[i].offsetLeft;
        arrMenus[i].style.top = ""+iTop;
        arrMenus[i].style.left = ""+iLeft;
    }
     }   
    }
}
