	var isIE5 = (navigator.userAgent.indexOf("MSIE 5.") > 0  |
             navigator.userAgent.indexOf("MSIE 6.0") > 0) ? 1 : 0;
	var isNS6 = (navigator.userAgent.indexOf("Gecko")    > 0) ? 1 : 0;
	var isMac = (navigator.userAgent.indexOf("Mac") > 0) ? 1: 0;
	
	var activeButton = null;
	var lastSelectedButton = null;

	/*
	if (isIE5)
	{
		document.styleSheets[document.styleSheets.length - 1].addRule("#menuBar", "padding-top:4px");
		document.styleSheets[document.styleSheets.length - 1].addRule("#menuBar", "padding-bottom:3px");
	}
	*/
	
	// Capture mouse clicks on the page so any active button can be deactivated.
	
	if(!isMac)
	{
		if (isIE5)
			document.onmousedown = pageMousedown;
		if (isNS6)
			document.addEventListener("mousedown", pageMousedown, true);
	}		
	  
	function pageMousedown(event)
	{
	  var className;
		//alert("pageMousedown");
	  // If the object clicked on was not a menu button or item, close any active
	  // menu.

	  if (isIE5)
	    nodeName = window.event.srcElement.parentNode.nodeName;
	  if (isNS6)
	    nodeName =  event.target.parentNode.parentNode.nodeName;
	
   if (activeButton && nodeName != "DIV")
	  {
		resetButton(activeButton);
	  // alert("pageMouseDown " + nodeName);
	  } 
	}
  		
	function buttonClick(button,menuName)
	{
		if(button.selected)
			return false;
			
		// assign the popup to this button if not already defined
		if(!button.menu)
			button.menu = document.getElementById(menuName);
					
		// reset previous button, in any
		if(activeButton && activeButton != button)
			resetButton(activeButton);
		// toggle
		if(button.isDepressed)
			resetButton(button);
		else
			depressButton(button);
		return false;				
	}
	
	function depressButton(button)
	{
		if(button.selected)
			return;
			
		// Save current style values so they can be restored later.
		button.oldClassName = button.className;

		// Change style value to make the button looks like it's
		// depressed.
		button.className = button.clickClass;
		
		// For IE, force first menu item to the width of the parent menu,
		// this causes mouseovers work for all items even when cursor is
		// not over the link text.

		if (isIE5 && !button.menu.firstChild.style.width)
		{
			button.menu.firstChild.style.width = button.menu.offsetWidth + "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);
		y = getPageOffsetTop(button) + button.offsetHeight;
		if (isIE5)
		  y += 2;
		if (isNS6)
		{
		  x--;
		  y--;
		}
		button.menu.style.left = x + "px";
		button.menu.style.top  = y + "px";
		button.menu.style.visibility = "visible";

		// Set button state and let the world know which button is
		// active.

		button.isDepressed = true;
		activeButton = button;
	}

	function getPageOffsetLeft(el)
	{
		// Return the true x coordinate of an element relative to the page.
		return el.offsetLeft + (el.offsetParent ? getPageOffsetLeft(el.offsetParent) : 0);
	}

	function getPageOffsetTop(el)
	{
		// Return the true y coordinate of an element relative to the page.
		return el.offsetTop + (el.offsetParent ? getPageOffsetTop(el.offsetParent) : 0);
	}

	function buttonMouseover(button, menuName,clickClass,hoverClass)
	{
		// If any other button menu is active, deactivate it and activate this one.
		// Note: if this button has no menu, leave the active menu alone.
		
		// initialize the button's click class if necessary
		if(!button.clickClass)
			button.clickClass = clickClass;
		
		if(button.selected)
			return;
			
		if (activeButton)
		{
			if(activeButton != button)
			{
				resetButton(activeButton);
				if (menuName)
					buttonClick(button, menuName);
				else
					button.className = hoverClass;	
			}
		}	
		else
		{
			if(menuName)
				buttonClick(button,menuName);
			else
				button.className=hoverClass;	
		}	
	}
	
	function resetButton(button)
	{
	  // Restore the button's style settings.
	  button.className = button.oldClassName;
	  
	  // 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;
	}
	
	function menupick(pick)
	{
		pick.blur();
		if(activeButton)
			resetButton(activeButton);
		//alert("pick");
	}
	
	function selectNavigate(button)
	{
		if(button.options[button.selectedIndex].value != "")
			location.href = button.options[button.selectedIndex].value;
	}
	
	function selectButton(button,clickClass,doSelect)
	{
		//alert("selectButton: " + button);
		if(button.selected)
		{
			if(!doSelect)
			{
				//alert("unSelect " + button.oldClassName);
				button.className = "NAVBARPLAIN0"; //button.oldClassName;
				button.selected = false;
				if(button == lastSelectedButton)
					lastSelectedButton = null;
				//alert("unSelect");
			}
		}
		else
		{
			if(doSelect)
			{
				//alert("doSelect");
				if(button != lastSelectedButton && lastSelectedButton != null)
				{
					selectButton(lastSelectedButton,"",false);
				}	
				if(!button.oldClassName)	
					button.oldClassName = button.className;
				button.className = clickClass;
				lastSelectedButton = button;
				button.selected = true;
				//alert("selectButton: " + button.className);
			}
		}
	}			
			
				
	
	function arraySelect(up,a)
	{
		
		if(up)
		{
			if(a.curIndex < a.length-1)
				a.curIndex++;
			else
				a.curIndex = 0;
		}
		else
		{
			if(a.curIndex > 0 )
				a.curIndex--;
			else
				a.curIndex = a.length-1;
		}
		location=a[a.curIndex];
		//alert("length " + a.length + " Index " + a.curIndex + " location " + a[a.curIndex]);		
}