/* 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 = 200; //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 hmMenusDone = Array();
var hmHideCount = 0;
var hmDropState = 'visible';
var hmDropCount = 0;
function hmAddEvent(obj, evn, fn){
	if (obj.attachEvent) {
		obj["HotMenu" + evn] = fn;
		obj.attachEvent('on' + evn, function(){obj["HotMenu" + 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])){
			if(state == 'visible'){
				clearTimeout(obj['outId']);
				hmZindexCount++;
				if(hmZindexCount > 300) hmZindexCount = 210;
				obj.style.zIndex = hmZindexCount;
				obj.childNodes[i].style.visibility = 'visible';
				hmDropCount++;
				hmShowOrHideAllDropDowns(0);
			}
			else{
				hmHideCount++;
				hmToHide[hmHideCount] = obj.childNodes[i];
				if(hmHideDelay <= 0) hmHideDelay = 1;
				hmDropCount--;
				obj['outId'] = setTimeout('hmShowOrHideAllDropDowns('+hmHideCount+');', hmHideDelay);
			}
		}
	}
}
function hmShowOrHideAllDropDowns(direct){
	if(direct>0) hmToHide[direct].style.visibility = 'hidden';
	if(navigator.appName!='Microsoft Internet Explorer')return;
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1); // capture x.x portion and store as a number
		if (ieversion>=7) return;
	}
	if(hmDropCount>0) hmDropState = "hidden";
	else hmDropState = "visible";
	if(hmDropCount<2){
		var elements = document.documentElement.getElementsByTagName('select');
		for (var i=0; i<elements.length; i++) {
		    elements[i].style.visibility = hmDropState;
		}
	}
}
function hmIsAllow(el){
	if(el.tagName == 'UL'|| el.tagName == 'OL'){
		if(el.attributes){
			for(var i = 0; i < el.attributes.length; i++){
				if(el.attributes[i].nodeName == "hm-static") return false;
			}
		}
		return true;
	}
	return false;
}
function hmSetEvents(obj){
	if(!obj.childNodes) obj = document.getElementById(obj);
	if(hmIsAllow(obj)){
		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])){
						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;
}
function hmRun(){
	for(var i = 0; i < hmMenus.length; i++){
		if(!hmMenusDone[i]){
			hmMenusDone[i] = true;
			hmSetEvents(hmMenus[i]);
		}
	}
}
hmAddEvent(window, 'load', function(){
	hmRun();
});