var ContentHeight = 70;
var TimeToSlide = 150;

var openAccordion = '';

function runAccordion(index)
{
  var nID = "Accordion" + index + "Content";
  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 (opening != null && ContentHeight == 70 && opening.getElementsByTagName != null)
  {
	ContentHeight = opening.getElementsByTagName("li").length * 22 + 10;
  }

  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
    {
      opening.style.display = 'block';
      opening.style.height = ContentHeight + 'px';
      ContentHeight = 70;
    } 
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.floor(Math.round((timeLeft/TimeToSlide) * ContentHeight));

  if(opening != null)
  {
    
    if(opening.style.height != '0px' && 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);
  
}

