var curElement;
var timer = 0;
var curID = "";

var posLeft;
var posTop;

var extraOffsetLeft = 12;
var extraOffsetTop = 0;

var MenusArray = new Array();
MenusArray[0] = "KeiraDropMenu";
MenusArray[1] = "CaymanDropMenu";
MenusArray[2] = "CozumelDropMenu";


// Gets the top position of all parent elements as well as the current element and adds
// them together so that the screen position from the top is returned.
function getAbsoluteOffset(elementName)
{
    var curElement = document.getElementById(elementName);
    var oTop = curElement.offsetTop;
    
    if (curElement.parentNode != null)
    {
        curElement = curElement.parentNode
        oTop = oTop + curElement.offsetTop;
    }
    
    return oTop;
}

// Determines if the tip is already displayed.  If not, it gets the top and left positions
// of where the menu should be displayed and calls the positionTip() function to display
// the tip. 
function displayTip(elementName, menuName)
{
    for (var i = 0; i < MenusArray.length; i++)
    {
        if (MenusArray[i] != menuName)
        {
            hideTip(MenusArray[i]);
        }
    }
    
    if (curID != elementName && curID != "")
    {
        hideTip(menuName);
    }
    curID = menuName;

    curElement = document.getElementById(elementName);
    posLeft = curElement.offsetLeft + curElement.offsetWidth + extraOffsetLeft;
    posTop = getAbsoluteOffset(elementName) + extraOffsetTop;       
    positionTip(menuName);

    holdTimeout();
}

// Sets a timer so that the menu is displayed for 1 second before disappearing
function Wait(id)
{
    timer = setTimeout("hideTip('" + curID + "')", 1000);
}

// Cancels the timer if it is running
function holdTimeout()
{
    if (timer)
    {
        clearTimeout(timer);
        timer = 0;
    }
}

// Hides the menu
function hideTip(id)
{
        document.getElementById(id).style.visibility = "hidden";
        curID = "";
        enableTip = false;
}

// Positions the menu and makes it visible
function positionTip(menuName)
{
    document.getElementById(menuName).style.left = posLeft + "px";
    document.getElementById(menuName).style.top = posTop + "px";            		
    document.getElementById(menuName).style.visibility = "visible";
}
