var ContentHeight = 1;
var TimeToSlide = 0;
var openAccordion = '';
var whereivebeen = 0;

function writeSessionCookie (cookieName, cookieValue) {

//if  (whereivebeen==0 ) {
	//alert('About to write' );
if (testSessionCookie()){
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
	whereivebeen=getCookieValue('l4networks-mctrl>');
    return true;
  }
  else return false;
}
//}


function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}


function runAccordion(index)
{
//var whereami=getCookieValue('l4networks-mctrl>');
	//alert('index' + index);


if (index != getCookieValue ('l4networks-mctrl>')  && index != 99)
{
//alert('NEG' + index);
writeSessionCookie('l4networks-mctrl>',index);
}
if (index = 99) {
index=getCookieValue ('l4networks-mctrl>') ;
}


var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';

//alert('Ivebeen' + whereivebeen);
	

//whereivebeen=whereami;  

//alert('Ivebeen' + whereivebeen );
// alert('nid' + nID);
//alert(index);

//bug in next line Nw set to 1 in var on top
//ContentHeight = document.getElementById("Accordion" + index + "Content"+"_").offsetHeight;
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "')", 33);
 
  openAccordion = nID;
  
}

function animate(lastTick, timeLeft, closingId, openingId)
{  
		//alert('accord');

  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 = 'auto';

   
    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);
}
