
var timeout = 1000;

for( var i = 0; i < 100; i++ ) {
    eval("var timeoutli" + i + " = false;");
}

function initMenu() {
    if ( browser.isDOM1 
      && !( browser.isMac && browser.isIE ) 
      && !( browser.isOpera && browser.versionMajor < 7 )
      && !( browser.isIE && browser.versionMajor < 5 )) {
        var menu = document.getElementById('menu');
        var lis = menu.getElementsByTagName('li');
        
        for ( var i=0; i<lis.length; i++ ) {
            // is there a ul element ?
            if ( lis.item(i).getElementsByTagName('ul').length > 0 ) {
                addAnEvent(lis.item(i),'mouseover',show);
                addAnEvent(lis.item(i),'mouseout',timeoutHide);
                addAnEvent(lis.item(i),'blur',timeoutHide);
                addAnEvent(lis.item(i),'focus',show);
                lis.item(i).getElementsByTagName('a')[0].style["background"] = "url(/images/handr.gif) no-repeat right";
                lis.item(i).setAttribute( 'id', "li"+i );
            }
        }
    }
}

function addAnEvent( target, eventName, functionName ) {
    if ( browser.isIE ) {
        eval('target.on'+eventName+'=functionName');
    } else {
        target.addEventListener( eventName , functionName , true );
    }
}
    
function timeoutHide() {
    eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );");
}

function hideUlUnder( id ) {   
    document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden';
}

function show() {
    this.getElementsByTagName('ul')[0].style['visibility'] = 'visible';
    eval ( "clearTimeout( timeout"+ this.id +");" );
    hideAllOthersUls( this );
}

function hideAllOthersUls( currentLi ) {
    var ul = currentLi.parentNode;
    for ( var i=0; i<ul.childNodes.length; i++ ) {
        if ( ul.childNodes[i].id && ul.childNodes[i].id != currentLi.id ) {
            hideUlUnderLi( ul.childNodes[i] );
        }
    }
}

function hideUlUnderLi( li ) {
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ ) {
        uls.item(i).style['visibility'] = 'hidden';
    }
} 
