var currentSubmenu = null;
var closeSubmenuTimer = null;
var currentLeftSubmenu = null;

function setSubmenu(){
	for(var i = 0; (obj = document.getElementById("globalmenu").getElementsByTagName("a")[i]); i ++){
		if(obj.parentNode.getElementsByTagName("div")[0]){
			obj.onmouseover = function(){
				closeSubmenu();
				var j = 0;
				while(! currentSubmenu){
					var childObj = this.parentNode.childNodes[j];
					if(childObj.tagName == "DIV" || childObj.tagName == "div"){
						currentSubmenu = childObj;
						currentSubmenu.style.visibility = "visible";
						cancelCloseSubmenu();
					}else{
						j ++;
					}
				}
			}
			obj.onmouseout = function(){ closeSubmenuTime(); }
			for(j = 0; (childObj = obj.parentNode.childNodes[j]); j ++){
				if(childObj.tagName == "DIV" || childObj.tagName == "div"){
					childObj.onmouseover = function(){ cancelCloseSubmenu(); }
					childObj.onmouseout = function(){ closeSubmenuTime(); }
				}
			}
		}
	}
}
function cancelCloseSubmenu(){
	if(closeSubmenuTimer){
		window.clearTimeout(closeSubmenuTimer);
		closeSubmenuTimer = null;
	}
}
function closeSubmenuTime(){
  closeSubmenuTimer = window.setTimeout(closeSubmenu, 300);
}
function closeSubmenu(){
	if(currentSubmenu){
		currentSubmenu.style.visibility = "hidden";
		currentSubmenu = null;
	}
}
function setLeftSubmenu(){
	for(var i = 0; (obj = document.getElementById("left").getElementsByTagName("dt")[i].firstChild); i ++){
		obj.onclick = function(){
			var submenu = document.getElementById("leftmenu-" + this.id.split("-")[1]);
			if(currentLeftSubmenu){
				currentLeftSubmenu.style.display = "none";
				var parentmenu = document.getElementById("for-" + currentLeftSubmenu.id.split("-")[1]);
				if(parentmenu.getAttribute("class") == "bottom" || parentmenu.getAttribute("className") == "bottom") parentmenu.style.backgroundPosition = "0 -60px";
			}
			if(submenu == currentLeftSubmenu){
				currentLeftSubmenu = null;
			}else{
				currentLeftSubmenu = submenu;
				currentLeftSubmenu.style.display = "block";
				if(this.getAttribute("class") == "bottom" || this.getAttribute("className") == "bottom") this.style.backgroundPosition = "0 -30px";
			}
			return false;
		}
	}
}
function setNewWin(){
	for(var i = 0; (obj = document.getElementsByTagName("a")[i]); i ++){
		if(obj.getAttribute("class") == "newwin" || obj.getAttribute("className") == "newwin") obj.target = "_blank";
	}
}
