/* Simple menu. concept from http://javascript-array.com/scripts/simple_drop_down_menu/
								I entirely rewrote and added init()
								*/
var etMenu = {
	/* TWEAKABLES */
	menuId:"menu",
	dropdownClassName:"dropdown",
	timeout:100,
	/* INIT VARS */
	close_t:null,
	curMenuItem:null,
	initd:false,
	/* */
	init: function () {
		if(!etMenu.initd && document.getElementById && document.getElementById(etMenu.menuId)){
			var container = document.getElementById(etMenu.menuId);
			var as = container.getElementsByTagName('a');
			for(j in as){
				if (as[j] && as[j].nodeType && as[j].nodeType == 1 && as[j].parentNode.parentNode.id == etMenu.menuId){
					var keyId = "etMenuDropdown_"+j;
					as[j].id = keyId;
					var divs = as[j].parentNode.getElementsByTagName('div');
					var menuDiv = false;
					for(i in divs){
						if (divs[i] && divs[i].className && divs[i].className == etMenu.dropdownClassName){
								menuDiv = divs[i];
						}
					}
					if(menuDiv){
						menuDiv.id = keyId+"_d";
						document.getElementById(keyId+"_d").style.display = "none"
						if(menuDiv.addEventListener){
							as[j].addEventListener('mouseover', function(){etMenu.show(this.id);},false);
							as[j].addEventListener('mouseout', function(){etMenu.startCloseTimer();},false);
							menuDiv.addEventListener('mouseover', function(){etMenu.cancelCloseTimer();},false);
							menuDiv.addEventListener('mouseout', function(){etMenu.startCloseTimer();},false);
						} else {
							as[j].onmouseover = new Function('etMenu.show(this.id);');
							as[j].onmouseout = etMenu.startCloseTimer;
							menuDiv.onmouseover = etMenu.cancelCloseTimer;
							menuDiv.onmouseout = etMenu.startCloseTimer;
						}
					}
				}
			}
		etMenu.initd = true;
		}
	},
	//these functions rewritten from concept as above.
	show: function(id){
		if (id){
			etMenu.cancelCloseTimer();
			etMenu.hide('current');
			etMenu.curMenuItem = id;
			document.getElementById(id).className = "hovered";
			document.getElementById(id+"_d").style.display = "block";
		}
	},
	hide: function(id){
		if (id == "current"){
			id = etMenu.curMenuItem;
		}
		if (id){
			document.getElementById(id).className = "";
			document.getElementById(id+"_d").style.display = "none";
			etMenu.curMenuItem = null;
		}
	},
	startCloseTimer: function(){
		etMenu.close_t = window.setTimeout("etMenu.hide('current')", etMenu.timeout);
	},
	cancelCloseTimer: function(){
		if(etMenu.close_t) {
			window.clearTimeout(etMenu.close_t);
			etMenu.close_t = null;
		}
	}
}

/* from themaninblue, it works. :) */

function addLoadListener(fn){
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', fn, false);
	} else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	} else {
		return false;
	}
	return true;
};

function attachEventListener(target, eventType, functionRef, capture) {
    if (typeof target.addEventListener != "undefined") {
        target.addEventListener(eventType, functionRef, capture);
    } else if (typeof target.attachEvent != "undefined") {
        target.attachEvent("on" + eventType, functionRef);
    } else {
        return false;
    }
    return true;
};
addLoadListener(etMenu.init);
etMenu.init();
