﻿var ContentHeight = 0;
var TimeToSlide = 250.0;
var openAccordion = '';
var curTick = 0;
var elapsedTicks = 0;
var timeLeft = 0;

 /*var openAccordions = new Array(); */

/* single container code */
function runAccordion(index){   
  
  /* menu clicked */
  var nID = "Accordion" + index + "Content";  
  
  if(openAccordion == nID){
	 /* check if user clicked same menu - close it */ 
     nID = '';
     /*alert("close same menu: " + nID + " - " + " " + openAccordion);*/	
     setTimeout("animate_close(" + curTick + "," + timeLeft + ",'" 
        + openAccordion + "','" + '' + "')", 33);	 
	}
  else
    {
		if(openAccordion == ''){
			    /* check if user clicked menu 1st time - open it */ 
        		/*alert("open menu 1st time: " + nID + " - " + " " + openAccordion);*/	
        		setTimeout("animate_open(" + new Date().getTime() + "," + TimeToSlide + ",'" 
            		+ openAccordion + "','" + nID + "')", 33);  			
			}
		else
		    {
				/* check if user clicked another menu when 1st menu still open - close old menu and then open new */
				/*alert("1st close old menu: " + nID + " - " + " " + openAccordion);*/	
     			setTimeout("animate_close(" + curTick + "," + timeLeft + ",'" 
        			+ openAccordion + "','" + '' + "')", 33);
				
        		/*alert("2nd open new menu: " + nID + " - " + " " + openAccordion);*/	
        		setTimeout("animate_open(" + new Date().getTime() + "," + TimeToSlide + ",'" 
            		+ openAccordion + "','" + nID + "')", 33);  				
			}
    }

  openAccordion = nID;


/*ContentHeight = AccHeight;*/
    
  /*x = readCookie('idxcookie');
  if (x) {index = x;} */
   
  /* multiple containers code */
  /*
  
  var x;
  var y;
  var nID = "Accordion" + index + "Content";
  var openAccordion = nID;
  var closeAccordion = ""; 
  	
  for(y in openAccordions)
  {
    if(openAccordions[y]==nID)
    {
      openAccordion='';
      closeAccordion=nID;
      openAccordions.splice(y, 1);
      break;
    }
  }  

  if(openAccordion!="")
    openAccordions[openAccordions.length]=openAccordion;
	
    setTimeout("animate("
      + new Date().getTime() + "," + TimeToSlide + ",'"
      + closeAccordion + "','" + openAccordion + "')", 33);*/
  
  /*eraseCookie("idxcookie");  
  createCookie("idxcookie",index,1);*/  
}

/*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);
}*/

function animate_open(lastTick, TLeft, closingId, openingId)
{  

  /*alert("inside open: " + lastTick + " " + timeLeft + " " + closingId + " " + openingId);*/
  curTick = new Date().getTime();
  elapsedTicks = curTick - lastTick;
  timeLeft = TLeft
   
  var closing = (closingId == '') ? null : document.getElementById(closingId);
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  
  if(timeLeft <= elapsedTicks)
  {
    if(closing != null)
    {
	  document.getElementById(closingId).style.display = 'none';
	  document.getElementById(closingId).style.height = '0px';
		
      /*closing.style.display = 'none';
      closing.style.height = '0px';*/
    }
	
	if(opening != null){
  		/*opening.style.height = 'auto';*/
		document.getElementById(openingId).style.height = 'auto';
		}    
    return;
  }
   
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(closing != null)
    document.getElementById(closingId).style.height = newClosedHeight + 'px';
	
	/*closing.style.height = newClosedHeight + 'px';*/
	
  if(opening != null)
  {
    if(document.getElementById(openingId).style.display != 'block'){
      document.getElementById(openingId).style.display = 'block';
	  document.getElementById(openingId).style.height = 'auto';
	  }
  }  
  
      /*if(opening.style.display != 'block'){
	  opening.style.display = 'block';
      opening.style.height = (ContentHeight - newClosedHeight) + 'px';
	  }*/
 
}

function animate_close(lastTick, TLeft, closingId, openingId)
{  
  timeLeft = TLeft;
  curTick = new Date().getTime();
  elapsedTicks = curTick - lastTick;
  
  var closing = (closingId == '') ? null : document.getElementById(closingId);
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  
  if(timeLeft <= elapsedTicks)
  {
	  
    if(closing != null)
    {
	  document.getElementById(closingId).style.display = 'none';
	  document.getElementById(closingId).style.height = '0px';
		
      /*closing.style.display = 'none';
      closing.style.height = '0px';*/
    }
	
	if(opening != null){
		document.getElementById(openingId).style.height = 'auto';
		
  		/*opening.style.height = 'auto';*/
		}    
    return;
  }
   
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(closing != null)
  	document.getElementById(closingId).style.height = newClosedHeight + 'px';
  
    /*closing.style.height = newClosedHeight + 'px';*/
	
  if(opening != null)
  {
    if(document.getElementById(openingId).style.display != 'block')
      document.getElementById(openingId).style.display = 'block';
      document.getElementById(openingId).style.height = (ContentHeight - newClosedHeight) + 'px';
  }  
  
  /*{
    if(opening.style.display != 'block')
      opening.style.display = 'block';
      opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  }*/  
}


/*function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
*/