var det = false;				//inicialzio que no está paraado...
var desp = 1;					//el desplazamiento en pixeles del texto
var refresco = 50;				//tiempo en refrescarse el scroll (en milisegundos)
var tiempo;						//para controlar la pausa
var TotalDivsToScroll;			//los divs que se han creado para que siempre se vea texto..
var LastDiv;					//ultimo div que se pinta


function noticia(titular,texto,fecha,enlace,destino)
{
	this.titular = titular;
	this.texto = texto;
	this.fecha= fecha;
	this.enlace = enlace;
	this.destino = destino;
}



function TextoScroll(container)
{	
	DivVisible = document.createElement('div');
	DivVisible.className = 'StyleDivVisible';
	//DivVisible.setAttribute('onmouseover','PauseScroll()');
	//DivVisible.setAttribute('onmouseout','PlayScroll()');
	
	//lo inserto en el container que le diga...
	container = document.getElementById(container);
	container.appendChild(DivVisible);	
	
	ok=0;
	do
	{		
		ID = 'DivAll'+ok;
		
		DivAll = document.createElement('div');
		DivAll.id = ID;
		DivAll.className = 'StyleDivAll';
		
		for(i=0; i<noticias.length; i++)
		{
			href = document.createElement('a');
			href.href = noticias[i].enlace;
			href.className = 'hrefSyle';
			
			div  = document.createElement('div');
			div.className = 'StyleDivComentari';
			
			titular = document.createElement('span');	
			titular.className = 'titular';			
			txt = document.createTextNode(noticias[i].titular);
			titular.appendChild(txt);
			div.appendChild(titular);
			/*
			fecha = document.createElement('span');	
			fecha.className = 'fecha';
			txt = document.createTextNode(noticias[i].fecha);
			fecha.appendChild(txt);
			br = document.createElement('br');
			fecha.appendChild(br);
			div.appendChild(fecha);
			*/
			texto = document.createElement('span');	
			texto.className = 'texto';
			txt = document.createTextNode(noticias[i].texto);
			texto.appendChild(txt);
			//br = document.createElement('br');
			//texto.appendChild(br);
			div.appendChild(texto);
			
			/*
			enlace = document.createElement('a');
			enlace.href = "http://www.yahoo.es";
			enlace.className = 'enlace';
			txt = document.createTextNode(noticias[i].enlace);
			enlace.appendChild(txt);
			div.appendChild(enlace);
			*/
			
			href.appendChild(div);
			DivAll.appendChild(href);
			
			separate = document.createElement('div');
			separate.className = 'StyleDivSeparacio';
			DivAll.appendChild(separate);
		}
	
		DivVisible.appendChild(DivAll);
		
		ok++;		
		if( ((ok==1) && (DivAll.offsetHeight < DivVisible.offsetHeight)) || ((ok>=2) && (DivAll.offsetHeight * ok > DivVisible.offsetHeight)) )
		{
			TotalDivsToScroll=ok;
			LastDiv=TotalDivsToScroll-1;
			ok=0;
		}
	}while(ok);
	
	//situo las posiciones de los divs creados...
	for(i=0; i<TotalDivsToScroll; i++)
	{
		name = 'DivAll'+i;
		el = document.getElementById(name);		
		
		if(i>0)
		{
			posAux = el.offsetHeight*i;
			el.style.top = posAux + "px";
		}
		else		
			el.style.top = 0 + "px";
	}
	
	//inicio de la función...
	if(TotalDivsToScroll>1)
		ActionScroll();
}

function ActionScroll()
{
	if(det)
		return;

	for(i=0; i<TotalDivsToScroll; i++)
	{
		name = 'DivAll'+i;
		el = document.getElementById(name);
		pos = el.style.top;		
		pos = pos.replace(/px/,"");
		pos = pos.replace(/pt/,"");
		pos = new Number(pos);
		pos -= desp;
	
		el.style.top = pos + "px";
		
		if( (pos+el.offsetHeight)<=0 )
		{
			nameAux = 'DivAll'+LastDiv;
			elAux = document.getElementById(nameAux);
			posAux = elAux.style.top;		
			posAux = posAux.replace(/px/,"");
			posAux = posAux.replace(/pt/,"");
			posAux = new Number(posAux);			
			posAux += elAux.offsetHeight;
			posAux -= desp;		
			el.style.top = posAux + "px";
			LastDiv = i;
		}
	}
	tiempo = window.setTimeout('ActionScroll()',refresco);
}


function PauseScroll()
{
	det = true;
	clearTimeout(tiempo);
}

function PlayScroll()
{
	det = false;
	clearTimeout(tiempo);
	ActionScroll();
}


