var step_time = 50 ; //tempo entre a escrita das letras
var step = true ; //flag do step time
var freeze_time = 3200 ; //tempo para troca do texto
var indice_qt_texto = 0 ; //indice da qt de textos disponiveis
var texto_qt = texto.length - 1 ; //qt de textos disponiveis para rolagem
var fim;

if(texto.length > 0)
	fim = texto[indice_qt_texto].length ; //fim do texto corrente
else
	fim = texto.length;
	
var indice_texto = 0 ; //indice do texto corrente
var limite = 55 // limite do tamanho do texto
f = false
//executamos duas vezes para adequar o tamanho da frase com os ...
for (i=0;i<=texto.length - 1;i++)
{
	texto[i] = texto[i].replace(/\&quot;/gi,'"');
	fim = texto[i].length;
	if (fim > limite)
	{
	fim = limite
	texto[i]=texto[i].substring(0,limite);		texto[i]=texto[i].substring(0,texto[i].lastIndexOf(' ')) + '...';
	texto[i]=texto[i].substring(0,limite);
	texto[i]=texto[i].substring(0,texto[i].lastIndexOf(' ')) + '...';
	}
}

if(texto.length > 0)
	fim = texto[indice_qt_texto].length;
else
	fim = texto.length;
	
//funcao responsavel por limpar os textos anteriores e continuar a escrita
function time()
{
	step = true ;
	child = document.getElementById('ticker_text').lastChild ;
	document.getElementById('ticker_text').removeChild( child ) ;
	ticker() ;
}
//funcao responsavel por escrever o texto do ticker
function ticker()
{

	// atribui valor ao link corrente
	document.getElementById('ticker_link').setAttribute( "href" , link[indice_qt_texto]);
	// escreve o texto apresentado letra a letra no objeto TextNode
	if (indice_texto == fim)
	{
		str = document.createTextNode( texto[indice_qt_texto].substring(0, indice_texto) );
		f = true
	}
	else
		str = document.createTextNode( texto[indice_qt_texto].substring(0, indice_texto) + '_' );
	//acrescenta TextNode ao div
	document.getElementById('ticker_text').appendChild( str ) ;
	indice_texto ++ ;
	//controle do final de um texto
	if (f)
	{
		f = false
		//reinica indice do texto corrente
		indice_texto = 0 ;
		//passa para o proximo texto
		indice_qt_texto ++ ;
		//caso textos tenham acabado, reinicie
		if (indice_qt_texto > texto_qt)
			indice_qt_texto = 0 ;
		//recalcula o final do texto corrente
		fim = texto[indice_qt_texto].length	;
		window.setTimeout( 'time()' , freeze_time ) ;
		step = false ;
	}
	if (step)
		window.setTimeout( 'time()' , step_time ) ;
}

window.onload=function(){ticker()}
