/* User Edit Options */
var hmZindexCount = 210; //Set this to be your minimum z-index for the menu.
var hmSetHidden = true; //true if you want the code to hide all submenus at init.
var hmClientAlertsOn = true; //true if you want to show the client any browser specific errors.
var hmDevAlertsOn = false; //true if you want to see any developer specific answeres.
var hmHideDelay = 300; //Set the hide delay, I have found 200-400 to be quite good.

/* DO NOT ATTEMPT TO EDIT CODE BELOW */
var hmToHide = Array();
var hmMenus = Array();
var hmHideCount = 0;
function hmAddEvent(obj, evn, fn){
	if (obj.attachEvent) {
		obj[evn] = fn;
		obj.attachEvent('on' + evn, function(){obj[evn](window.event);});
	}
	else {
		if(obj.addEventListener) obj.addEventListener(evn, fn, false);
		else if(hmClientAlertsOn) alert("Sorry your browser does not support Events Handlers.\r\nPlease upgrade your browser and try again.");
	}
}
function hmToggleMenu(obj, state){
	for(var i = 0; i < obj.childNodes.length; i++){
		if(hmIsAllow(obj.childNodes[i].tagName)){
			if(state == 'visible'){
				clearTimeout(obj['outId']);
				hmZindexCount++;
				obj.style.zIndex = hmZindexCount;
				obj.childNodes[i].style.visibility = 'visible';
			}
			else{
				hmHideCount++;
				hmToHide[hmHideCount] = obj.childNodes[i];
				if(hmHideDelay <= 0) hmHideDelay = 1;
				obj['outId'] = setTimeout('hmToHide['+hmHideCount+'].style.visibility = \'hidden\'',hmHideDelay);
			}
		}
	}
}
function hmIsAllow(el){
	if(el == 'UL'|| el == 'OL') return true;
	else return false;
}
function hmSetEvents(obj){
	if(!obj.childNodes) obj = document.getElementById(obj);
	if(hmIsAllow(obj.tagName)){
		for(var i = 0; i < obj.childNodes.length; i++){
			if(obj.childNodes[i].tagName == 'LI'){
				hmAddEvent(obj.childNodes[i], 'mouseover', function(){hmToggleMenu(this, 'visible');});
				hmAddEvent(obj.childNodes[i], 'mouseout', function(){hmToggleMenu(this, 'hidden');});
				for(var j = 0; j < obj.childNodes[i].childNodes.length; j++){
					if(hmIsAllow(obj.childNodes[i].childNodes[j].tagName)){
						if(hmSetHidden) obj.childNodes[i].childNodes[j].style.visibility = 'hidden';
						hmSetEvents(obj.childNodes[i].childNodes[j]);
					}
				}
			}
		}
	}
	else{
		if(hmDevAlertsOn) alert("Sorry you can only attach HotMenu to an UL or OL!\r\nElement id: " + obj.id);
	}
}
function HotMenu(el){
	for(var i = 0; i < hmMenus.length; i++){
		if(hmMenus[i] == el){
			if(hmDevAlertsOn) alert("Sorry, duplicate attachment!\r\nElement id: " + el);
			return;
		}
	}
	hmMenus[hmMenus.length] = el;
}
hmAddEvent(window, 'load', function(){
	for(var i = 0; i < hmMenus.length; i++){
		hmSetEvents(hmMenus[i]);
	}
});