//menu stuff - Doremi

var toObj, curSubNavObj, defaultSubNavObj, animInterval;

var isIE = navigator.appVersion.indexOf("MSIE")>0


window.onload = initSubNav;


function initSubNav() {
	if (document.getElementById('submenucontainer') == null)
		return;
		
	for (i=0; i < document.getElementById('submenucontainer').childNodes.length; i++) {
		smObj = document.getElementById('submenucontainer').childNodes[i];
		
		if (smObj.attributes!=null && smObj.attributes.getNamedItem('defaultsubmenu').value == "1") {
			smObj.style.display = 'inline';
			smObj.style.top = 0;
			curSubNavObj = smObj;
			defaultSubNavObj = smObj;
		}
	}
	
	if (document.getElementById('submenu3container')) {
		smObj = document.getElementById('submenu3container');
		if (smObj.attributes!=null) {
			smObj.style.top = 0;
		}
	}
}



function hoverMainNav(sTag, isHover) {
	
	
	//curSubNavObj.style.display = 'none'; 
	
	
	//isHover = true onmouseover, false onmouseout
	mnObj = document.getElementById(sTag);
	if (mnObj == null) 
		return false;
			
	//main nav hover
	mnObj.src = eval("img_" + sTag + ((isHover)?"_hover":"") + ".src");			
			
	//submenu
	snObj = document.getElementById("sub" + sTag);
	
	if (isHover && snObj == curSubNavObj) {
		window.clearTimeout(toObj);
		return;
	}
	
	if (!isHover && snObj == defaultSubNavObj && curSubNavObj == defaultSubNavObj) {
		window.clearTimeout(toObj);
		return;
	}
	
	//hide previous, if still open
	if (isHover && curSubNavObj != null) {
		if (toObj != null)
			window.clearTimeout(toObj);
		if (animInterval != null)
			window.clearInterval(animInterval);
				
		if (snObj == null) //no new menu to display
			return hideSubNav(curSubNavObj.id.slice(3));					
		else
			curSubNavObj.style.display = 'none'; //hide immediately
	}
			
	if (snObj != null) {
		if (isHover) {
			showSubNav(sTag);
			curSubNavObj = snObj;
		} else {
			toObj = window.setTimeout("hideSubNav('" + sTag + "');",100);
		}
	}
			
}

function hoverSubNav(sTag, isHover) {
	snObj = document.getElementById("sub" + sTag);
	if (snObj == null)
		return false;
		
	if (isHover && snObj == curSubNavObj) {
		window.clearTimeout(toObj);
		return;
	}
	
	if (!isHover && snObj == defaultSubNavObj && curSubNavObj == defaultSubNavObj) {
		window.clearTimeout(toObj);
		return;
	}
			
	if (snObj == curSubNavObj) { //already visible
		if (isHover) {
			if (toObj != null)
				window.clearTimeout(toObj);
		} else {
			toObj = window.setTimeout("hideSubNav('" + sTag + "');",10);
		}
	} else {
		//should never happen, but just in case, hide.
		hideSubNav(sTag);
	}
}

function hoverSubNavImg(sTag, sTag2, isHover) {
	//alert("sub" + sTag);
	snObj = document.getElementById("sub" + sTag);
	if (snObj == null)
		return false;
		
	//sub nav hover
	//alert("img_" + sTag2 + ((isHover)?"_hover":"") + ".src");
	sniObj = document.getElementById(sTag2);
	if (sniObj)
		sniObj.src = eval("img_" + sTag2 + ((isHover)?"_hover":"") + ".src");
		
	if (isHover && snObj == curSubNavObj) {
		window.clearTimeout(toObj);
		return;
	}
	
	if (!isHover && snObj == defaultSubNavObj && curSubNavObj == defaultSubNavObj) {
		window.clearTimeout(toObj);
		return;
	}
			
	if (snObj == curSubNavObj) { //already visible
		if (isHover) {
			if (toObj != null)
				window.clearTimeout(toObj);
		} else {
			toObj = window.setTimeout("hideSubNav('" + sTag + "');",10);
		}
	} else {
		//should never happen, but just in case, hide.
		hideSubNav(sTag);
	}
}

function hoverSubNav3Img(sTag, sTag2, isHover) {
	//alert("sub" + sTag);
	//snObj = document.getElementById("sub" + sTag);
	//if (snObj == null)
	//	return false;
		
	//sub nav hover
	//alert("img_" + sTag2 + ((isHover)?"_hover":"") + ".src");
	sniObj = document.getElementById(sTag2);
	if (sniObj)
		sniObj.src = eval("img_" + sTag2 + ((isHover)?"_hover":"") + ".src");
}

function showSubNav(sTag) {
	snObj = document.getElementById("sub" + sTag);
	snObj.style.display = "inline";
	

	snObj.style.top = -15;
	if (animInterval != null) 
		window.clearInterval(animInterval);
	animInterval = window.setInterval("slideOutSubNav('" + sTag + "');",20);			
}

function slideOutSubNav(sTag) {			
	snObj = document.getElementById("sub" + sTag);
			
	if (snObj.offsetTop >= 0)
		window.clearInterval(animInterval);
	else
		snObj.style.top = snObj.offsetTop + 1;
}

function hideSubNav(sTag) {
	
	snObj = document.getElementById("sub" + sTag);
	snObj.style.top = 0;
	if (animInterval != null) {
		window.clearInterval(animInterval);
		
	}
	
	animInterval = window.setInterval("slideInSubNav('" + sTag + "');",1);
	curSubNavObj = null;
	
	
}

function slideInSubNav(sTag) {
	snObj = document.getElementById("sub" + sTag);
	if (snObj.offsetTop <= -15) {
		window.clearInterval(animInterval);
		snObj.style.display = "none";
		
		if (defaultSubNavObj != null) {
			curSubNavObj = defaultSubNavObj;
			showSubNav(defaultSubNavObj.id.slice(3));
		}
	}
	else
		snObj.style.top = snObj.offsetTop - 1;
}


