var size =[430,150]; 		// dimensione scroller (larghezza x altezza in pixel)
var speed = 6;				// velocità di cambio della news (da 1 in su)
var speedPause = 1;			// altro parametro per la velocità (da 1 in su)
var pause=6;				// secondi in cui rimane visibile una news
var direction = 'sx';		// direzionde di scorrimento (dx o sx)
var autoScroll = true;		// Attiva lo scorrimento automatico delle news
var ciclo = 0;

// Script vero e proprio
var actualNews='0',y,scrollDiv=null;
init=function(divGeneral)
{
	var cont=getElem(divGeneral);
	cont.style.width=size[0]+'px';
	cont.style.height=size[1]+'px';
	var txtContent=document.createElement('div');
	txtContent.setAttribute('id','textContent');
	txtContent.style.width=size[0]+'px';
	txtContent.style.height=size[1]-20+'px';
	txtContent.innerHTML='<div class="scrollDiv" id="'+divGeneral+'scroll">'+newsList[0]+'</div>';
	cont.appendChild(txtContent);
	var pageDiv=document.createElement('div');
	pageDiv.setAttribute('id','pageDiv');
	pageDiv.style.paddingTop='1px'; //size[1]-19
	var pagine='';
	for (var t=1;t<=newsList.length;t++)
	{
		pagine+='<input type="button" value="'+t+'" id="'+t+'" onclick="return clickPage(this)" />';
	}
	pageDiv.innerHTML=pagine;
	cont.appendChild(pageDiv);		
	cont.style.visibility='visible';
	if(speed<=0)
	{
		speed=1;
	}
	if(pause<=0)
	{
		pause=1;
	}
	scrollDiv=getElem(divGeneral+'scroll');
	buttonSel(document.getElementById('1'));
	if(autoScroll)
	{
		timeout=setTimeout('changeNews()',pause*1000);
	}
}

getElem=function (div) 
{
	return document.getElementById ? document.getElementById(div) : document.all[div];
}

clickPage=function(button)
{
	button.blur();
	if (actualNews==button.value-1)
	{
		return false;
	}
	clearCiclo();
	showNewNewsIntro(button.value-1);
	return false;
}

changeNews=function()
{
	y=0;
	ciclo=setInterval('hideNews()',1*speedPause);
	return false;
}
	
hideNews=function()
{
	scrollDiv.style.left=(direction=='dx')?y+'px':'-'+y+'px';
	y+=speed;
	if(y>=size[0])
	{
		clearCiclo();
		showNewNewsIntro();
	}
}
					
showNewNewsIntro=function()
{	
	clearCiclo();
	var page=null;
	if(showNewNewsIntro.arguments.length>0)
	{
		page=showNewNewsIntro.arguments[0];
	}
	else
	{
		page=(actualNews<newsList.length-1)?eval(actualNews+1):0;
	}
	scrollDiv.innerHTML=newsList[page];
	y=(direction=='dx')?-size[0]:size[0];
	actualNews=page;
	buttonSel(document.getElementById(eval(actualNews+1)));
	scrollDiv.style.left=y+'px';
	ciclo=setInterval('showNewNews()',1*speedPause);
}

showNewNews=function()
{
	y=(direction=='dx')?y+speed:y-speed;
	scrollDiv.style.left=y+'px';

	var lim=(direction=='dx')?-y:y;
	if(lim<speed)
	{
		clearCiclo();
		scrollDiv.style.left='0px';
		if(autoScroll)timeout=setTimeout('changeNews()',pause*1000);
	}
}

clearCiclo=function()
{
	if(typeof(ciclo)!="undefined")
	{
		clearInterval(ciclo);
	  	if(typeof(timeout)!="undefined")
	  	{
	  		clearTimeout(timeout);
	  	}
	}
}

buttonSel=function(button)
{
	for (var f=1;f<=newsList.length;f++)
	{
		document.getElementById(f).className="nonSelezionato";
	}
	button.className="selezionato";
}