
var selTop;   // the top most thing that was selected going in.
var pageSel;  // this pages selection
var childSel; // this pages child selection
var lastSel;  // the last thing selected
var ht; // the inner html of the last submenu
var subMenus = new Array();  // a map of submenus, cause we blow away the real hidden content.
var offTimer;
var onTimer;

// force the default selection
window.addEvent('domready', function() {
  if( selTop != 0 )
  {
    var id = new String("menu_item_" + selTop);
    var topMenu = $(id);
    var childSel = '';
    if( topMenu.getParent().get('class') == "subHidden" )
    { // this is a submenu item page
      childSel = id;
      subpid = topMenu.getParent().get('id');
      selTop = subpid.replace('subId','');
      id = subpid.replace('subId','menu_item_');
      topMenu = $(id);
    }
    lastSel = pageSel = id;

    var myFx = new Fx.Morph( $(id) );
    if( topMenu )
    {
      myFx.start({
          'background-color':['#2C5301'],
          'margin-top': [0],
          'padding-top': [11],
          'border': [0],
          'margin-left': [-1]
      });
      // mark child selected 
      if( childSel.length )
      {
        $(childSel).setStyle( 'background-color',  '#FFFFFF');
      }
      // move the hidden menu
      subs = $('subId'+selTop);
      visSub = $('subMenu');
      if( subs && visSub )
      {
        ht =  new String(subs.get('html'));
        subMenus[subs]=ht;
        subs.get('html','');
        visSub.set('html',ht);
      }
    }
  }
  // for xtranet editing
  startEvents();
});

// top level menu hover event handler
var itemOff = function( offId )
{
}

var itemOn = function ( onId )
{
  if( onId && $(onId) )
  {
    lastSel = onId;
    subId = onId.replace('menu_item_','subId');
    subs = $(subId);
    visSub = $('subMenu');
    if( visSub )
    {
        var temp = "";
        if( subs )
        {
          temp = new String(subs.get('html'));
        }
        visSub.set('html',temp);
    }
    
  }
}

function hoverWork1( hoverId )
{
  onTimer = itemOn.delay(25, 0, hoverId);
}

function hoverOut1( hoverId )
{
  offTimer = itemOff.delay(100, 0, hoverId);
}

function hoverOut2(hoverId, isOut )
{
}

function hoverWork2(hoverId, isOut )
{
  $clear(offTimer);
}

function hoverWork3(hoverId, isOut )
{
}