
var list = new Array(); 
var tickerObj; 
var hex1 = 255;
var hex2 = 255;
var hex3 = 255;
var alpha=0;
var timer1;
var timer2;
var timer3;
var whereami=0;
var inpausa=0;
var divId=undefined;
var r=0;
var g=0;
var b=0;
var totalefigli=0;
var interval = 5; // interval in seconds
var fadeSpeed = 50;
function fadeText(divId,r,g,b) 
{

  if(tickerObj)
  {
    if(hex1>r || hex2>g || hex3>b) 
	{
	  if (hex1>r)	
		hex1-=3; // increase color darkness
	  if (hex2>g)
		hex2-=3;
	  if (hex3>b)
		hex3-=9;
	  var nodellitesto = tickerObj.getElementsByTagName("p");
	  for (var i=0; i<nodellitesto.length; i++) 
	  {
		nodellitesto[i].style.color="rgb("+hex1+","+hex2+","+hex3+")";	
	  }
	//  nodellitesto.style.color="rgb("+hex1+","+hex2+","+hex3+")";	
      //tickerObj.style.color="rgb("+hex1+","+hex2+","+hex3+")";
      timer3=setTimeout("fadeText('" + divId + "',"+r+","+g+","+b+")", fadeSpeed); 
    } 
	else
	{
      hex1=255;
	  hex2=255;
	  hex3=255; //reset hex value
	}
  }
}
function fadeDiv(divId,alpha)
{
  if(tickerObj)
  {
	tickerObj.style.filter="alpha(opacity="+alpha*100+")";
	tickerObj.style.opacity=alpha;
	//tickerObj.style.-moz-opacity=alpha;
	alpha+=0.1;
	if (alpha<1)
	timer1=setTimeout("fadeDiv('" + divId + "',"+alpha+")", fadeSpeed); 
  }
}

function initialiseList(DIVID,RR,GG,BB) 
{
  totalefigli=0;
  r=RR;
  g=GG;
  b=BB;
  tickerObj = document.getElementById(DIVID);
  if(!tickerObj)
    reportError("Could not find a div element with id \"" + DIVID + "\"");
  else divId=DIVID;
	var listaprovv = new Array;
  listaprovv = tickerObj.childNodes;
  if(listaprovv.length <= 0)
    reportError("The div element \"" + divId + "\" does not have any children");
	var c=0;
  for (var i=0; i<listaprovv.length; i++) 
  {
      var node = listaprovv[i];
	if (node.nodeType=="1")
	{
		node.style.display = "none"; 
		list[c]=listaprovv[i];
		c++;
		totalefigli++;
	}
	/*else  
		if (listaprovv[i].nodeType == 3)
			tickerObj.removeChild(listaprovv[i]);
	*/		
//	alert(list[i]);
	//if (list[i].nodeType == 3 && !/\S/.test(list[i].nodeValue)) 
    //    tickerObj.removeChild(list[i]);
  }
//  alert("TOT: "+totalefigli);
//  alert("inpausa= "+inpausa+" whereami= "+whereami+"")
  if (inpausa)
    run(whereami,r,g,b);
  else
    run(0,r,g,b);
}
function AvantiDiUno()
{
//  alert("TOTAVA: "+whereami);
  PausaFader();
  whereami+=1;
  if (whereami>(totalefigli-1))
      whereami=0;
  run(whereami,r,g,b);
}
function IndietroDiUno()
{
//  alert("TOTIND: "+whereami);
  PausaFader();
  whereami-=1;
  if (whereami<0)
    whereami=(list.length-1);
  run(whereami,r,g,b);
}
function run(count,r,g,b,intervallo) 
{
 // fadeText(divId,r,g,b);
   fadeDiv(divId,alpha);
  list[count].style.display = "block";
  var tramezzo=interval*1000;
//  if(count > 0)
//    list[count-1].style.display = "none";
//  else
//    list[list.length-1].style.display = "none";
  for (var i=0; i<list.length; i++)
  {
    if (count!=i)
      list[i].style.display = "none";
  }

  whereami=count;
  count++;
  if(count == list.length || count>list.length)
    count = 0;
  if (intervallo && intervallo!=undefined && intervallo!=null)
      tramezzo=intervallo;
  timer2=window.setTimeout("run("+count+","+r+","+g+","+b+")", tramezzo);
}
function reportError(error) 
{
//  alert("The script could not run because you have errors:\n\n" + error);
  return false;
}
function StoppaFader()
{
    if (timer1)
	    clearTimeout(timer1);
    if (timer2)	
	    clearTimeout(timer2);
    if (timer3)	
	    clearTimeout(timer3);		
    if (tickerObj)
    {
      tickerObj.style.opacity=100;
    }
    inpausa=0;	
    r=g=b=count=whereami=0;
    divId=null;
}
function PausaFader()
{
    if (timer1)
	    clearTimeout(timer1);
    if (timer2)	
	    clearTimeout(timer2);
    if (timer3)	
	    clearTimeout(timer3);		
    if (tickerObj)
    {
      tickerObj.style.opacity=100;
    }
    inpausa=1;	    
}


//-->
