// JavaScript Document
var ContentHeight = 250;
var TimeToSlide = 250.0;

var openAccordion = '';

function initTitle(){
	for(i=1; i<=7; i++){
		document.getElementById("title"+i).className = "AccordionTitle";
	}
}

function runAccordion(index)
{
  initTitle();
  document.getElementById("title"+index).className ="AccordionTitleSelected";
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID){
	  nID = '';
	  document.getElementById("title"+index).className ="AccordionTitle";
  }
  
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "')", 33);
  openAccordion = nID;
  //document.getElementById('title'+index).style.color="#ff0000";
}
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(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = 100 + '%';
   
    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 + "')", 33);
}
