/*DynaMenu v1.0.  Programmed by Toan T. Thai, (C) 2007, www.tawarnolds.com. This entire script is developed for commercial use only.
BEGIN of customizable parameters
this.HilightMode ? none=nothing/BGOnly=only set bg pic and color if any
*/
FilterMode = ""; Positioning = "absolute"; mHeight = ""; mWidth = ""; initOpacity = 80; initPrimeOpacity = 70;
divBGColor = ""; BGHiLiColor = "#ffeeaa"; FGHiLiColor = "#dd7700" //BGPic = "../graphics/mbuttonreg.jpg" ; BGHiLiImage = "../graphics/mbuttonhili.jpg";

//var BGPic = new Image(); BGPic.src = "../graphics/mbuttonreg.jpg";
var BGHiLiImage = new Image(); BGHiLiImage.src = "../graphics/mbuttonhili.jpg"; //set to "none" for no use
var tempImgHolder = new Image(); tempBGColorHolder = "";  tempFGColorHolder = "";

MenuBGColor = "#bbbbbb"; MenuBorderColor = "#BBBBBB"; MenuBorderStyle = "solid"; MenuBorderWidth = 1;
var SubMenuBGColor = ""; var SubMenuBorderColor = "#ff9900"; var SubMenuBorderStyle = "solid"; var SubMenuBorderWidth = 1;

BetweenPad = document.createElement("br"); //may not be changed
//END of customizable items

/*function getHiliDiv() {
	var HiliDiv = document.createElement("div"); HiliDiv.style.backgroundImage = "url(" + BGHiLiImage.src + ")";
	HiliDiv.style.position = "absolute"; HiliDiv.style.top = "0px"; HiliDiv.style.left = "0px"; HiliDiv.id = "HiliDiv"; HiliDiv.style.width = "100%"; HiliDiv.style.height = "100%"; HiliDiv.style.zIndex = 0;
	HiliDiv.style.visibility = "hidden"; HiliDiv.style.display = "none"
	return HiliDiv;
}
var HiliDiv = getHiliDiv();
*/
//Scan for valid menu data
var ALLDivs = document.getElementsByTagName("div");
for (i=0; i<ALLDivs.length; i++) {
	if (ALLDivs[i].getAttribute("menuContainer") == "true") {
		if (ALLDivs[i].getElementsByTagName("div")[0].id && ALLDivs[i].id) {
			if (ALLDivs[i].getAttribute("MenuBorderWidth")) {MenuBorderWidth = parseInt(ALLDivs[i].getAttribute("MenuBorderWidth"))}
			if (ALLDivs[i].getAttribute("SubMenuBorderWidth")) {SubMenuBorderWidth = parseInt(ALLDivs[i].getAttribute("SubMenuBorderWidth"))}
			if (ALLDivs[i].getAttribute("MenuBorderColor")) {MenuBorderColor = ALLDivs[i].getAttribute("MenuBorderColor")}
			if (ALLDivs[i].getAttribute("MenuBGColor")) {MenuBGColor = ALLDivs[i].getAttribute("MenuBGColor")}
			if (ALLDivs[i].getAttribute("SubMenuBorderColor")) {SubMenuBorderColor = ALLDivs[i].getAttribute("SubMenuBorderColor")}
			if (ALLDivs[i].getAttribute("SubMenuBGColor")) {SubMenuBGColor = ALLDivs[i].getAttribute("SubMenuBGColor")}
			if (ALLDivs[i].getAttribute("BGHiLiColor")) {BGHiLiColor = ALLDivs[i].getAttribute("BGHiLiColor")}
			if (ALLDivs[i].getAttribute("FGHiLiColor")) {FGHiLiColor = ALLDivs[i].getAttribute("FGHiLiColor")}
			if (ALLDivs[i].getAttribute("divBGColor")) {divBGColor = ALLDivs[i].getAttribute("divBGColor")}
			if (ALLDivs[i].getAttribute("BGHiLiImage"))
				{MenuBGColor = ALLDivs[i].getAttribute("BGHiLiImage"); var BGHiLiImage = new Image(); BGHiLiImage.src = ALLDivs[i].getAttribute("BGHiLiImage");}
			if (ALLDivs[i].getAttribute("initOpacity")) {initOpacity = ALLDivs[i].getAttribute("initOpacity")}
			if (ALLDivs[i].getAttribute("initPrimeOpacity")) {initPrimeOpacity = ALLDivs[i].getAttribute("initPrimeOpacity")}
			BuildPrimaryButtons(ALLDivs[i].getElementsByTagName("div")[0].id, ALLDivs[i].id) //gret the sub container, *data
		} else { alert("You must properly name the container DIV and data DIV blocks."); }
	}
}
ALLDivs = null;

var State1On = false; State2On = false; ButtonOnChecked = false;
document.onmouseover = function() {
if (State1On == false) {HideSubMenu(1, "");}
if (State2On == false) {HideSubMenu(2, "");}
}

function BuildPrimaryButtons(divMenuData, divMenu) {
	var divMenuWidth = 0; tempLeft = 0; tmpTop = 0; nDiv = -1;
	document.getElementById(divMenu).initLeft = parseInt(document.getElementById(divMenu).style.left);
	document.getElementById(divMenu).initTop = parseInt(document.getElementById(divMenu).style.top);
	document.getElementById(divMenuData).style.visibility = "hidden"; document.getElementById(divMenuData).style.display = "none";
	var AllDivs = document.getElementById(divMenuData).getElementsByTagName("div");
	for (var n=0; n<AllDivs.length; n++) {
		if (AllDivs[n].getAttribute("Parent") == "none") { nDiv += 1;
			var tempDiv = AllDivs[n].cloneNode(true); tempDiv.originalID = tempDiv.id; tempDiv.id = divMenu + "td" + nDiv; tempDiv.cousinDiv = divMenu + "divSecond" + nDiv; tempDiv.menuElement = "true";
			if (tempDiv.getAttribute("HilightMode") !== "none") {
				if (divBGColor !== "" && tempDiv.style.backgroundColor == "") {tempDiv.style.backgroundColor = divBGColor;}
				//if (BGPic.src !== "" && tempDiv.getElementsByTagName("img")[0]) { tempDiv.getElementsByTagName("img")[0].src = BGPic.src; }
				setOpacity(initPrimeOpacity, tempDiv);
			}
			if (tempDiv.getElementsByTagName("img")[0]) tempDiv.getElementsByTagName("img")[0].style.border = "0px";
			if (mWidth !== "") {tempDiv.style.width = mWidth + "px";}
			if (mHeight !== "") {tempDiv.style.height = mHeight + "px";}
			tempDiv.style.borderStyle = MenuBorderStyle; tempDiv.style.borderWidth = MenuBorderWidth + "px"; tempDiv.style.borderColor = MenuBorderColor;
			tempDiv.style.position = Positioning; //tempDiv.style.cursor = "pointer";

			if (document.getElementById(divMenu).getAttribute('LayoutDirection') == "Horizontal") {
				tempDiv.style.top = "0px";
				tempDiv.style.left = tempLeft + "px"; tempLeft += parseInt(tempDiv.style.width) + parseInt(Number(ieVersion()) >= 5 ? 0 : MenuBorderWidth*2);
				divMenuWidth += parseInt(tempDiv.style.width);
			} else {
				tempDiv.style.top = tmpTop + "px"; tmpTop += parseInt(tempDiv.style.height) + parseInt(Number(ieVersion()) >= 5 ? 0 : MenuBorderWidth*2);
				tempDiv.style.left = "0px";
				if (parseInt(tempDiv.style.width) > divMenuWidth) {divMenuWidth = parseInt(tempDiv.style.width);}
			}
			document.getElementById(divMenu).style.width = divMenuWidth + "px"; //tempDiv.style.overflow = "visible";
			tempDiv.onmouseover = MouseOverPrime; tempDiv.onmouseout = MouseOutPrime;
			tempDiv.divMenuData = divMenuData; tempDiv.divMenu = divMenu;
			document.getElementById(divMenu).appendChild(tempDiv);
			BuildSecondDivs(nDiv, tempDiv);
		}
	}
	//document.getElementById(divMenuData).innerHTML = ""; //clear template divs, it somehow slows down loading if not
	document.getElementById(divMenuData).parentNode.removeChild(document.getElementById(divMenuData));
}
window.onscroll = RelocateMenu;

function ieVersion() { // Returns the version of Internet Explorer or a -1 (indicating the use of another browser).
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function getScrollX() { return parseInt(document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) }
function getScrollY() { return parseInt(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) }

function HideSubMenu(Type, DivIDon) {
	if (Type == 1) {
		var Divs = document.getElementsByTagName("div")
		for (var i=0; i<Divs.length; i++) {
			if (Divs[i].id.match(/divSecond/ig)) {
				if (Divs[i].id == DivIDon) {setOpacity(0, Divs[i]); Divs[i].style.visibility = "visible"; Divs[i].style.display = ""; aniOpacity(Divs[i].id, 0, 100, 6);} else {Divs[i].style.visibility = "hidden"; Divs[i].style.display = "none"}
			}
		}
	} else if (Type == 2) {
		var Divs = document.getElementsByTagName("div")
		for (var i=0; i<Divs.length; i++) {
			if (Divs[i].id.match(/divThird/ig)) {
				if (Divs[i].id == DivIDon) {setOpacity(0, Divs[i]); Divs[i].style.visibility = "visible"; Divs[i].style.display = ""; aniOpacity(Divs[i].id, 0, 100, 6);} else {Divs[i].style.visibility = "hidden"; Divs[i].style.display = "none"}
			}
		}
	}
}
function RelocateMenu(initCall) {
	var Divs = document.getElementsByTagName("div")
	for (var i=0; i<Divs.length; i++) {
		if (Divs[i].getAttribute("menuContainer") == "true" && Divs[i].getAttribute("attachToScreen") == "true") {
			initLeft = Divs[i].initLeft; initTop = Divs[i].initTop;
			Divs[i].style.top = document.documentElement.scrollTop + initTop + "px"; Divs[i].style.left = document.documentElement.scrollLeft + initLeft + "px";
		}
	}
	//alert(document.getElementById("spanMenu").offsetWidth + "|" + document.getElementById("spanMenu").offsetHeight);
	//alert(document.body.clientHeight + "|" + screen.height + "|" + document.documentElement.scrollHeight + "|" + document.documentElement.scrollTop);
}
function Left(str, n){
	if (n <= 0) return "";
	else if (n > String(str).length) return str;
	else return String(str).substring(0,n);
}
function Right(str, n){
	if (n <= 0) return "";
	else if (n > String(str).length) return str;
	else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); }
}
function getOuterHTML(obj){
	var tempDiv = document.createElement("div");
	var tempE = obj.cloneNode(true); tempDiv.appendChild(tempE);
	return tempDiv.innerHTML;
}
function findparentDivID(Obj) {
	var tableObj = Obj.parentNode; 
	while(tableObj.tagName.toLowerCase() !== "table") {
		tableObj = tableObj.parentNode;
	}
}
function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
		return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft :document.body.scrollLeft);
	else return null;
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
		return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	else return null;
}
function setOpacity(oN, obj) {
	obj.style.opacity = (oN / 100);
	obj.style.MozOpacity = (oN / 100);
	obj.style.KhtmlOpacity = (oN / 100);
	obj.style.filter = "alpha(opacity=" + oN + ")";
}
function setOpacityByID(oN, objID) {
	if (document.getElementById(objID)) {
		var obj = document.getElementById(objID);
		obj.style.opacity = (oN / 100);
		obj.style.MozOpacity = (oN / 100);
		obj.style.KhtmlOpacity = (oN / 100);
		obj.style.filter = "alpha(opacity=" + oN + ")";
	}
}
function aniOpacity(objID, nStart, nEnd, ms) {
try {
	if (document.getElementById(objID)) {
		if (document.getElementById(objID).style.opacity == 1 || document.getElementById(objID).style.MozOpacity == 1 || document.getElementById(objID).style.KhtmlOpacity == 1 || document.getElementById(objID).style.filter == "alpha(opacity=100)") {clearTimeOut(myTimeOut); return;}
		var speed = ms; var delayer = 0;
		if (nStart > nEnd) {
			for(i = nStart; i >= nEnd; i--) {
				myTimeOut = setTimeout("setOpacityByID(" + i + ",'" + objID + "')",(delayer * speed));
				delayer++;
			}
		} else if (nStart < nEnd) {
			for(i = nStart; i <= nEnd; i++) {
				myTimeOut = setTimeout("setOpacityByID(" + i + ",'" + objID + "')",(delayer * speed));
				delayer++;
			}
		}
	} else {if (myTimeOut) clearTimeOut(myTimeOut);}
} catch (err) {}
}
function BuildSecondDivs(PrimeID, PrimeButton) {
	var AllDivs2 = document.getElementById(PrimeButton.divMenuData).getElementsByTagName("div");
	var PrimeButtons = new Array(); SecondButtons = new Array(); pa = -1; pc = -1;
	for (var p1=0; p1<AllDivs2.length; p1++) { if (AllDivs2[p1].getAttribute("Parent") == "none") {pa += 1; PrimeButtons[pa] = AllDivs2[p1];} }
	for (var p2=0; p2<AllDivs2.length; p2++) { if (AllDivs2[p2].getAttribute("Parent") == PrimeButton.originalID) {pc += 1; SecondButtons[pc] = AllDivs2[p2];} }
	var objDivSecond = document.createElement("div"); objDivSecond.id = PrimeButton.divMenu + "divSecond" + PrimeID; objDivSecond.menuElement = "true"
	objDivSecond.style.position = Positioning; objDivSecond.style.backgroundColor = SubMenuBGColor;
	tempHeight = 0; tempWidth = 0; tempBorders = 0; tempTop = 0; var tempLeft = 0; ParallelVBorders = 0; ParallelHBorders = 0;
	if (PrimeButton.style.borderWidth && Number(ieVersion()) < 5) ParallelVBorders = parseInt(PrimeButton.style.borderRightWidth) + parseInt(PrimeButton.style.borderLeftWidth)
	if (PrimeButton.style.borderWidth && Number(ieVersion()) < 5) ParallelHBorders = parseInt(PrimeButton.style.borderTopWidth) + parseInt(PrimeButton.style.borderBottomWidth)

	/*for (var i=0; i<SecondButtons.length; i++) {
		if (SecondButtons[i].style.borderTopWidth.indexOf("px") > 0) tempBorders += parseInt(SecondButtons[i].style.borderTopWidth);
		if (SecondButtons[i].style.borderBottomWidth.indexOf("px") > 0) tempBorders += parseInt(SecondButtons[i].style.borderBottomWidth);
	}*/
	for (var i=0; i<SecondButtons.length; i++) {
		if (SecondButtons[i].style.borderTopWidth) tempBorders += parseInt(SecondButtons[i].style.borderTopWidth); //retireve all top and bottom borders' width
		if (SecondButtons[i].style.borderBottomWidth) tempBorders += parseInt(SecondButtons[i].style.borderBottomWidth);
		//alert(SecondButtons[i].style.borderBottomWidth + "|" + SecondButtons[i].style.borderTopWidth + "=" + tempBorders);
		tempHeight += parseInt(SecondButtons[i].style.height);
		if (tempWidth < parseInt(SecondButtons[i].style.width)) tempWidth = parseInt(SecondButtons[i].style.width)
}
	if (PrimeButton.getAttribute("submenuMaxHeight")) {
		if (tempHeight + tempBorders < parseInt(PrimeButton.getAttribute("submenuMaxHeight"))) objDivSecond.style.height = tempHeight + tempBorders + "px";
		else objDivSecond.style.height = parseInt(PrimeButton.getAttribute("submenuMaxHeight")) + "px";
	} else {
	if (tempHeight + tempBorders < (document.body.clientHeight - 20)) { objDivSecond.style.height = tempHeight + parseInt(Number(ieVersion()) >= 5 ? 0:tempBorders) + "px"; }
		else {objDivSecond.style.height = (document.body.clientHeight - parseInt(PrimeButton.style.top) - 20) + "px";}
	}
	objDivSecond.style.width = tempWidth + "px";
//dynamic positioning block
	if (document.getElementById(PrimeButton.divMenu).getAttribute('LayoutDirection') == "Horizontal") {
		objDivSecond.style.top = tempTop + parseInt(PrimeButton.style.height) + ParallelHBorders + "px";
		for (var i=0; i<PrimeID; i++) { tempLeft += parseInt(PrimeButtons[i].style.width) + parseInt(Number(ieVersion()) >= 5 ? 0:MenuBorderWidth*2); }
		if (PrimeID < PrimeButtons.length-1) {objDivSecond.style.left = tempLeft + "px";
		} else {//last prime button's secondiv must remain within main boundaries
			if (document.getElementById(PrimeButton.divMenu).getAttribute('AdjustLastElement') !== "false") objDivSecond.lastPrime = "true";
			if (parseInt(objDivSecond.style.width) > parseInt(PrimeButton.style.width) && document.getElementById(PrimeButton.divMenu).getAttribute('AdjustLastElement') !== "false")
				{objDivSecond.style.left = tempLeft - (parseInt(objDivSecond.style.width) - parseInt(PrimeButton.style.width)) - (2*(SubMenuBorderWidth - MenuBorderWidth)) + "px";}
			else {objDivSecond.style.left = tempLeft + "px";}
		}
	} else {
	    for (var i = 0; i < PrimeID; i++) { tempTop += parseInt(PrimeButtons[i].style.height) + parseInt(Number(ieVersion()) >= 5 ? 0 : MenuBorderWidth * 2); }
		objDivSecond.style.top = tempTop + "px";
		if (document.getElementById(PrimeButton.divMenu).getAttribute("attachToScreen") == "true") {
			tempTop += getScrollY(); objDivSecond.style.left = tempLeft + parseInt(PrimeButton.style.width) + "px";
		} else {}//objDivSecond.style.left = parseInt(PrimeButton.style.width) + parseInt(document.getElementById(this.divMenu).style.left) + "px";}
	}
	if (document.getElementById(PrimeButton.divMenu).getAttribute('FlyOutDirection') == "Up") {
		if (document.getElementById(PrimeButton.divMenu).getAttribute('LayoutDirection') == "Horizontal") {
			if (document.getElementById(PrimeButton.divMenu).getAttribute("attachToScreen") == "true") {
				objDivSecond.style.top = -(tempHeight + tempBorders + SubMenuBorderWidth*2) + "px";
			} else {objDivSecond.style.top = -(tempHeight + tempBorders) + "px";}
		} else {//Vertical
			objDivSecond.style.top = (tempTop - parseInt(objDivSecond.style.height)) + parseInt(PrimeButton.style.height) - getScrollY() + ParallelHBorders - (SubMenuBorderWidth*2) + "px";//document.documentElement.scrollTop
			objDivSecond.style.left = parseInt(PrimeButton.style.width) + ParallelVBorders + "px";
		}
	} else {//Down
		if (document.getElementById(PrimeButton.divMenu).getAttribute('LayoutDirection') == "Horizontal") {
			if (document.getElementById(PrimeButton.divMenu).getAttribute("attachToScreen") == "true") {
				//NONE
			} else {objDivSecond.style.top = tempTop + parseInt(PrimeButton.style.height) + ParallelHBorders + "px";}
		} else { //Vertical
			if (document.getElementById(PrimeButton.divMenu).getAttribute("attachToScreen") == "true") {
				objDivSecond.style.top = tempTop - getScrollY() + "px";objDivSecond.style.left = parseInt(PrimeButton.style.width) + ParallelVBorders + "px";
			} else {objDivSecond.style.left = parseInt(PrimeButton.style.width) + ParallelVBorders + "px";}
		}
	}
	//get second div X offset, to achieve tab-like horizontal style menu
	if (PrimeButton.getAttribute("submenuXOffset")) objDivSecond.style.left =parseInt(objDivSecond.style.left) + parseInt(PrimeButton.getAttribute("parentDivXOffset")) + "px";

	//end of dynamic positioning block
	objDivSecond.style.borderStyle = SubMenuBorderStyle; //objDivSecond.style.backgroundColor = "#555555"; //objDivSecond.style.cursor = "pointer";
	objDivSecond.style.borderWidth = SubMenuBorderWidth + "px"; objDivSecond.style.borderColor = SubMenuBorderColor;
	objDivSecond.onmouseout = divSecondOut; objDivSecond.onmouseover = divSecondOver; objDivSecond.style.zIndex = 3000;
	objDivSecond.style.visibility = "visible"; objDivSecond.style.display = ""; setOpacity(0, objDivSecond);
	if (PrimeButton.getAttribute("submenuOverFlow")) { objDivSecond.style.overflow = PrimeButton.getAttribute("submenuOverFlow"); } else { objDivSecond.style.overflow = "visible"; }

	if (SecondButtons.length > 0) {document.getElementById(PrimeButton.divMenu).appendChild(objDivSecond);}
	for (var i2=0; i2<SecondButtons.length; i2++) { //second buttons
		var tempDiv = SecondButtons[i2].cloneNode(true); //secondary buttons, retrieve the first div in each cell
		tempDiv.originalID = tempDiv.id; tempDiv.id = PrimeButton.divMenu + "subtd" + PrimeID + "x"+ i2; tempDiv.cousinDiv = PrimeButton.divMenu + "divThird" + PrimeID + "x" + i2;
		if (tempDiv.getAttribute("HilightMode") !== "none") {
			if (divBGColor !== "" && tempDiv.style.backgroundColor == "") {tempDiv.style.backgroundColor = divBGColor;}
			//if (BGPic !== "" && tempDiv.style.backgroundImage == "") {tempDiv.style.backgroundImage = "url(" + BGPic.src + ")";}
			setOpacity(initOpacity, tempDiv);
		}
		if (tempDiv.getElementsByTagName("img")[0]) tempDiv.getElementsByTagName("img")[0].style.border = "0px";
		tempDiv.style.position = "relative";
		tempDiv.onmouseover = MouseOverSecond; tempDiv.onmouseout = MouseOutSecond;
		tempDiv.divMenuData = PrimeButton.divMenuData; tempDiv.divMenu = PrimeButton.divMenu;
		objDivSecond.appendChild(tempDiv);
		//if (i < TBCols.length-1) objDivSecond.appendChild(BetweenPad);
		BuildThirdDivs(PrimeID, i2, tempDiv);
	}
}
function BuildThirdDivs(PrimeID, SecondID, SecondButton) {
    var AllDivs3 = document.getElementById(SecondButton.divMenuData).getElementsByTagName("div");
	ThirdButtons3 = new Array(); pt = -1;
	for (var p=0; p<AllDivs3.length; p++) { if (AllDivs3[p].getAttribute("Parent") == SecondButton.originalID) {pt += 1; ThirdButtons3[pt] = AllDivs3[p];} }
	if (ThirdButtons3.length <= 0) return;
	var objDivThird = document.createElement("div"); objDivThird.originalID = objDivThird.id; objDivThird.id = SecondButton.divMenu + "divThird" + PrimeID + "x" + SecondID; tempBorders = 0;
	objDivThird.style.position = Positioning; objDivThird.style.backgroundColor = SubMenuBGColor;
	if (Number(ieVersion()) >= 5) { } else {
	    for (var i=1; i<SecondID; i++) {
		    if (SecondButtons[i].style.borderTopWidth) tempBorders += parseInt(SecondButtons[i].style.borderTopWidth)
		    if (SecondButtons[i].style.borderBottomWidth) tempBorders += parseInt(SecondButtons[i].style.borderBottomWidth);
	}}
	tempDivSecondID = SecondButton.parentNode.id;
	var tempTop = parseInt(document.getElementById(tempDivSecondID).style.top);
	if (document.getElementById(tempDivSecondID).getElementsByTagName("div").length > 1) {
		for (var n=0; n<SecondID; n++) { tempTop += parseInt(document.getElementById(tempDivSecondID).getElementsByTagName("div")[n].style.height); }
	}
	var tempHeight = 0; tempWidth = 0;
	for (var i=0; i<ThirdButtons3.length; i++) {
		if (ThirdButtons3[i]) {
			tempHeight += parseInt(ThirdButtons3[i].style.height);
			if (tempWidth < parseInt(ThirdButtons3[i].style.width)) tempWidth = parseInt(ThirdButtons3[i].style.width)
	}}
	objDivThird.style.height = tempHeight + "px"; objDivThird.style.width = tempWidth + "px";
	objDivThird.style.top = parseInt(tempTop) + parseInt(tempBorders) + (Number(ieVersion()) >= 5 ? 0 : parseInt(SubMenuBorderWidth)) + "px"; //objDivThird.style.cursor = "pointer";
	var tempVBorders = 0;
	if (SecondButton.style.borderWidth) tempVBorders = parseInt(SecondButton.style.borderRightWidth) + parseInt(SecondButton.style.borderLeftWidth)
	if (document.getElementById(tempDivSecondID).lastPrime == "true") {objDivThird.style.left = parseInt(document.getElementById(tempDivSecondID).style.left) - (tempWidth + tempVBorders + SubMenuBorderWidth) + "px";
	} else {objDivThird.style.left = parseInt(document.getElementById(tempDivSecondID).style.left) + parseInt(SecondButton.style.width) + tempVBorders + SubMenuBorderWidth + "px";}
	if (SecondButton.style.left) {objDivThird.style.left = parseInt(objDivThird.style.left) + parseInt(SecondButton.style.left) + "px";}//on for offsetting left or right

	objDivThird.style.borderStyle = SubMenuBorderStyle; objDivThird.style.borderWidth = SubMenuBorderWidth + "px"; objDivThird.style.borderColor = SubMenuBorderColor;
	objDivThird.onmouseout = divThirdOut; objDivThird.onmouseover = divThirdOver; objDivThird.style.zIndex = 3000;
	setOpacity(0, objDivThird);
	if (SecondButton.getAttribute("submenuOverFlow")) objDivThird.style.overflow = SecondButton.getAttribute("submenuOverFlow");
	else objDivThird.style.overflow = "visible";
	document.getElementById(SecondButton.divMenu).appendChild(objDivThird);

	var divThirdHeight = 0;
	if (ThirdButtons3.length > 0) { //third buttons
		for (var i3=0; i3<ThirdButtons3.length; i3++) {
			var tempDiv = ThirdButtons3[i3].cloneNode(true); tempDiv.id = SecondButton.divMenu + "subtd" + PrimeID + "x" + SecondID + "x" + i3;
			if (tempDiv.getAttribute("HilightMode") !== "none") {
				if (divBGColor !== "" && tempDiv.style.backgroundColor == "") {tempDiv.style.backgroundColor = divBGColor;}
				//if (BGPic !== "" && tempDiv.style.backgroundImage == "") {tempDiv.style.backgroundImage = "url(" + BGPic + ")";}
				setOpacity(initOpacity, tempDiv);
			}
			if (tempDiv.getElementsByTagName("img")[0]) tempDiv.getElementsByTagName("img")[0].style.border = "0px";
			tempDiv.style.position = "relative"; //tempDiv.style.top = mouseY(event);
			tempDiv.onmouseover = MouseOverThird; tempDiv.onmouseout = MouseOutThird;
			tempDiv.divMenuData = SecondButton.divMenuData; tempDiv.divMenu = SecondButton.divMenu;
			divThirdHeight += parseInt(tempDiv.style.height);
			objDivThird.appendChild(tempDiv);
			//if (i < TBColDivs.length-1) {objDivThird.appendChild(BetweenPad)}; //no break at the lat item
	}}
	objDivThird.style.height = divThirdHeight + "px";
}
function divSecondOut() {State1On = false; State2On = false;}
function divSecondOver() {State1On = true; State2On = true;}

function divThirdOut() {State1On = false; State2On = false}
function divThirdOver() {State1On = true; State2On = true}

function MouseOverPrime() {
	HideSubMenu(1, this.cousinDiv); HideSubMenu(2, "nonsense");
	State1On = true;
	//set prime button border OFF
	var allDivs = document.getElementById(this.divMenu).getElementsByTagName("div")
	//var PrimeButtons = new Array(); pa = -1;
	for (var p=0; p<allDivs.length; p++) { if (allDivs[p].getAttribute("Parent") == "none") allDivs[p].style.borderColor = document.getElementById(this.divMenu).getAttribute("MenuBorderColor"); } //{pa += 1; PrimeButtons[pa] = allDivs[p];} }
	//for (var n=0; n<allDivs.length; n++) {
	//	for (var n2=0; n2<PrimeButtons.length; n2++) { if (allDivs[n].id == this.divMenu + "td" + n2) {allDivs[n].style.borderColor = MenuBorderColor;} }
	//}
	if (this.getAttribute("HilightMode") !== "none") {
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiColor") !== "") 
			{tempBGColorHolder = this.style.backgroundColor; this.style.backgroundColor = document.getElementById(this.divMenu).BGHiLiColor;}
		if (document.getElementById(this.divMenu).getAttribute("FGHiLiColor") !== "") {tempFGColorHolder = this.style.color; this.style.color = document.getElementById(this.divMenu).getAttribute("FGHiLiColor");}
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiImage") !== "none" && this.getElementsByTagName("img")[0]) {
			if (this.getElementsByTagName("img")[0].getAttribute("rollOver") == "true") {
				tempImgHolder.src = this.getElementsByTagName("img")[0].src; this.getElementsByTagName("img")[0].src = document.getElementById(this.divMenu).getAttribute("BGHiLiImage");}
		}
		aniOpacity(this.id, initPrimeOpacity, 100, 6); //setOpacity(100, this);
		if (document.getElementById(this.divMenu).getAttribute("SubMenuBorderColor") !== "") {this.style.borderColor = document.getElementById(this.divMenu).getAttribute("SubMenuBorderColor");}
	}
}

function MouseOutPrime() {
	State1On = false; 
	if (this.getAttribute("HilightMode") !== "none") {
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiColor") !== "") this.style.backgroundColor = tempBGColorHolder;
		if (document.getElementById(this.divMenu).getAttribute("FGHiLiColor") !== "") this.style.color = tempFGColorHolder;
		if (this.getElementsByTagName("img")[0]) {
			if (this.getElementsByTagName("img")[0].getAttribute("rollOver") == "true") this.getElementsByTagName("img")[0].src = tempImgHolder.src;
		}
	setOpacity(initPrimeOpacity, this);
	}
}

function MouseOverSecond() {
	HideSubMenu(2, this.cousinDiv); State1On = true; State2On = true;
	if (this.getAttribute("HilightMode") !== "none") {
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiColor") !== "")
			{tempBGColorHolder = this.style.backgroundColor; this.style.backgroundColor = document.getElementById(this.divMenu).getAttribute("BGHiLiColor");}
		if (document.getElementById(this.divMenu).getAttribute("FGHiLiColor") !== "") {tempFGColorHolder = this.style.color; this.style.color = document.getElementById(this.divMenu).getAttribute("FGHiLiColor");}
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiImage") !== "none" && this.getElementsByTagName("img")[0]) {
			if (this.getElementsByTagName("img")[0].getAttribute("rollOver") == "true") {
				tempImgHolder.src = this.getElementsByTagName("img")[0].src; this.getElementsByTagName("img")[0].src = document.getElementById(this.divMenu).getAttribute("BGHiLiImage");}
		}
		aniOpacity(this.id, initOpacity, 100, 6);  //setOpacity(100, this);
	}
}
function MouseOutSecond() {
	State1On = false;
	if (this.getAttribute("HilightMode") !== "none") {
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiColor") !== "") this.style.backgroundColor = tempBGColorHolder;
		if (document.getElementById(this.divMenu).getAttribute("FGHiLiColor") !== "") this.style.color = tempFGColorHolder;
		if (this.getElementsByTagName("img")[0]) {
			if (this.getElementsByTagName("img")[0].getAttribute("rollOver") == "true") this.getElementsByTagName("img")[0].src = tempImgHolder.src;
		}
		setOpacity(initOpacity, this);
	}
}

function MouseOverThird() {
	if (this.getAttribute("HilightMode") !== "none") {
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiColor") !== "") {tempBGColorHolder = this.style.backgroundColor; this.style.backgroundColor = document.getElementById(this.divMenu).getAttribute("BGHiLiColor");}
		if (document.getElementById(this.divMenu).getAttribute("FGHiLiColor") !== "") {tempFGColorHolder = this.style.color; this.style.color = document.getElementById(this.divMenu).getAttribute("FGHiLiColor");}
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiImage") !== "none" && this.getElementsByTagName("img")[0]) {
			tempImgHolder.src = this.getElementsByTagName("img")[0].src; this.getElementsByTagName("img")[0].src = document.getElementById(this.divMenu).getAttribute("BGHiLiImage");}
		aniOpacity(this.id, initOpacity, 100, 6); //setOpacity(100, this);
	}
}
function MouseOutThird() {
	if (this.getAttribute("HilightMode") !== "none") {
		if (document.getElementById(this.divMenu).getAttribute("BGHiLiColor") !== "") this.style.backgroundColor = tempBGColorHolder;
		if (document.getElementById(this.divMenu).getAttribute("FGHiLiColor") !== "") this.style.color = tempFGColorHolder;
		if (this.getElementsByTagName("img")[0]) this.getElementsByTagName("img")[0].src = tempImgHolder.src;
		setOpacity(initOpacity, this);
	}
}
//call to hide all menu elements at first
HideSubMenu(1, ""); HideSubMenu(2, "");