var classHide = "hide";
var classShow = "show";
var hasSubMenus = "true";
var ulElement;


function rollOutMenu(ulId){
	var ulRoot = document.getElementById("navbar");
	if(ulRoot == null){
		ulRoot = document.getElementById("home_navbar");
	}
	var ulSelected = document.getElementById(ulId);
	
	for(var i=0; i<ulRoot.childNodes.length; i++){
		var node = ulRoot.childNodes[i];
		for(j=0; j<node.childNodes.length; j++){
			subnode = node.childNodes[j];
			if(subnode.tagName == "UL" && subnode != ulSelected){
				
				var cls = subnode.getAttribute("class");
				
				if(cls == classShow){
					subnode.setAttribute("class", classHide);
					subnode.setAttribute("className", classHide);
				}
			}
		}
	}
}

function bgHighChange(id, color){
	var changeEl = document.getElementById(id);
	if(changeEl != null){
		if(changeEl.style.setAttribute){
			changeEl.style.setAttribute("cssText", "background-color: "+color+";");
		}else{
			changeEl.setAttribute("style", "background-color: "+color+";");
			//divEl.setAttribute("style", "border-top: 1px solid #"+color+";");
		}
		
		changeEl.onmouseout = function(){
			if(changeEl.style.setAttribute){
				changeEl.style.setAttribute("cssText", "background-color: #8A8A8A;");
			}else{
				changeEl.setAttribute("style", "background-color: #8A8A8A;");
			}
		}
	}
}

function bgCalChange(id, color){
	var changeEl = document.getElementById(id);
	if(changeEl != null){
		if(changeEl.style.setAttribute){
			changeEl.style.setAttribute("cssText", "background-color: "+color+";");
		}else{
			changeEl.setAttribute("style", "background-color: "+color+";");
			//divEl.setAttribute("style", "border-top: 1px solid #"+color+";");
		}
		
		changeEl.onmouseout = function(){
			if(changeEl.style.setAttribute){
				changeEl.style.setAttribute("cssText", "background-color: #cbcbc9;");
			}else{
				changeEl.setAttribute("style", "background-color: #cbcbc9;");
			}
		}
	}
}

function bgChange(divid, color, bcolor){
	var divEl = document.getElementById(divid);
	var padding = "";
	if(divid == "m12"){
		padding = "padding-top: 10px; padding-bottom: 5px;";
	}
	if(divEl != null){
		if(divEl.style.setAttribute){
			divEl.style.setAttribute("cssText", "background-color: "+color+"; border-top: 1px solid #"+bcolor+"; "+padding+"");
		}else{
			divEl.setAttribute("style", "background-color: "+color+"; border-top: 1px solid #"+bcolor+"; "+padding+"");
			//divEl.setAttribute("style", "border-top: 1px solid #"+color+";");
		}
	}
	
	divEl.onmouseout = function(){
		//alert(bcolor);
		if(divEl != null){
			if(divEl.style.setAttribute){
				divEl.style.setAttribute("cssText", "border-top: 1px solid #"+bcolor+"; "+padding+"");
			}else{
				divEl.setAttribute("style", "border-top: 1px solid #"+bcolor+"; "+padding+"");
			}
		}
	}
	
	divEl.onclick = function(){
		if(ulElement != null){
			ulElement.setAttribute("class", classHide);
			ulElement.setAttribute("className", classHide);
		}
	}
}


function rollOver(linkid, rollImg, isHome){
	var elLink = document.getElementById(linkid);
	if(elLink != null){
		var changeImg = elLink.getElementsByTagName("img")[0];
		if(changeImg != null){
			var rollOutImg = changeImg.getAttribute("src");
			changeImg.setAttribute("src", rollImg);
		}
		
		/* search other open menu */
		/* submenus showing using tables */
		if(hasSubMenus){
			var ulId = "b"+linkid.substring(1, 4);	
			var ulElement = document.getElementById(ulId);
			rollOutMenu(ulId);
			if(ulElement != null){
				ulElement.setAttribute("class", classShow);
				/* IE compatibile scripts */
				ulElement.setAttribute("className", classShow);
			}
			
			if(ulElement != null){
				for(var i=0; i<ulElement.childNodes.length; i++){
					var node = ulElement.childNodes[i];
					if(node.tagName == "LI"){
						node.onmouseover = function(){
							ulElement.setAttribute("class", classShow);
							ulElement.setAttribute("className", classShow);
						}
						node.onmouseout = function(e){
							ulElement.setAttribute("class", classHide);
							ulElement.setAttribute("className", classHide);
						}
					}
				}
			}
			if(isHome == "home" && ulElement){
				var id = ulElement.getAttribute("id");
				var height = ulElement.offsetHeight+5;
				ulElement.style.top = '-'+height+'px'; 
			}
		}
	}

	
/*
	divElement.onmouseout = function(e){
		if(ulElement != null){
			alert(e.target);
			ulElement.setAttribute("class", classHide);
			
			ulElement.setAttribute("className", classHide);
		}
	}
*/
	elLink.onmouseout = function(e){
		if(changeImg != null)	{
			changeImg.setAttribute("src", rollOutImg);
		}
	}
	
	elLink.onclick = function(){
		if(ulElement != null){
			ulElement.setAttribute("class", classHide);
			/* IE compatibile scripts */
			ulElement.setAttribute("className", classHide);
		}
	}
}
