// JavaScript Document
var TimeToSlide = 250.0;

var openAccordion = '';
var openHeight = 0;

function runAccordion(index)
{
	var nID = "Accordion" + index + "Content";
	var lID = "Accordion" + index + "List";
	var aID = "Accordion" + index;
	var cID = '';
	if(openAccordion == nID) {
		nID = '';
		lID = '';
		document.getElementById(aID).style.backgroundImage = 'url(css/images/mark-closed.png)';
	} else if(openAccordion != '') {
		cID = openAccordion.substring(0, openAccordion.length - 7);
		if ( document.getElementById(cID)) document.getElementById(cID).style.backgroundImage = 'url(css/images/mark-closed.png)';
	}
	if ( lID != '' && document.getElementById(lID) ) {
		document.getElementById(aID).style.backgroundImage = 'url(css/images/mark-open.png)';
	}
	setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" 
	  + openAccordion + "','" + nID + "','" + lID + "')", 10);
	openAccordion = nID;
}

function getComputedHeight(theElt)
{
        docObj = document.getElementById(theElt);
        if(docObj.offsetHeight != null){
                tmphght = docObj.offsetHeight;
        }
        else{
                var tmphght1 = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
                tmphght = tmphght1.split('px');
                tmphght = tmphght[0];
        }
        return tmphght;
}

function animate(lastTick, timeLeft, closingId, openingId, openingList)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  var listHeight = 0;
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);
 
    if(opening != null) {
  		listHeight = getComputedHeight(openingList);
    }
 
 
  if(timeLeft <= elapsedTicks)
  {
    if(opening != null) 
	{
      opening.style.height = listHeight + 'px';
	  openHeight = listHeight;
	 }
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round(timeLeft/TimeToSlide * openHeight);
  var newOpenHeight = Math.round((TimeToSlide-timeLeft)/TimeToSlide * listHeight);

  if(opening != null)
  {
    if(opening.style.display != 'block') 
      opening.style.display = 'block';
 	opening.style.height =  newOpenHeight + 'px';
  }
  
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate(" + curTick + "," + timeLeft + ",'" 
      + closingId + "','" + openingId + "','" + openingList + "')", 10);
}

