//Get window width, THIS MUST BE WITHIN THE BODY TAG!
var winW, winH
function getWindowSize(){
	if (browser.isIE55 || browser.isIE6up) {	
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;	
	} else {
		winW = window.innerWidth;
		winH = window.innerHeight;
	}
}

function fncShowSub(div){
	var thisID, thisSub, thisTop, thisRight, thisOpen, thisSubWidth, thisSubRight
	//--set the MainID, if it's a sub, take that part out
	thisID = div.id;
	if (thisID.indexOf("_Sub") != -1){
		thisID = thisID.replace("_Sub", "");
	}
	
	//--vars
	thisSub 	= document.getElementById(thisID + "_Sub");
	thisTop 	= document.getElementById(thisID).offsetTop;
	thisLeft	= document.getElementById(thisID).offsetLeft;
	thisRight 	= document.getElementById(thisID + "_XY").offsetLeft + thisLeft;
	thisOpen 	= document.getElementById("MenuOpen").value;

	//--if A Sub is open and NOT this Sub, close it
	if(thisOpen != "" && thisOpen != thisSub){
		document.getElementById(thisOpen).style.visibility = "hidden";
		document.getElementById(thisOpen).style.left = 0;
	}
	
	//--if this Sub exists align it and make it visible
	if(thisSub){
		thisSubWidth = document.getElementById(thisID + "_Sub_XY").offsetLeft;
		thisSubRight = thisRight + thisSubWidth;
		
		//if the right side is greater then the screen size bring it it.
		if(thisSubRight > winW){
			thisRight = thisLeft - thisSubWidth - 20;
		}
		thisSub.style.top 	= thisTop;
		thisSub.style.left 	= thisRight + 10;
		thisSub.style.visibility = "visible";
		thisSub.style.display = "block";
	}		
	//--Turn of fncMenuClose
	document.getElementById("MenuOpen").value = "";
	document.getElementById("MenuClose").value = -1;		
}

function fncHideSub(div){
	var thisID, thisSub
	//set the MainID, if it's a sub, take that part out
	thisID = div.id;
	if(thisID.indexOf("_Sub") != -1){
		thisID = thisID.replace("_Sub", "");
	}
	//vars
	thisSub = document.getElementById(thisID + "_Sub");
	
	//if this Sub exists start the count down at 5
	if(thisSub){
		document.getElementById("MenuOpen").value = thisID + "_Sub";
		document.getElementById("MenuClose").value = 5;
	}
}

function fncMenuClose(){	
	var thisOpen, thisClose
	//The currently open MenuItem(thisOpen) and how much time it has left until closing(thisClose)
	thisOpen	= document.getElementById("MenuOpen").value;
	thisClose 	= document.getElementById("MenuClose").value;
	
	//if the timers set, start counting down
	if(thisClose >= 0){
		document.getElementById("MenuClose").value = thisClose - 1;
	} 
	//if the timer hit 0, close the currently open MenuItem(thisOpen) and empty thisOpen
	if(thisClose == 0 && thisOpen != ""){
		document.getElementById(thisOpen).style.visibility = "hidden";
		document.getElementById(thisOpen).style.left = 0;
		document.getElementById("MenuOpen").value = "";
	}
	//Counter: 100 is how faster it counts, make it bigger to count slower
	setTimeout("fncMenuClose()", 100);
}

