var delay=800;
var submenu=null;
var shover=null;
var isOver=false;
var timer=null;
var timer2=null;
function initMenu(){
	var menus=utils.getElementsByClass(document,"menu02","ul");
	var sfEls=menus[0].getElementsByTagName("li");
	for(var i=0; i<sfEls.length;i++){
		sfEls[i].onmouseover=function(){
			utils.css(this,"shover","add");
			var el=this.getElementsByTagName("ul");
			//alert(el.length);
			if(el.length>0){
				
				if(!isOver){
					isOver=true;
					shover=this;
					submenu=el[0];
					FadeIn(delay);
				}else if(isOver && (shover!=this)){
					hideOut();
					clearTimeout(timer);
					isOver=true;
					shover=this;
					submenu=el[0];
					FadeIn(delay);
				}else if(isOver && (shover==this)){
					clearTimeout(timer);
				}
			}
		};
		sfEls[i].onmouseout=function(){
			var el=this.getElementsByTagName("ul");
			if(el.length>0){
				timer=setTimeout("hideOut()", 800);
			}
		}
	}
}
function hideOut(){
	clearTimeout(timer2);
	utils.css(shover,"shover","remove");
	isOver=false;
	shover=null;
	submenu=null;
	
}
function FadeIn(remainingTime) {

	if (remainingTime < 0) {

	} else {
		var opacity = 1 - remainingTime / delay;
		if(submenu!=null){
			setOpacity(submenu, opacity);
		}
		//alert("FadeIn("+(remainingTime - 80)+")");
		timer2=setTimeout("FadeIn("+(remainingTime - 80)+")", 80);
	}
}
function setOpacity(element, opacity) {
	// set the transparency property of element in all browsers
	element.style["-moz-opacity"] = opacity; // mozilla
	element.style.filter = "alpha(opacity=" + opacity * 100 + ")"; // IE
	element.style.opacity = opacity; // other browsers, like Opera
}
var utils={
	css:function(el, targetclass, action){
		var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
		if (action=="check")
			return needle.test(el.className)
		else if (action=="remove")
			el.className=el.className.replace(needle, "")
		else if (action=="add" && !needle.test(el.className))
			el.className+=" "+targetclass
	},
	getElementsByClass:function(el,classname,tag){
		var a_array=el.getElementsByTagName(tag);
		var b_array=new Array();
		for(var i=0;i<a_array.length;i++){
			if(utils.css(a_array[i],classname,"check")){
				b_array.push(a_array[i]);
			}
		}
		return b_array;
	}

}

function init(){
	initMenu();
}
if(window.attachEvent){
	window.attachEvent("onload",init);
}else{
	window.addEventListener("load",init,false);
}

