// JavaScript Document


var TimeToSlide = 100;

var openNav = '';

function loadnav() {
  var c_name="runnav";
  var index;
  var AccHeight;
  var c_value;

  if (document.cookie.length>0)
  {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
    { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      c_value = unescape(document.cookie.substring(c_start,c_end));
      index = (((c_value.split("&"))[0]).split("="))[1];
      AccHeight = (((c_value.split("&"))[1]).split("="))[1];
      // alert("index=" + index + " AccHeight= " + AccHeight);
      runNav(index,AccHeight);
    }
  }
}


function save(index, AccHeight)
{
  var name="runnav";
  var value="index=" + index + "&" + "AccHeight=" + AccHeight;
 
  document.cookie = name + "=" + escape(value) + ";path=/;";
  /* document.cookie = name + "=" + escape(value) + ";path=/;expires=Thursday, 10-JAN-20 16:00:00 GMT;"; */
}

function unsave()
{
  var name="runnav";
  document.cookie = name + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function runNav(index, AccHeight)
{
  ContentHeight = AccHeight;
  var nID = "Nav" + index + "Content";
  if(openNav == nID)
    nID = '';
 
  setTimeout("animate("
      + new Date().getTime() + "," + TimeToSlide + ",'"
      + openNav + "','" + nID + "')", 1);
  //animate(new Date().getTime(), TimeToSlide,openNav,nID);

  if ( nID == '' ) {
    unsave();
  } else {
    save (index, AccHeight);
  }
  openNav = nID;
}

// Open Navigation Function

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);

  //alert (timeLeft + " " + elapsedTicks); 
  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 + "')", 0);
  //animate(curTick,timeLeft,closingId,openingId);
}

