var sRootName = "" ;
var sSuffix = ".jpg" ;

var nContentHeight = 200 ;
var fTimeToSlide = 500.0 ;
var sOpenAccordion = '' ;
var nOpening = 0 ;
var nClosing = 0 ;

var aIcons = null ;

function NumToStr2(nVal)
{
  var sTemp = "00" ;
  
  sTemp = sTemp + nVal ;
  return sTemp.substr(sTemp.length - 2) ;
}

function GetImgName(nImg)
{
  return (sRootName + NumToStr2(nImg) + sSuffix) ;
}

function LoadBannerImages()
{
var nImg1, nImg2 ;
var nImages = 7 ;  // Number of g_banner_xx.gif images

  // Find RootName from path to "1pix.gif"
  sRootName = document.images["banner1"].src ;
  sRootName = sRootName.replace("1pix.gif", "g_banner_") ;
  sSuffix = ".jpg" ; // Banner images are jpeg

  // Get some random numbers 0..7
  nImg1 = Math.floor(Math.random() * nImages) ;
  nImg2 = Math.floor(Math.random() * nImages) ;
  if (nImg1 == nImg2)
    {
      // Move nImg2 by 1
      nImg2 = (nImg2 + 1) % nImages ;
    }

  // Display the two banner images
  document.images["banner1"].src = GetImgName(nImg1) ;
  document.images["banner2"].src = GetImgName(nImg2) ;
}

// Accordion Functions
function firstAccordion(nIdx)
{
  sOpenAccordion = "Accordion" + nIdx + "Content" ;

  // Get array of Icon Images if we haven't got one yet
  if (aIcons == null)
   {
    aIcons = document.getElementsByName("accordion-icon") ;
   }

  nOpening = nIdx ;

  // Open fully NOW without animation
  animate(0, 0, "", sOpenAccordion) ;
}
function runAccordion(nIdx)
{
var sID = "Accordion" + nIdx + "Content" ;

  // Get array of Icon Images if we haven't got one yet
  if (aIcons == null)
   {
    aIcons = document.getElementsByName("accordion-icon") ;
   }

  if (sOpenAccordion == sID)
   {
    sID = '' ;
    nClosing = nIdx ;
    nOpening = 0 ;
   }
  else
   {
    nClosing = nOpening ;
    nOpening = nIdx ;
   }

  nContentHeight = document.getElementById("Accordion" + nIdx + "Content_").offsetHeight ;
  setTimeout("animate(" + new Date().getTime() + "," + fTimeToSlide + ",'" + sOpenAccordion + "','" + sID + "')", 33) ;

  sOpenAccordion = sID ;
}

function animate(fLastTick, fTimeLeft, sClosingID, sOpeningID)
{
var fCurTick = new Date().getTime() ;
var fElapsedTicks = fCurTick - fLastTick ;
var nNewClosedHeight = 0 ;

var eOpening = (sOpeningID == '') ? null : document.getElementById(sOpeningID) ;
var eClosing = (sClosingID == '') ? null : document.getElementById(sClosingID) ;

  if (fTimeLeft <= fElapsedTicks)
   {
    if (eOpening != null)
     {
      eOpening.style.height = 'auto' ;
     }

    if (eClosing != null)
     {
      // eClosing.style.display = 'none' ;
      eClosing.style.height = '0px' ;
     }

    // Set icon images
    if ((nClosing > 0) && (nClosing <= aIcons.length))
        aIcons[nClosing - 1].src = "../images/nav2/plus-sign2.gif" ;
    if ((nOpening > 0) && (nOpening <= aIcons.length))
        aIcons[nOpening - 1].src = "../images/nav2/minus-sign2.gif" ;

    // alert("nOpening = " + nOpening + ", nClosing = " + nClosing) ;

    return ;
   }

  fTimeLeft -= fElapsedTicks ;
  nNewClosedHeight = Math.round((fTimeLeft / fTimeToSlide) * nContentHeight) ;

  if (eOpening != null)
   {
    if (eOpening.style.display != 'block')
     {
      eOpening.style.display = 'block' ;
     }
    eOpening.style.height = (nContentHeight - nNewClosedHeight) + 'px' ;
   }

  if (eClosing != null)
   {
    eClosing.style.height = nNewClosedHeight + 'px' ;
   }

   setTimeout("animate(" + fCurTick + "," + fTimeLeft + ",'" + sClosingID + "','" + sOpeningID + "')", 33) ;
}

