function loaded()
{
    var menuBar = window.document.getElementById('ddm_bar');
    if (menuBar.addEventListener)
    {
        menuBar.addEventListener('mouseover', openMenu,false);
        menuBar.addEventListener('mouseout',closeMenu,false);
    }
    else
    {
        menuBar.attachEvent('onmouseover',openMenu);
        menuBar.attachEvent('onmouseout',closeMenu);
    }
}


function openMenu(e)
{
    e=e || window.event;
    var li = getLI(e.target || e.srcElement);
    var from = e.relatedTarget || e.fromElement;
    
    if (li !=from && !isDescendant(from, li))
    {
        li.className='ddm_highlighted';
        var div = window.document.getElementById(li.id + '_commands');
        if (div) div.style.visibility = 'visible';
    }
}

function closeMenu(e)
{
    e=e || window.event;
    var li = getLI(e.target || e.srcElement);
    var to = e.relatedTarget || e.toElement;
    
    if (li != to && !isDescendant(to,li))
    {
        li.className='ddm';
        var div = window.document.getElementById(li.id + '_commands');
        if (div) div.style.visibility = 'hidden';
    }
}
function isDescendant(node,ancestor)
{
    if (ancestor.hasChildNodes())
    {
        var childs = ancestor.childNodes;
        for (var i=0;i<childs.length;i += 1)
            if (childs[i]==node) return true;
            else if (isDescendant(node,childs[i])) return true;
    }
    return false;
}

function getLI(node)
{
    while (node && node.tagName !='LI') node=node.parentNode;
    return node;
}
if (window.addEventListener) window.addEventListener('load',loaded,false);
else window.attachEvent('onload',loaded);
