﻿var ContentHeight = 350;
var TimeToSlide = 200.0;

var openAccordion = '';
currentOn=2;

function runAccordion(index)
{
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';
    
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "')", 33);
  
  //font changer
  changeElement = document.getElementById('acc' + index);
  changeElement.style.color = "#EEEEEE";
  
  for(acc=1; acc<3; acc++){
	if(index == currentOn){
	  changeElement = document.getElementById('acc' + acc); 
	  changeElement.style.color = "#323232";
	  index = 1000;
	}
	if(acc != index){
	  changeElement = document.getElementById('acc' + acc); 
	  changeElement.style.color = "#323232";
	}
  }
  currentOn = index;
  if(currentOn == 1){
	acc1Color = "#EEEEEE";
	acc2Color = "#323232";
  }else if(currentOn == 2){
	acc2Color = "#EEEEEE";
	acc1Color = "#323232";
  }else{
	acc2Color = "#323232";
	acc1Color = "#323232";
  }
  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(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = ContentHeight + 'px';
	 
    
    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);
}