var ContentHeight = 0;

var fullexpand = false;
var commentexpand = false;
//var ContentHeight2 = 0;


var TimeToSlide = 250.0;
var commentheight;
var openAccordion = '';
var openAccordion3 = '';
var curexpand;



function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function chkexpand(){
	
	curexpand = getCookie("expanded");
	
	//alert(curexpand);
	if(curexpand == "Y"){
		openAccordion = "Accordion1Content";
		commentheight = document.getElementById("dum1").offsetHeight;
		
		document.getElementById("Accordion1Content").style.display = "block" ;
		document.getElementById("Accordion1Content").style.height =commentheight + "px" ;
		//setTimeout("runAccordion2(1,'Y')",200);
		if(commentexpand){
  	
			document.getElementById("commentgo").src = "images/oll-go.jpg";
			commentexpand = false;
			setCookie("expanded","N",1);
		}else{
		
			document.getElementById("commentgo").src = "images/oll-down.jpg";
			commentexpand = true;
			setCookie("expanded","Y",1);
		}
	}
	
}

function runAccordion(index)
{
  dummyindex = index;
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';
   
  setTimeout("animateb(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "'," + dummyindex + ")", 33);
 
  openAccordion = nID;
}

function runAccordion2(index, callby)
{

  dummyindex = index;
  commentheight = document.getElementById("dum1").offsetHeight;
  
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';
   
  setTimeout("animate2(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "'," + dummyindex + ")", 1);
 
  openAccordion = nID;
  
		if(commentexpand){
  	
			document.getElementById("commentgo").src = "images/oll-go.jpg";
			commentexpand = false;
			setCookie("expanded","N",1);
		}else{
		
			document.getElementById("commentgo").src = "images/oll-down.jpg";
			commentexpand = true;
			setCookie("expanded","Y",1);
		}
  
  
}
/*
function chgexpand(){
	
	if(commentexpand == "Y"){
  	
  	setCookie("expanded","Y",1);
  	
  }else if(commentexpand == "N"){
  	
  	setCookie("expanded","N",1);
  	
  }
	
}
*/
function runAccordion3(index)
{
		
	
  
  dummyindex = index;
  fullstoryheight = document.getElementById("dum2").offsetHeight;
  
  var nID = "Accordion" + index + "Content";
  if(openAccordion3 == nID)
    nID = '';
   
  setTimeout("animate2(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion3 + "','" + nID + "'," + dummyindex + ")", 1);
 
  openAccordion3 = nID;
  
  if(fullexpand){
  	
  	document.getElementById("storybutton").src = "images/oll-go.jpg";
  	fullexpand = false;
  	
  }else{
  	
  	document.getElementById("storybutton").src = "images/oll-down.jpg";
  	fullexpand = true;
  }
  
}

function animateb(lastTick, timeLeft, closingId, openingId, dummyindex)
{ 
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);

  if(dummyindex == 1){
	ContentHeight = 140;
  }else if(dummyindex == 2){
	ContentHeight = 210;
  }else if(dummyindex == 3){
	ContentHeight = 180;
  }else{}
 
  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("animateb(" + curTick + "," + timeLeft + ",'"
      + closingId + "','" + openingId + "')", 33);
}

function animate2(lastTick, timeLeft, closingId, openingId, dummyindex)
{ 
  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);

  if(dummyindex == 1){
	ContentHeight2 = commentheight;
  }else if(dummyindex == 2){
	ContentHeight2 = fullstoryheight;
  }else{}
 
  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = ContentHeight2 + 'px';
      
    if(closing != null)
    {
    	
      closing.style.display = 'none';
   		closing.style.height = '0px';
      
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight2);

  if(opening != null)
  {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
    opening.style.height = (ContentHeight2 - newClosedHeight) + 'px';
  }
 
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate2(" + curTick + "," + timeLeft + ",'"
      + closingId + "','" + openingId + "')", 1);
}
