﻿var menu = null;
var timeout = null;

function showMenu(sender, target, offX, offY, width, height)
{
    if (timeout != null || menu != null)
        removeMenu();
        
    var y = offY + 0;
    sender.onclick = function() { showMenu(sender, target, offX, y, width, height); return false; };
    sender.onmouseout = startTimeout;


    var posX = getOffsetX(sender);
    var posY = getOffsetY(sender);
    var offHeight = sender.offsetHeight;
    
    if (offX == null)
        offX = 0;
    if (offY == null)
        offY = 0;
        
    if (browser.ie7)
    {
        offY += 2;
    }
    
    menu = document.getElementById(target);
    menu.style.top = (offHeight + posY + offY) + 'px';
    menu.style.left = (posX + offX) + 'px';
    if (width != null && width > 0)
        menu.style.width = width + 'px';
    if (height != null && height > 0)
        menu.style.height = height + 'px';
    menu.style.display = 'block';
    
    menu.onmouseover = stopTimeout;
    menu.onmouseout = startTimeout;
}

function startTimeout()
{
    timeout = setTimeout("removeMenu()", 400);
}

function stopTimeout()
{
    if (timeout != null)
    {
        clearTimeout(timeout);
        timeout = null;
    }
}

function removeMenu()
{
    if (menu != null)
    {
        menu.onmouseout = null;
        menu.onmouseover = null;
        menu.style.display = 'none';
        menu = null;
    }
    if (timeout != null)
        stopTimeout();
}