// Determine browser type (Netscape 6 or IE 5.5).

var isIE5 = (navigator.userAgent.indexOf("MSIE 5.5") > 0) ? 1 : 0;
var isNS6 = (navigator.userAgent.indexOf("Gecko")    > 0) ? 1 : 0;
  
// 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 (isIE5)
  document.onmousedown = pageMousedown;
if (isNS6)
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {

  var className;

  // If the object clicked on was not a menu button or item, close any active
  // menu.

  if (isIE5)
    className = window.event.srcElement.className;
  if (isNS6)
    className = (event.target.className ?
      event.target.className : event.target.parentNode.className);

  if (className != "menuButton" && className != "menuItem" && className != "menuButton_ecomm" && className != "menuItem_ecomm" && className != "menuButton_global" && className != "menuItem_global" && activeButton)
    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);

  // Reset the currently active button, if any.

  if (activeButton && activeButton != button)
    resetButton(activeButton);

  // Toggle the button's state.

  if (activeButton && button.isDepressed)
    resetButton(button);
  else
    depressButton(button);

  return false;
}

function buttonMouseover(button, menuName) {

  // 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.

  if (activeButton && activeButton != button) {
    resetButton(activeButton);
    if (menuName)
      buttonClick(button, menuName);
  }
}

function depressButton(button, bgcolor) {

  // Save current style values so they can be restored later.
  // Only needs to be done once.

  if (!button.oldBackgroundColor) {
    button.oldBackgroundColor = button.style.backgroundColor;
    button.oldBorderBottomColor = button.style.borderBottomColor;
    button.oldBorderRightColor = button.style.borderRightColor;
    button.oldBorderTopColor = button.style.borderTopColor;
    button.oldBorderLeftColor = button.style.borderLeftColor;
    button.oldColor = button.style.color;
    button.oldLeft = button.style.left;
    button.oldPosition = button.style.position;
    button.oldTop = button.style.top;
  }
  
  // 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
  // the brower type.

  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 resetButton(button) {

  // Restore the button's style settings.

  button.style.backgroundColor = button.oldBackgroundColor;
  button.style.borderBottomColor = button.oldBorderBottomColor;
  button.style.borderRightColor = button.oldBorderRightColor;
  button.style.borderTopColor = button.oldBorderTopColor;
  button.style.borderLeftColor = button.oldBorderLeftColor;
  button.style.color = button.oldColor;
  button.style.left = button.oldLeft
  button.style.position = button.oldPosition;
  button.style.top = button.oldTop;

  // 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 menuHide(menuItem, menuName)
{
	menuItem.style.visibility = 'hidden';
	activeButton = false;
}

function menuShow(menuItem)
{
	menuItem.style.visibility = 'visible';
}

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 el.offsetTop + (el.offsetParent ? getPageOffsetTop(el.offsetParent) : 0);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
