var TimeToSlide = 250.0;
var heights = new Array();
var openIndex = '';
var ArrayHeight = [];
var imageName = 'image1';

function runInitialAccordion(index, contentHeights)
{
  heights = contentHeights; 
  if(openIndex == index)
   	  index = '';    
	  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openIndex + "','" + index + "')", 33);
	  
	  openIndex = index;
	  
	  index = index - 1
	  if(index >= 1)
	  {
		runInitialAccordion(index, contentHeights);
	  }
	  return;
}
function runNavigationAccordion(index)
{
	if(openIndex != index)
	{
		runAccordion(index);
	}
}

function runAccordion(index)
{
  if(openIndex == index)
    index = '';
    
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openIndex + "','" + index + "')", 33);
 
  openIndex = index;
}

function animate(lastTick, timeLeft, closingIndex, openingIndex)
{    
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var opening = (openingIndex == '') ? null : document.getElementById("Accordion" + openingIndex + "Content");
  var closing = (closingIndex == '') ? null : document.getElementById("Accordion" + closingIndex + "Content");
 
  if(timeLeft <= elapsedTicks)
  {
    if (opening != null) {
		opening.style.height = heights[openingIndex] + 'px';
        opening.style.display = 'block';
	}
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * heights[closingIndex]);
  var newOpenHeight =Math.round((1-(timeLeft/TimeToSlide)) * heights[openingIndex]);	

  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 +",'" + closingIndex + "','" + openingIndex + "')", 33);
   
}

function swapImg(index){	
	if(openIndex == index){		
		document.imageName.src='/images/minus_sign.png';
		
		//document.image2.src="/images/plus_sign.png";
		//return '/images/minus_sign.png';
		//return '/images/minus_sign.png';
		//reference.element.setAttribute('src','/images/minus_sign.png');		
	}
	else{		
		document.imageName.src='/images/plus_sign.png';
		
		//document.image2.src="/images/minus_sign.png";
		//return '/images/plus_sign.png';
		//reference.element.setAttribute('src','/images/plus_sign.png');		
	}
} 
