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 = "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 Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

var activeButton = null;

function buttonClick(event, menuId) {

  var button;

  // Get the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // Blur focus from the link to remove that annoying outline.
  // button.blur();

  // Associate the named menu to this button if not already done.
  // Additionally, initialize menu display.

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);

//   if (button.menu.isInitialized == null)
//      menuInit(button.menu);
	  
  }

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;

  // Exit if this button is the currently active one.

  if (button == activeButton)
    return false;

  // [END MODIFIED]

  // Reset the currently active button, if any.

  if (activeButton != null)
    resetButton(activeButton);

  // Activate this button, unless it was the currently active one.

  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}
function buttonMouseover(event, menuId) {

  var button;

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Activates this button's menu if no other is currently active.

  if (activeButton == null) {
    buttonClick(event, menuId);
    return;
  }

  // [END MODIFIED]

  // Find the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // If any other button menu is active, make this one active instead.

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {

  var x, y;

  // Update the button's style class to make it look like it's
  // depressed.

  button.className += " menuButtonActive";

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;
  if (button.menu.onmouseout == null)
    button.menu.onmouseout = buttonOrMenuMouseout;

  // [END MODIFIED]

  // Position the associated drop down menu under the button and show it.
  // Position = +160 right (width of side bar - some pixels from border and dots), - 2 px (move up a little)
  x = getPageOffsetLeft(button) + 160;
  y = getPageOffsetTop(button);

  // For IE, adjust position.

  if (browser.isIE) {
	  
//    x += button.offsetParent.clientLeft - 2;
//    y += button.offsetParent.clientTop;
  }

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";

  // For IE; size, position and show the menu's IFRAME as well.

  if (button.menu.iframeEl != null)
  {
    button.menu.iframeEl.style.left = button.menu.style.left;
    button.menu.iframeEl.style.top  = button.menu.style.top;
    button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
    button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
    button.menu.iframeEl.style.display = "";
  }
}

function resetButton(button) {

  // Restore the button's style class.

  removeClassName(button, "menuButtonActive");

  // Hide the button's menu, first closing any sub menus.

  if (button.menu != null) {
    button.menu.style.visibility = "hidden";
	
	// Reset button image to 'off' mode
	button.src = getImageOffSrc(button.src);

    // For IE, hide menu's IFRAME as well.

    if (button.menu.iframeEl != null)
      button.menu.iframeEl.style.display = "none";
  }
}
function menuMouseover(event) {

  var menu;

  // Find the target menu element.

  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  // Close any active sub menu.

  if (menu.activeItem != null)
    closeSubMenu(menu);
}



function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

// Strips the "_on" from a sidemenu's image source name
// ex. getImageOffSrc('blahblahblah_on.gif') = 'blahblahblah.gif'
// the sidemenu src name must be of the form "xxxxxxx_on.yyy"  (yyy is a 3-letter extension)
function getImageOffSrc(name) {
	return name.substring(0, name.length-7) + name.substring(name.length-4, name.length);
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

function buttonOrMenuMouseout(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element the mouse is moving to.

  if (browser.isIE)
    el = window.event.toElement;
  else if (event.relatedTarget != null)
      el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);

  // If the element is not part of a menu, reset the active button.

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}


function preloadImages() {
	if (document.images) {
		var menuimg1 = new Image();
		menuimg1.src="http://www.phoebemicro.com/images/topmenu1_on.gif";
		var menuimg2 = new Image();
		menuimg2.src="http://www.phoebemicro.com/images/topmenu2_on.gif";
		var menuimg3 = new Image();
		menuimg3.src="http://www.phoebemicro.com/images/topmenu3_on.gif";
		var menuimg4 = new Image();
		menuimg4.src="http://www.phoebemicro.com/images/topmenu4_on.gif";
		var menuimg5 = new Image();
		menuimg5.src="http://www.phoebemicro.com/images/topmenu5_on.gif";

		var img1 = new Image();
		img1.src = "http://www.phoebemicro.com/images/sidemenu1_on.gif";
		var img2 = new Image();
		img2.src = "http://www.phoebemicro.com/images/sidemenu2_on.gif";
		var img3 = new Image();
		img3.src = "http://www.phoebemicro.com/images/sidemenu3_on.gif";
		var img4 = new Image();
		img4.src = "http://www.phoebemicro.com/images/sidemenu4_on.gif";
		var img5 = new Image();
		img5.src = "http://www.phoebemicro.com/images/sidemenu5_on.gif";
		var img6 = new Image();
		img6.src = "http://www.phoebemicro.com/images/sidemenu6_on.gif";
		var img7 = new Image();
		img7.src = "http://www.phoebemicro.com/images/sidemenu7_on.gif";
		var img8 = new Image();
		img8.src = "http://www.phoebemicro.com/images/sidemenu8_on.gif";
		var img9 = new Image();
		img9.src = "http://www.phoebemicro.com/images/sidemenu9_on.gif";
		var img10 = new Image();
		img10.src = "http://www.phoebemicro.com/images/sidemenu10_on.gif";		
		var img11 = new Image();
		img11.src = "http://www.phoebemicro.com/images/sidemenu11_on.gif";		
		var img12 = new Image();
		img12.src = "http://www.phoebemicro.com/images/sidemenu12_on.gif";	
		
		var img2 = new Image();
		img2.src="http://www.phoebemicro.com/images/p1.1.gif";
		var menuimg2 = new Image();
		img2.src="http://www.phoebemicro.com/images/p2.1.gif";
		var menuimg3 = new Image();
		img2.src="http://www.phoebemicro.com/images/p3.1.gif";
		var menuimg4 = new Image();
		img2.src="http://www.phoebemicro.com/images/p4.1.gif";
		var menuimg5 = new Image();
		img2.src="http://www.phoebemicro.com/images/p5.1.gif";
		
	}
}