var ContentHeight = 312;
var TimeToSlide = 250.0;
var openAccordion = '';

function runAccordion(index)
{
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
  {
    nID = '';
  }
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "')", 33);
  openAccordion = nID;
}

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';
      opening.style.overflow = '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';
    }
    if(opening.style.display != 'hidden')
    {
      opening.style.overflow = 'hidden';
    } 
    opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  }
 
  if(closing != null)
  {
		if(closing.style.display != 'hidden')
    {
      closing.style.overflow = 'hidden';
    } 
    closing.style.height = newClosedHeight + 'px';
  }
  setTimeout("animate(" + curTick + "," + timeLeft + ",'" + closingId + "','" + openingId + "')", 33);
}

  /************************
   * SCROLL DIV AUTOMATICO 
   ************************/
   
  var delayb4scroll=8000; //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
	var marqueespeed=1; //Specify marquee scroll speed (larger is faster 1-10)
	var pauseit=1; //Pause marquee onMousever (0=no. 1=yes)?
	
	var copyspeed=marqueespeed;
	var copyspeedmanual=1;
	var pausespeed=(pauseit==0)? copyspeed: 0;
	var actualheight='';
	var	lefttime="";
			
	var scrollStep=1;
	var timerUp="";
	var timerDown="";
	
	function scrollmarquee()
	{
		/*
		if ((parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
			&& ((parseInt(cross_marquee.style.top)>(actualheight+8)))) //if scroller hasn't reached the end of its height
		*/
		if (parseInt(cross_marquee.style.top)>(marqueeheight-(actualheight-8)))
		{
			cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"; //move scroller upwards
		}
		/*
		else //else, reset to original position
		{
			cross_marquee.style.top="0px";
			clearInterval(lefttime);
			setTimeout('lefttime=setInterval("scrollmarquee()",100)', delayb4scroll);
		}
		*/
	}
	
	function initializemarquee()
	{
		cross_marquee=document.getElementById("contents-contract-text");
		cross_marquee.style.top=0;
		marqueeheight=document.getElementById("contents-contract-text-container").offsetHeight;
		actualheight=cross_marquee.offsetHeight; //height of marquee content (much of which is hidden from view)
		if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1)
		{
			//if Opera or Netscape 7x, add scrollbars to scroll and exit
			cross_marquee.style.height=marqueeheight+"px";
			cross_marquee.style.overflow="scroll";
			return;
		}
		setTimeout('lefttime=setInterval("scrollmarquee()",100)', delayb4scroll);
	}
	
	function scrollDivUp(){
		copyspeed=pausespeed;
		if (parseInt(cross_marquee.style.top)<0) //if scroller hasn't reached the end of its height
		{
			cross_marquee.style.top=parseInt(cross_marquee.style.top)+(copyspeedmanual)+"px"; //move scroller upwards
		}
		timerUp=setTimeout("scrollDivUp()",20);
	}

	function scrollDivDown(){
		copyspeed=pausespeed;
		//if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8)) //if scroller hasn't reached the end of its height
		if (parseInt(cross_marquee.style.top)>(marqueeheight-(actualheight-8)))
		{
			cross_marquee.style.top=parseInt(cross_marquee.style.top)-(copyspeedmanual)+"px"; //move scroller upwards
		}
		timerDown=setTimeout("scrollDivDown()",20);
	}	
	
	function stopManualScroll(){
		clearTimeout(timerDown);
		clearTimeout(timerUp);
		copyspeed=marqueespeed;
	}
	
	
	/************************
   * VISUALIZZA VARIANTI
   ************************/
	
	view_var_popup_w = 560;
	view_var_popup_h = 620;

	function ViewVar(id, num)
	{
		OpenPopUp('colours_var.php?id=' + id + '&n=' + num, 'colours', view_var_popup_w, view_var_popup_h, 'yes');
		return false;
	}
