var menu_id=0;
var menu_interval=new Array();
var menu_timeout=400;
var menu_timein=300;

function add_menu_events(o) {
	for(var i=0; i<o.childNodes.length; i++) {
		var p=o.childNodes[i];
/*		for(var j=0; j<p.childNodes.length; j++) {
			alert(p.childNodes[j].tagName);
		}

*/
		if(p.childNodes.length>0 && p.lastChild.tagName=='UL') {
			if(!p.lastChild.id) {
				menu_id+=1;
				p.lastChild.id="menu"+menu_id;
			}

			p.onmouseout=function(){ hide_menu(this.lastChild); this.className=new String(this.className).replace('hover',''); };
			p.onmouseover=function(){ show_menu(this.lastChild); this.className+=" hover"; };
			p.lastChild.onmouseout=function(){ hide_menu(this); };
			p.lastChild.onmouseover=function(){ show_menu(this); };

			if(p.className) p.style.className+=" ";
			p.className+="expandable";

			add_menu_events(p.lastChild);
		} else 	if(p.tagName=='LI') {
			p.onmouseout=function(){ this.className=new String(this.className).replace('hover',''); };
			p.onmouseover=function(){ this.className+=" hover"; };
		}
	}
}

function hide_menu(o){
	clearTimeout(menu_interval[o.id]);
	menu_interval[o.id]=setTimeout("clear_menu('"+o.id+"')",menu_timeout);
}

function clear_menu(o){
	o=document.getElementById(o);
	o.style.display='none';
}

function show_menu(o){
	clearTimeout(menu_interval[o.id]);
	menu_interval[o.id]=setTimeout("display_menu('"+o.id+"');",menu_timein);
}

function display_menu(o){
	o=document.getElementById(o);
	o.style.display='block';
}

//add_menu_events(document.getElementById('main_menu'));
