/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 * Extensively modified by Mike Foster, cross-browser.com, 19Dec03
 */

var currentMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(actuatorId, menuId)
{
  var actuator = document.getElementById(actuatorId);
  var menu = document.getElementById(menuId);
  
  var portalID = document.body.id
  var splitArray = portalID.split("_");
  var bodyID= splitArray[1];
  
  var menuSplit = menuId.split("_");
  var menuID = menuSplit[1];
  
  if (actuator == null || menu == null) return;

  actuator.menu = menu;
  menu.actuator = actuator;
  
  actuator.onmouseover = function()
  {
    if (currentMenu) {
      this.hideMenu();
    }
    this.showMenu();
   	if(bodyID == menuID){
   		Element.setStyle(actuator,{'backgroundPosition': '0 -21px'});
   		Element.setStyle(actuator,{'color': '#fff'});
   	}

  }

  actuator.onmouseout = function(evnt)
  {
    var e = evnt || window.event;
    if (e) {
      var oTo = e.relatedTarget || e.toElement;
      var li = this.parentNode || this.parentElement; // assumes actuator is child of LI
      // has mouse moved out of LI?
      while (oTo && oTo != li) {
        oTo = oTo.parentNode || oTo.parentElement;
      }
      if (!oTo) {
        this.hideMenu();
      }
    }
     if(bodyID == menuID){
   		Element.setStyle(actuator,{'backgroundPosition': '0 0px'});
   		Element.setStyle(actuator,{'color': '#000'});
   	}

  }

  menu.onmouseout = function(evnt)
  {
    var e = evnt || window.event;
    if (e) {
      var oTo = e.relatedTarget || e.toElement;
      // has mouse moved out of UL?
      while (oTo && oTo != this) {
        oTo = oTo.parentNode || oTo.parentElement;
      }
      if (!oTo) {
        this.actuator.hideMenu();
      }
    }
   	if(bodyID == menuID){
   		Element.setStyle(actuator,{'backgroundPosition': '0 0px'});
   		Element.setStyle(actuator,{'color': '#000'});
   	}
  }
  
  menu.onmouseover = function(evnt)
  {
   	if(bodyID == menuID){
   		Element.setStyle(actuator,{'backgroundPosition': '0 -21px'});
   		Element.setStyle(actuator,{'color': '#fff'});
   	}
   }
		

  actuator.showMenu = function()
  {
    var m = this.menu;
    m.style.left = this.offsetLeft + "px";
    m.style.top = this.offsetTop + this.offsetHeight + "px";
    m.style.visibility = "visible";
    currentMenu = m;
  }

  actuator.hideMenu = function()
  {
    if (currentMenu) {
      currentMenu.style.visibility = "hidden";
      currentMenu = null;
    }
  }
}
