/* DECLARE VARIABLE (you can change it) */

// delay before closing in milliseconds
delay_ms = 800; 

/* END DECLARE VARIABLE */


function closeMenuItem(id) {
	var m = document.getElementById(id);
	if (m && m.getAttribute("shouldClose")==1){
		m.lastChild.style.display="none";
		m.style.backgroundColor="#0094c2";
	}
}

//document.getElementById("err").innerHTML = document.getElementById("err").innerHTML+m.id+" "+current_item_id+"<br>";

activateMenu = function(nav) {

	/* currentStyle restricts the Javascript to IE only */
	var navroot = document.getElementById(nav);

	/* Get all the list items within the menu */
	var lis=navroot.getElementsByTagName("LI");
	for (i=0; i<lis.length; i++) {

		// set id for tag
		 lis[i].setAttribute("id","_za_menuitem"+i);

		/* If the LI has another menu level */
		if(lis[i].lastChild.tagName=="UL"){

		/* assign the display function to the LI */
		lis[i].onmouseover=function() {

			this.setAttribute("shouldClose",0);
			/* display the inner menu */
			this.lastChild.style.display="block";
			/* change background color */
			this.style.backgroundColor="#ff6600";
		}

		/* assign the hide function */
		lis[i].onmouseout=function(event) {
			this.setAttribute("shouldClose",1);

			var e = event || window.event;
		    var target = e.relatedTarget || e.toElement;

			if (isParent(target, document.getElementById("menu")))
			{
				this.lastChild.style.display="none";
				this.style.backgroundColor="#0094c2";
			} else {
				current_time_id = setTimeout("closeMenuItem('"+this.id+"')",delay_ms);
			}
		}
	}
	/* If the LI has no children */
	else {
		/* assign the function to the LI */
		lis[i].onmouseover=function() {
			this.style.backgroundColor="#ff6600";
		}
		lis[i].onmouseout=function() {
			this.style.backgroundColor="#0094c2";
		}
	}
}
}

/* is parent have child? */
function isParent(child, parent) {
    if (!child || !parent) {
        return false;
    }
    while (true) {
        if (child == parent) {
            return true;
        }
        if (child.parentElement) {
            child = child.parentElement;
        } else if (child.parentNode) {
            child = child.parentNode;
        } else {
            return false;
        }
    }
}

window.onload= function(){
    activateMenu('menu');

    // Fix Firefox 1.0.4
    if(navigator.userAgent.indexOf('1.0.4')!=-1)
    {
		document.getElementById('menu').className = 'FF104';
	}
}