// -- menu.js -- client code for menu item mouseovers, footer positioning. --
var ContentHeight = 100;      //-- vars used by accordion menu --
var TimeToSlide = 250.0;
var openAccordion = '';

// -- see which document object model we have. --
var brwsr = '';
if (document.getElementById) brwsr = 'w3c';
else if (document.all)       brwsr = 'ie';
else                         brwsr = 'nn';   //Netscape 4.x

//alert('browser = \'' + brwsr + '\'.');

//***************************************************************************
function showMsg(msg)
{
   window.status = msg;
}

//***************************************************************************
// set height of scrolling div so footer is always at the bottom of the window
//***************************************************************************
function setObjHeight(obj, fhgt)
{
   var hgt = 0;
   var winObj = false;
   var winRef = 'document.';

   if (window.innerHeight) hgt = window.innerHeight;  //browser = nn
   else                    hgt = document.body.clientHeight;
   //alert('height = \'' + hgt + '\'.');           //debug
   hgt = Math.abs(hgt - fhgt);                     //subtract height of footer

   if      (brwsr == 'w3c') winRef += 'getElementById(\'' + obj + '\')';
   else if (brwsr == 'ie')  winRef += 'all.' + obj;
   else                     winRef += obj;

   if (brwsr == 'nn') winObj = eval(winRef);
   else eval("try {winObj = eval(" + winRef + ");} catch(e) { }");

   if ( winObj )
   {
      //alert('winObj.style.height = \'' + hgt + '\'.');   //debug
      if (brwsr == 'w3c' || brwsr == 'ie') winObj.style.height = hgt;
      else                                 winObj.height = hgt;
   }
}

//***************************************************************************
function SetObjVisibility(obj, visi)
{
   var winObj = false;
   var winRef = 'document.';

   if      (brwsr == 'w3c') winRef += 'getElementById(\'' + obj + '\')';
   else if (brwsr == 'ie')  winRef += 'all.' + obj;
   else                     winRef += obj;

   winObj = eval(winRef);

   if ( winObj )
   {
      if (brwsr == 'w3c' || brwsr == 'ie') winObj.style.visibility = visi;
      else                                 winObj.visibility = visi;
   }
}

//***************************************************************************
// if main.asp is in the right frame, have it display/hide a menu item description.
//***************************************************************************
function switchDivState(div1,div2)
{
   var winObj = false;
   if (parent.main)
   {
      var winRef = 'parent.main.document.';
      if      (brwsr == 'w3c') winRef += 'getElementById(\'' + div1 + '\')';
      else if (brwsr == 'ie')  winRef += 'all.' + div1;
      else                     winRef += div1;

      if (brwsr == 'nn') winObj = eval(winRef);
      else eval("try {winObj = eval(" + winRef + ");} catch(e) { }");

      if ( winObj )
      {
         parent.main.SetObjVisibility(div1,'hidden');
         parent.main.SetObjVisibility(div2,'visible');
      }
   }
   return true;
}

//***************************************************************************
// Displays/hides alternate (highlighted) menu item (nn), and if main.asp is in
// the right frame, has it display/hide a corresponding menu item description.
//***************************************************************************
function switchState(first,second,div1,div2)
{
   SetObjVisibility(first,'hidden');
   SetObjVisibility(second,'visible');

   switchDivState(div1,div2);
   return true;
}

//***************************************************************************
function doMenuPick(theURL)
{
   top.contents.location.href = theURL;
}

//***************************************************************************
function doMainPick(theURL)
{
   top.main.location.href = theURL;
}

//***************************************************************************
// two functions used by accordion menu:
//***************************************************************************
function runAccordion(index, accHeight)
{
   var nID = "Accordion" + index + "Content";
   ContentHeight = accHeight;
   if (openAccordion == nID)
      nID = '';

   setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "')", 33);

   openAccordion = nID;
}

//***************************************************************************
function animate(lastTick, timeLeft, closingId, openingId)
{
   var curTick = new Date().getTime();
   var elapsedTicks = curTick - lastTick;

   var opening = (openingId == '') ? null : document.getElementById(openingId);
   var closing = (closingId == '') ? null : document.getElementById(closingId);

   if (timeLeft <= elapsedTicks)
   {
      if (opening != null)
         opening.style.height = ContentHeight + 'px';

      if (closing != null)
      {
         closing.style.display = 'none';
         closing.style.height = '0px';
      }
      return;
   }

   timeLeft -= elapsedTicks;
   var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

   if (opening != null)
   {
      if(opening.style.display != 'block')
         opening.style.display = 'block';
      opening.style.height = (ContentHeight - newClosedHeight) + 'px';
   }

   if (closing != null)
      closing.style.height = newClosedHeight + 'px';

   setTimeout("animate(" + curTick + "," + timeLeft +",'" + closingId + "','" + openingId + "')", 33);
}

