var timeout;
var nextToShow;
var lastShowed;

function initMenu()
{
	var menuDiv = document.getElementById('menu');
	hideUlUnderLi(menuDiv.getElementsByTagName('ul')[0]);
	var act = document.getElementById('activeid');
	show(act);
}

function show(me)
{
	clearTimeout(timeout);
	nextToShow = me;
	timeout = setTimeout('showNextUl()', 450);
}

// show the first ul element found under this element
function showNextUl()
{
	// hide all submenues
	hideAllUls( nextToShow );
	 // show the active sub menu
    nextToShow.getElementsByTagName('ul')[0].style.display = 'block';
}

// hide all ul on the same level of this list item, except the one
// marked with the activeid
function hideAllUls( currentLi )
{
    var lis = currentLi.parentNode;
	var act = document.getElementById('activeid');
    for ( var i=0; i<lis.childNodes.length; i++ )
    {
        if ( lis.childNodes[i].nodeName=='LI' && lis.childNodes[i] != act)
        {
            hideUlUnderLi( lis.childNodes[i] );
        }
    }
}

// hide all the ul wich are in the given li element
function hideUlUnderLi( li )
{
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ )
    {
        hideel(uls.item(i));
    }
}

// hide the first ul child of the given element
function hide( li )
{
	clearTimeout(timeout);
	lastShowed = li.getElementsByTagName('ul')[0];
	timeout = setTimeout('hideLast()', 100);
}

function hideLast()
{
	hideel(lastShowed);
}

function hideel( el )
{
	el.style.display = 'none';
}


