  /*
    You can add as many independet menus as you like, 
    i.e. main navigation and content navigation.
    
    conventions:
    - main navi item DIVS that are embedded in the page
      must have "MainItem" in their CSS class name
      must have corresponding "HorzOffset" and "VertOffset" variables (see below)
    - sub menu DIVS which are positioned absolutely
      must have "SubMenu" in their CSS class name
      must have an ID in the shape of "menu_1" or "menu_1_3"
    - sub menu item DIVS that are contained in sub menu DIVs
      must have "SubItem" in their CSS class name
  */

  // EDIT these class-specific variables --------------------------
  // The names of these variables correspond to the CSS class names
  // of the DIV tags they correspond to.
  
  // ex.: naviMainItemActiveBg is the background color 
  // for the DIV of class "naviMainItem" when highlighted
  var naviMainItemActiveBg="";
  var naviMainItemInactiveBg="";
  var naviMainItemActiveText="#942933";
  var naviMainItemInactiveText="942933";
  
  var naviSubItemActiveBg="#fefffd";
  var naviSubItemInactiveBg="#f1ebdb";
  var naviSubItemActiveText="#942933";
  var naviSubItemInactiveText="942933";
  
  var leftNavActiveBg="#4845c3";
  var leftNavInactiveBg="#1713af";
  var leftNavActiveText="#FFFFFF";
  var leftNavInactiveText="FFFFFF";
  
  var contentMainItemActiveBg="#4845c3";
  var contentMainItemInactiveBg="#1713af";
  var contentMainItemActiveText="#FFFFFF";
  var contentMainItemInactiveText="FFFFFF";
  
  var contentSubItemActiveBg="#4845C3";
  var contentSubItemInactiveBg="#1713af";
  var contentSubItemActiveText="#FFFFFF";
  var contentSubItemInactiveText="FFFFFF";
  
  // EDIT these general variables ---------------------------------
  
  // horizontal DIV offset of Netscape browsers
  var horzNSOffset=10;
  var vertOffset=10;
  var hotZoneBorder=4;
    
  // DO NOT EDIT these variables ----------------------------------
  
  var hotZoneLeft=-1;
  var hotZoneTop=-1;
  var hotZoneRight=-1;
  var hotZoneBottom=-1;
  
  var mouseX=0;
  var mouseY=0;
  
  var activeMenuID='_';
  var activeItems=new Array();
  
  var NONE=0;
  var LEFT=1;
  var RIGHT=2;
  var TOP=3;
  var BOTTOM=4;
  
  // "PUBLIC" functions (callable from HTML pages) ----------------

  function unhover(menuItem) {
    if (!menuItem) return;
    setInactiveStyle(menuItem);
  }
  
  function hover(menuItem,menuNum,position) {
    if (!menuItem) return;
    var parentMenu=getParentMenu(menuItem);
    if (!parentMenu) return;
    
    var thisLevel=getLevelFromID(parentMenu.id);

    // hide all menus following in the hierarchy
    hideCurrentMenusOnLevel(thisLevel+1);
    setActiveStyle(menuItem);

    // if thisLevel is not 1 then showMenu will set the activeMenuID    
    if (thisLevel==1)
      activeMenuID=parentMenu.id;
    
    // make sure that the menu item that 
    // popped up the current menu will be highlighted
    hoverLastItem();
        
    if ((menuNum!=NONE) && (showMenu(menuItem,menuNum,position))) {
      // register this menu item in the array of currently active menu items
      pushItem(menuItem);
      setHotZoneForActiveMenu();
    }
  }  
  
  // "PRIVATE" functions (just for internal use) ------------------
  
  // the following two functions change the 
  // visual style of the given object
  // depending on its CSS class name
  function setActiveStyle(obj) {
    var className=obj.className;
    obj.style.backgroundColor=eval(className+"ActiveBg");
    obj.style.color=eval(className+"ActiveText");
  }
  
  function setInactiveStyle(obj) {
    var className=obj.className;
    obj.style.backgroundColor=eval(className+"InactiveBg");
    obj.style.color=eval(className+"InactiveText");
  }

  // shows the respective sub menu and aligns it 
  // to the right of the given parentItem (DIV)
  function showMenu(parentItem,num,position) {
    if (!parentItem) return;
    // get sub menu DOM element
    var subMenuID="menu_"+num;
    var subMenu=(document.getElementById)?document.getElementById(subMenuID):eval("document.all."+subMenuID);
    if (!subMenu) return false;
    
    var menuLeft, menuTop;
    coords=getAbsPosition(parentItem);
    menuLeft=coords[0];
    menuTop=coords[1];

    if (position==RIGHT)
      menuLeft+=parentItem.offsetWidth;
    else if (position==TOP)
      menuTop-=subMenu.offsetHeight;
    else if (position==LEFT)
      menuLeft-=subMenu.offsetWidth;
    else if (position==BOTTOM)
      menuTop+=parentItem.offsetHeight;
    
    subMenu.style.left=menuLeft;
    subMenu.style.top=menuTop;
    subMenu.style.visibility="visible";
    
    activeMenuID=subMenuID;
    
    return true;
  }
  
  // used for managing the array of currently active menu Items
  // adds another menu item to the array
  function pushItem(menuItem) {
    activeItems[activeItems.length]=menuItem;
  }
  
  // used for managing the array of currently active menu Items
  // pops off the last menu item from the array and returns it
  function popItem() {
    var menuItem;
    if (activeItems.length!=0) {
      menuItem=activeItems[activeItems.length-1];
      activeItems.length--;
    }
    return menuItem;
  }
  
  // highlights the last menu item in the activeItems array
  function hoverLastItem() {
    if (activeItems.length!=0)
      setActiveStyle(activeItems[activeItems.length-1]);
  }
  
  function getParentMenu(menuItem) {
    if (document.getElementById)
      while (menuItem) {
        if ((menuItem.id) && (menuItem.id.indexOf('menu')==0)) 
          break;
        else
          menuItem=menuItem.parentNode;
      } 
    else
      while (menuItem) {
        if ((menuItem.id) && (menuItem.id.indexOf('menu')==0)) 
          break;
        else
          menuItem=menuItem.parentElement;
      } 
    return menuItem;
  }
    
  // returns an array of absolute positions (0 => x, 1=> y) of a DOM element
  function getAbsPosition(obj) {
    var absLeft=obj.offsetLeft;
    var absTop=obj.offsetTop;
    
    if (IE5) {
      var padLeft=obj.currentStyle.paddingLeft;
      var padTop=obj.currentStyle.paddingTop;
      
      var pos=padLeft.indexOf('px');
      if (pos!=-1)
        absLeft-=parseInt(padLeft.substring(0,pos));
      pos=padTop.indexOf('px');
      if (pos!=-1)
        absTop-=parseInt(padTop.substring(0,pos));
    }

    do {
      obj=obj.offsetParent;
      absLeft+=obj.offsetLeft;
      absTop+=obj.offsetTop;
    } while (obj.offsetParent);
    
    // specific to RPM
    if (activeMenuID.indexOf('menu_2')==0) {
      var scrollArea=(document.getElementById)?document.getElementById('scrollArea'):eval("document.all.scrollArea");
      absLeft-=scrollArea.scrollLeft;
      absTop-=scrollArea.scrollTop;
    }
     
    return new Array(absLeft,absTop);
  }
  
  // counts the underscores _ in the given ID to 
  // determine the menu level
  function getLevelFromID(menuID) {
    var level=0;
    var pos=0;
    while (menuID.indexOf('_',pos)!=-1) {
      level++;
      pos=menuID.indexOf('_',pos)+1;
    }
    return level;
  }
  
  // takes the ID of the currently active sub menu,
  // hides it and all the menus preceding in the hierarchy
  // walks through the menu hierarchy derived from the menuIDs
  function hideCurrentMenusOnLevel(num) {
    var menuID=activeMenuID;
    var thisLevel=getLevelFromID(menuID);
    if ((thisLevel==1) || (thisLevel<num))
      return;
    var menu;
    var lastItem;

    while (thisLevel>=num) {
      menu=(document.getElementById)?document.getElementById(menuID):eval("document.all."+menuID);
      if ((menu) && (thisLevel!=1))
        menu.style.visibility='hidden';
      // chop the last section of the ID, inckuding the underscore _
      menuID=menuID.substring(0,menuID.lastIndexOf('_'));
      // remove highlighted menu items from the array
      lastItem=popItem()
      if (lastItem)
        setInactiveStyle(lastItem);
      thisLevel--;
    }
    
    activeMenuID=menuID;
    // reset hot zone to current sub menu
    setHotZoneForActiveMenu();
  }
    
  // sets the rectangle covering all active menus as hot zone
  // walks through the menu hierarchy derived from the menuIDs
  function setHotZoneForActiveMenu() {
    if (getLevelFromID(activeMenuID)<2) return;
    var menuID=activeMenuID;
    var menu;
    var curLeft, curTop, curRight, curBottom;
    var startLevel=getLevelFromID(menuID);
    var thisLevel=startLevel;
    
    while (thisLevel>0) {
      // for the main navigation level, do not take the whole menu
      // but only the active main navi item to set the hot zone
      if (thisLevel==1)
        menu=activeItems[0];
      else
        menu=(document.getElementById)?document.getElementById(menuID):eval("document.all."+menuID);
      
      if (menu) 
        if (thisLevel==startLevel) {
          coords=getAbsPosition(menu);
          hotZoneLeft=coords[0];
          hotZoneTop=coords[1];
          hotZoneRight=hotZoneLeft+menu.offsetWidth;
          hotZoneBottom=hotZoneTop+menu.offsetHeight;
        } else {
          coords=getAbsPosition(menu);
          curLeft=coords[0];
          curTop=coords[1];
          curRight=curLeft+menu.offsetWidth;
          curBottom=curTop+menu.offsetHeight;
          if (curLeft<hotZoneLeft) hotZoneLeft=curLeft;
          if (curTop<hotZoneTop) hotZoneTop=curTop;
          if (curBottom>hotZoneBottom) hotZoneBottom=curBottom;
          if (curRight>hotZoneRight) hotZoneRight=curRight;
        }
      
      // chop the last section of the ID, inckuding the underscore _
      menuID=menuID.substring(0,menuID.lastIndexOf('_'));
      thisLevel--;
    }
    hotZoneLeft-=hotZoneBorder;
    hotZoneTop-=hotZoneBorder;
    hotZoneRight+=hotZoneBorder;
    hotZoneBottom+=hotZoneBorder;
  }
  
  function checkMousePos(e) {
    if (document.all) {
      mouseX=event.clientX+document.body.scrollLeft;
      mouseY=event.clientY+document.body.scrollTop;
    } else {
      mouseX=e.pageX;
      mouseY=e.pageY;
    }  

    if ((getLevelFromID(activeMenuID)>1) && 
      (mouseX <= hotZoneLeft-horzNSOffset || mouseX >= hotZoneRight || 
       mouseY <= hotZoneTop || mouseY >= hotZoneBottom)) {
      hideCurrentMenusOnLevel(2);
    }
    return true;
  }
  
  // specific to RPM
  function registerMenu() {
  }
  
  // initialize event capturing
  if (!document.all) 
    document.captureEvents(Event.MOUSEMOVE);
  document.onmousemove = checkMousePos;

  // check browser version
  var IE5=false;
  // MSIE 5 MAC edition has a bug with the offsetLeft/offsetTop properties
  if ((navigator.appVersion.indexOf('MSIE 5')!=-1) && (navigator.appVersion.indexOf('Macintosh')!=-1))
    IE5=true;
  