var ContentHeight = 250;
var TimeToSlide = 250.0;

var openAccordion = '';

function runAccordion(index)
{
  var nID = index;
  if(openAccordion == nID)
    return;
    
  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("Accordion" + openingId + "Content");
  var closing = (closingId == '') ? null : document.getElementById("Accordion" + closingId + "Content");
 
  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
    {
      opening.style.height = ContentHeight + 'px';
      
      var imgElement = document.getElementById("Accordion" + openingId + "Image");
      if (imgElement != null)
        imgElement.src = rollover(openingId);
    }
    
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';

      var imgElement = document.getElementById("Accordion" + closingId + "Image");
      if (imgElement != null)
        imgElement.src = rollout(closingId);
    }
    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);
}

function rollover(index)
{
  if (index == openAccordion)
  {
    if (index == 1)
        return "images/menuGetHelpSelected.png";
    if (index == 2)
        return "images/menuGiveHelpSelected.png";
    if (index == 3)
        return "images/menuAboutUsSelected.png";
  }
  else
  {
    if (index == 1)
        return "images/menuGetHelpRO.png";
    if (index == 2)
        return "images/menuGiveHelpRO.png";
    if (index == 3)
        return "images/menuAboutUsRO.png";
  }
}

function rollout(index)
{
  if (index == openAccordion)
  {
    if (index == 1)
        return "images/menuGetHelpSelected.png";
    if (index == 2)
        return "images/menuGiveHelpSelected.png";
    if (index == 3)
        return "images/menuAboutUsSelected.png";
  }
  else
  {
    if (index == 1)
        return "images/menuGetHelpUnselected.png";
    if (index == 2)
        return "images/menuGiveHelpUnselected.png";
    if (index == 3)
        return "images/menuAboutUsUnselected.png";
  }
}
