// see artivle about creating CSS menu  on "A List Apart" 
// http://www.alistapart.com/articles/horizdropdowns/
// http://www.alistapart.com/articles/dropdowns/
// --------------------------------------------------
// and one Bieler Batiste fix for IE
// faden@PASDEPOURRIELaltern.org - remove ( PASDEPOURRIEL )
// or send me a mail with this form
// http://www.magnin-sante.ch/journal/?p=mailto.php&amp;m=gbefoAbmufso/psh
// 

var timeout = 500;

for( var i = 0; i < 100; i++ )
{
    eval("var timeoutli" + i + " = false;");
}

// inicjalizacja menu


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');
        
        menu.className='menu';
        
        for ( var i=0; i<lis.length; i++ )
        {
            if ( lis.item(i).getElementsByTagName('ul').length > 0 )
            {        

                if ( browser.isIE )
                {
                dodajZdarzenie(lis.item(i),'keyup',show);
                }
                dodajZdarzenie(lis.item(i),'mouseover',show);
                dodajZdarzenie(lis.item(i),'mouseout',timeoutHide);
                dodajZdarzenie(lis.item(i),'blur',timeoutHide);
                dodajZdarzenie(lis.item(i),'focus',show);
                
                lis.item(i).setAttribute( 'id', "li"+i );
              
            }
        }
    }
}

function dodajZdarzenie( 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()
{
    // pokaz pod-menu
    this.getElementsByTagName('ul')[0].style['visibility'] = 'visible';
    // wyczysc opoznienie
    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] );
        }
    }
}


// chowaj UL pod LI
function hideUlUnderLi( li )
{
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ )
    { uls.item(i).style['visibility'] = 'hidden';}
} 