function Browser() 
{
	var ua,s,i;
	this.isIE=false;//Internet Explorer
	this.isOP=false;//Opera
	this.isNS=false;//Netscape
	this.version=null;
	ua=navigator.userAgent;
	s="Opera";
	if ((i=ua.indexOf(s))>=0) 
	{
		this.isOP=true;
		this.version=parseFloat(ua.substr(i+s.length));
		return;
	}
	s="MSIE";
	if ((i=ua.indexOf(s)) >= 0) 
	{
		this.isIE=true;
		this.version=parseFloat(ua.substr(i+s.length));
		return;
	}
	s="Netscape6/";
	if ((i=ua.indexOf(s))>=0) 
	{
		this.isNS=true;
		this.version=parseFloat(ua.substr(i+s.length));
		return;
	}
	// Treat any other "Gecko" browser as NS 6.1.
	s="Gecko";
	if ((i=ua.indexOf(s))>=0) 
	{
		this.isNS=true;
		this.version=6.1;
		return;
	}
}
var browser = new Browser();
// Negate width setting on menu style rule for IE and NS. Width must be set
// in style rule for Opera.
if (browser.isIE) document.styleSheets[document.styleSheets.length - 1].addRule(".menu", "width:auto");
if (browser.isNS) document.styleSheets[document.styleSheets.length - 1].insertRule(".menu { width:auto; }", document.styleSheets[document.styleSheets.length - 1].cssRules.length);
// Global variable for tracking the currently active button.
var activeButton = null;
// Capture mouse clicks on the page so any active button can be
// deactivated.
if (browser.isIE || browser.isOP) document.onmousedown = pageMousedown;
if (browser.isNS) document.addEventListener("mousedown", pageMousedown, true);
var overMenuButton = 0;
function pageMousedown(event) 
{
	var el;
	if (!activeButton) return;
	// Find the element that was clicked on.
	if (browser.isIE || browser.isOP) el = window.event.srcElement;
	if (browser.isNS) el = (event.target.className ? event.target : event.target.parentNode);
	if (el == activeButton) return;
	if (el.className != "menuButton" && el.className != "menuItem" && el.className != "menu") resetButton(activeButton);
}

function buttonClick(button, menuName) 
{
	// Blur focus from the link to remove that annoying outline.
	button.blur();
	// Associate the named menu to this button if not already done.
	if (!button.menu) button.menu = document.getElementById(menuName);
	if (activeButton && activeButton != button) resetButton(activeButton);
	if (button.isDepressed) resetButton(button); 
	else { depressButton(button); hideSelects(0, button.menu); }
	return false;
}

function buttonMouseover(button, menuName) 
{ 
	if (activeButton && activeButton != button) resetButton(activeButton);
	if (menuName && activeButton != button) buttonClick(button, menuName);
	autoHideDelay();
}

function submenuMouseover() 
{
	if(activeButton) { resetButton(activeButton); activeButton = null; }
}

function depressButton(button) 
{
	var w,dw,x,y;
	// Change the button's style class to make it look like it's depressed.
	button.className="menuButtonActive";
	// For IE, set an explicit width on the first menu item. This will
	// cause link hovers to work on all the menu's items even when the
	// cursor is not over the link's text.
	if (browser.isIE && !button.menu.firstChild.style.width) 
	{
		w=button.menu.firstChild.offsetWidth;
		button.menu.firstChild.style.width=w+"px";
		dw=button.menu.firstChild.offsetWidth-w;
		w-=dw;
		button.menu.firstChild.style.width=w+"px";
	}
	// Position the associated drop down menu under the button and
	// show it. Note that the position must be adjusted according to
	// browser, styling and positioning.
	
	// x = getPageOffsetLeft(button);
	x=getPageOffsetLeft(button)-3;
	// y = getPageOffsetTop(button) + button.offsetHeight;
	y=102;
	//alert(button.substring(18, 5));//="main.php?location=about&action=about")
	if (browser.isNS && browser.version<6.1) y--;
	// Position the menu.
	button.menu.style.left=x+"px";
	button.menu.style.top=y+"px";
	// For Opera, need to use "pixel" properties due to bug with standard
	// style properties.
	if (browser.isOP) 
	{
		y=getPageOffsetTop(button)+button.style.pixelHeight+1;
		button.menu.style.pixelLeft=x;
		button.menu.style.pixelTop=y;
	}
	//button.menu.style.height=button.menu.childNodes.length*17.3/2+"px";
	button.menu.style.visibility="visible";
	// Set button state and let the world know which button is
	// active.
	button.isDepressed=true;
	activeButton=button;
}
function resetButton(button) 
{
	// Restore the button's style class.
	button.className="menuButton";
	// Hide the button's menu.
	if (button.menu) button.menu.style.visibility="hidden";
	// Set button state and clear active menu global.
	button.isDepressed=false;
	activeButton=null;
	hideSelects(1,null);
}

// Return the true x coordinate of an element relative to the page. 
function getPageOffsetLeft(el) { return el.offsetLeft+(el.offsetParent?getPageOffsetLeft(el.offsetParent):0); }
// Return the true y coordinate of an element relative to the page.
function getPageOffsetTop(el) { return el.offsetTop+(el.offsetParent?getPageOffsetTop(el.offsetParent):0); }
function hideSelects(type,divElm)
{
	var n=document.getElementById("hideSelect");
	var mySize;
	if(browser.isIE)
	{
		//n.style["filter"]="'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'";
		if(type==0)
		{
			mySize=divElm.style["top"].substring(0, divElm.style["top"].length-2)-0+5;
			if(divElm.id.substring(0, 7)=="submenu") mySize+=33;
			n.style["top"]=mySize+"px";
			mySize=divElm.style["left"].substring(0, divElm.style["left"].length-2)-0+2;
			n.style["left"]=mySize+"px";
			n.style["width"]=divElm.firstChild.style["width"];
			n.style["height"]=(divElm.childNodes.length*17.3/2)+"px"//"200px"//divElm.style["height"];
			n.style["display"]="";
		}
		else n.style["display"]="none";
	}
}
var IE = document.all?true:false;
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var mouseX=0; var mouseY=0;
// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		mouseX=event.clientX+document.body.scrollLeft;
		mouseY=event.clientY+document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
		mouseX=e.pageX;
		mouseY=e.pageY;
	}  
	// catch possible negative values in NS4
	if (mouseX<0){tempX=0;}
	if (mouseY<0){tempY=0;}  
	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	return true;
}
/* AUTO HIDE */
function autoHideDelay()
{
	setTimeout("autoHide()", 1500); //HIDE MENU DELAY - 1.5 sec!!!
}

function autoHide()
{
	var n = document.getElementById("hideSelect");
	var startX; var endX; var startY; var endY;
	if(activeButton!=null) 
	{
		if(browser.isIE)
		{
			startX=n.style["left"].substring(0, n.style["left"].length-2);
			endX=eval(startX)+eval(n.style["width"].substring(0, n.style["width"].length-2));
			startY=n.style["top"].substring(0, n.style["top"].length-2);
			endY=eval(startY)+eval(n.style["height"].substring(0, n.style["height"].length-2));
		}
		else
		{
			startX=getPageOffsetLeft(activeButton)-3;
			endX=startX+eval(activeButton.menu.offsetWidth);
			startY = 102+eval(activeButton.menu.style.marginTop.substring(0, activeButton.menu.style.marginTop.length-2));
			endY=startY+(activeButton.menu.childNodes.length*17.3/2);
		}
		if( (mouseX<startX || mouseX>endX || mouseY<startY || mouseY>endY) && overMenuButton==0 ) 
		{
			resetButton(activeButton);
		}
		else { setTimeout("autoHide()", 1500); }
	}
}
