var ContentHeight = 230;
var TimeToSlide = 550.0;
//var TimeToSlide = 250.0;

var openAccordion = '';

// height has been incorporated here to give a different height to the city list
function runAccordion(index, height)
{
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';
    
  if (!height )
	var height = 0;
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "', " + height + ")", 33);
  
  openAccordion = nID;
}

function animate(lastTick, timeLeft, closingId, openingId, height)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);

  if (height > 0)
	var NewContentHeight = height;
  else
	var NewContentHeight = ContentHeight;

  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = NewContentHeight + 'px';
    
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * NewContentHeight);

  if(opening != null)
  {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
    opening.style.height = (NewContentHeight - newClosedHeight) + 'px';
  }
  
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate(" + curTick + "," + timeLeft +",'" + closingId + "','" + openingId + "', " + height + ")", 33);
  //setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "', " + height + ")", 33);
}
