// the timeout for the menu
var timeout = 1000;

// hide the first ul element of the current element
function timeoutHide(obj) {
    eval( "timeout" + obj.id + " = window.setTimeout('hideUlUnder( \"" + obj.id + "\" )', " + timeout + " );");
}

// hide the ul elements under the element identified by id
function hideUlUnder(id) {
    var uls=document.getElementById(id).getElementsByTagName('ul');
    if (uls.length>=1) {
   		uls[0].style['visibility'] = 'hidden';
		x = document.getElementById(id);
		x.className = "";
    }
}

// show the first ul element found under this element
function show(obj) {
	obj.className = "onstate";
	
	// show the sub menu
    var uls=obj.getElementsByTagName('ul');
    if (uls.length>=1) {
    	uls[0].style['visibility'] = 'visible';
    }
    
	// clear the timeout
	if (eval("typeof(timeout"+obj.id+")") != "undefined")
    	eval ("clearTimeout( timeout"+ obj.id +");");
    
	hideAllOtherUls(obj);
}

// hide all uls on the same level of this list item
function hideAllOtherUls(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) {
			
            ul.childNodes[i].className = "";
			hideUlUnderLi(ul.childNodes[i]);
        }
    }
}

// hide all uls which are in the li element
function hideUlUnderLi(li) {
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ ) {
        uls.item(i).style['visibility'] = 'hidden';
    }
}