var contentHeight;
var timeToSlide = 250.0;
var flag = 0;

//Array of open accordions
var openAccordion = [];
//Array defined in php include call per page with accordion

function runAccordion(index, prefix, desiredHeight) {
  var nID = prefix + "_accordion_" + index + "_content";
 
  //return if it is the same drawer
  if(openAccordion[prefix] == nID){
  	return;
  }
  
  //we want the accordion to open to a height defined by the contents
  if(desiredHeight == null){
  	var contents = document.getElementById(nID);
  	
  	//get height (must display it as block)
  	contents.style.position = "absolute";
  	contents.style.zIndex = "-1";
  	contents.style.visibility = "hidden";
  	contents.style.display = "block";
  	contents.style.height = "auto";
  	desiredHeight = parseInt(contents.offsetHeight);
  	
  	//re-hide
  	contents.style.position = "static";
  	contents.style.zIndex = "1";
  	contents.style.visibility = "visible";
  	contents.style.display = "none";
  	contents.style.height = "0px";
  }
  
  contentHeight = desiredHeight;
  
  //if same, don't set nID.  This is so drawer knows its same and won't animate
  //if(openAccordion == nID) { nID = ''; }
   
  setTimeout("animate(" + new Date().getTime() + "," + timeToSlide + ",'"
      + openAccordion[prefix] + "','" + nID + "')", 33);
 
  openAccordion[prefix] = nID;
}

function animate(lastTick, timeLeft, closingId, openingId, prefix) {
	var curTick = new Date().getTime();
	var elapsedTicks = curTick - lastTick;
 
	var opening = (openingId == '') ? null : document.getElementById(openingId);
	var closing = (closingId == '') ? null : document.getElementById(closingId);
  
	//don't animate if it's the same drawer
	if(opening == closing){
		return;
	}
 
	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);
}