function oBrowser() {
	this.OPERA = (navigator.userAgent.indexOf("Opera") != -1);
	this.WEBTV = (navigator.appName.indexOf("WebTV") != -1);
	this.NN = (navigator.appName == "Netscape");
	this.NN4 = (navigator.appVersion.charAt(0) == 4 && this.NN);
	this.NN6 = (navigator.appVersion.charAt(0) > 4 && this.NN);
	this.IE = (navigator.appName == "Microsoft Internet Explorer" && !this.OPERA && !this.WEBTV);
	this.IE4 = (navigator.appVersion.indexOf("4.") && this.IE);
	this.IE5 = (navigator.appVersion.indexOf("5.") && this.IE);
	this.DOM = document.getElementById ? 1 : 0;

	this.fSetBounds();
}

oBrowser.prototype.fSetBounds = function() {
	if (this.NN || this.OPERA) {
		this.w = window.innerWidth;
		this.h = window.innerHeight;
		this.l = window.pageXOffset;
		this.t = window.pageYOffset;
	} else if (this.IE) {
		this.w = document.body.clientWidth;
		this.h = document.body.clientHeight;
		this.l = document.body.scrollLeft;
		this.t = document.body.scrollTop;
	}
}

var oBrowser = new oBrowser();


nRollUpDelay = 50;
nMenuRollRate = 3; //30;

function oMenu (id, dir, parentid) {
	this.sID = id;
	this.sIDouter = this.sID + "outer";
	this.sIDinner = this.sID + "inner";
	this.sDir = dir;
	if (parentid) {
		this.sParentID = parentid;
		//alert(id + " has parent");
	}
	this.bRolledUp = true;
	this.bRolledDown = false;
	this.nMenuInnerX = 0;
	this.nMenuInnerY = 0;
	//alert(this.sID +"; parentID=" + this.sParentID);
	
	bDIVLoaded = false;
	this.fOnDIVLoad();
}

oMenu.prototype.fOnDIVLoad = function() {
	var d = document;
	
	var oMenuOuter = oBrowser.DOM ? d.getElementById(this.sIDouter) : oBrowser.IE ? d.all[this.sIDouter] : d.layers[this.sIDouter];
	if (oMenuOuter) var oMenuInner = oBrowser.NN4 ? this.oMenuOuter.layers[this.sIDinner] : oBrowser.IE ? d.all[this.sIDinner] : d.getElementById(this.sIDinner);
	
	if (!oMenuOuter || !oMenuInner) {
		window.setTimeout(this.sID + ".fOnDIVLoad()", 100);
	} else {
		this.oMenuOuter = oMenuOuter;
		this.oMenuInner = oMenuInner;
		sTempFunctionMouseOver = this.sID + ".fMouseOver();" + (this.sParentID ? this.sParentID + ".fMouseOver();" : "");
		sTempFunctionMouseOut = this.sID + ".fMouseOut();" + (this.sParentID ? this.sParentID + ".fMouseOut();" : "");
		oMenuInner.onmouseover = new Function(sTempFunctionMouseOver);
		oMenuInner.onmouseout = new Function(sTempFunctionMouseOut);
		
		bDIVLoaded = true;
		this.fRollUpMenuDone();
	}
}

oMenu.prototype.fMouseOver = function() {
	if (bDIVLoaded) {
		//window.status = this.oMenuOuter.style.zIndex;
		if (!this.sParentID) {
			this.oMenuOuter.style.zIndex = 2;
		}
		this.fStopTimerToRollUpMenu();
		this.fRollDownMenu();
	}
}

oMenu.prototype.fMouseOut = function() {
	if (bDIVLoaded) {
		if (!this.sParentID) {
			this.oMenuOuter.style.zIndex = 1;
		}
		this.fStartTimerToRollUpMenu();
	}
}

oMenu.prototype.fStartTimerToRollUpMenu = function() {
	this.RollUpTimer = window.setTimeout(this.sID+".fRollUpMenu();", nRollUpDelay);
}

oMenu.prototype.fStopTimerToRollUpMenu = function() {
	if (this.RollUpTimer) {
		this.RollUpTimer = window.clearTimeout(this.RollUpTimer);
	}
}

oMenu.prototype.fRollUpMenu = function() {
	//if (this.bRolledDown) {
		//roll up the menu...
		this.bRollOut = false;
		if (this.RollTimerMC) {
			this.RollTimerMC = window.clearTimeout(this.RollTimerMC);
		}
		this.RollTimerMC = window.setInterval(this.sID + ".fRollMenuMC()", 20);
		//this.fRollUpMenuMC(); //temp version!!!
	//}
}

oMenu.prototype.fRollUpMenuDone = function() {
	//window.status = "rolled up... done!";
	//alert(this.sID+" nMenuWidth = "+nMenuWidth);
	if (this.RollTimerMC) {
		this.RollTimerMC = window.clearTimeout(this.RollTimerMC);
	}
	if (this.sDir == "r") {
		this.nMenuInnerX = -nMenuWidth;
		this.nMenuInnerY = 0;
	
	} else if (this.sDir == "l") {
		this.nMenuInnerX = nMenuWidth;
		this.nMenuInnerY = 0;
	
	} else if (this.sDir == "d") {
		this.nMenuInnerX = 0;
		this.nMenuInnerY = -nMenuHeight;;

	}	
	this.fMoveMenuInner(this.nMenuInnerX, this.nMenuInnerY);
	
	this.bRolledUp = true;
	this.fShowMenuOuter(false);
}

oMenu.prototype.fRollDownMenu = function() {
	//if (this.bRolledUp) {
		this.fShowMenuOuter(true);
		this.bRolledUp = false;
		//roll down the menu
		//t  = 0;
		this.bRollOut = true;
		if (this.RollTimerMC) {
			this.RollTimerMC = window.clearTimeout(this.RollTimerMC);
		}
		this.RollTimerMC = window.setInterval(this.sID + ".fRollMenuMC()", 20);
		//this.fRollDownMenuMC(); //temp version!!
	//}
}

oMenu.prototype.fRollDownMenuDone = function() {
	//window.status = "rolled down... done!";
	if (this.RollTimerMC) {
		this.RollTimerMC = window.clearTimeout(this.RollTimerMC);
	}
	this.nMenuInnerX = 0;
	this.nMenuInnerY = 0;
	this.bRolledDown = true;
}

oMenu.prototype.fRollMenuMC = function() {
	//t ++;
	//window.status = t;
	if (this.sDir == "d") {
		if (this.bRollOut) {
			this.nMenuInnerY += Math.ceil((0 - this.nMenuInnerY) / nMenuRollRate) + 1; // += nMenuRollRate;
			if (this.nMenuInnerY >= 0) {
				this.fRollDownMenuDone();
			}
		} else {
			this.nMenuInnerY += Math.floor((this.nMenuInnerY - 0) / nMenuRollRate) - 1; // -= nMenuRollRate;
			if (this.nMenuInnerY <= -nMenuHeight) {
				this.fRollUpMenuDone();
			}
		}
		this.fMoveMenuInner(0, this.nMenuInnerY);
		
	} else if (this.sDir == "r") {
		if (this.bRollOut) {
			this.nMenuInnerX += Math.ceil((0 - this.nMenuInnerX) / nMenuRollRate) + 1; // += nMenuRollRate;
			if (this.nMenuInnerX >= 0) {
				this.fRollDownMenuDone();
			}
		} else {
			this.nMenuInnerX += Math.floor((this.nMenuInnerX - 0) / nMenuRollRate) - 1; // -= nMenuRollRate;
			if (this.nMenuInnerX <= -nMenuWidth) {
				this.fRollUpMenuDone();
			}
		}
		this.fMoveMenuInner(this.nMenuInnerX, 0);
		
	} else if (this.sDir == "l") {
		if (this.bRollOut) {
			this.nMenuInnerX += Math.floor((0 - this.nMenuInnerX) / nMenuRollRate) - 1; // -= nMenuRollRate;
			if (this.nMenuInnerX <= 0) {
				this.fRollDownMenuDone();
			}
		} else {
			this.nMenuInnerX += Math.ceil((this.nMenuInnerX - 0) / nMenuRollRate) + 1; // += nMenuRollRate;
			if (this.nMenuInnerX >= nMenuWidth) {
				this.fRollUpMenuDone();
			}
		}
		this.fMoveMenuInner(this.nMenuInnerX, 0);
		
	} 
}

oMenu.prototype.fShowMenuOuter = function(bvisible) {
	//alert("show "+bvisible+" this.oMenuOuter.visibility: "+this.oMenuOuter.style.visibility);
	if (bvisible) {
		this.oMenuOuter.style.visibility = "visible";
	} else {
		this.oMenuOuter.style.visibility = "hidden";
	}
}

oMenu.prototype.fMoveMenuInner = function(x, y) {
	this.oMenuInner.style.left = x;
	this.oMenuInner.style.top = y;
	//if(NN && !NN6) document.layers[sid].moveTo(nx, ny);
}

