/***************************************************************************
*** MARQUEE ****************************************************************
*** REQUIRE PROTOTYPE ******************************************************
*** By Pablo Alberto Rodríguez Guerrero ************************************
***************************************************************************/


function marquee(objetName, content, cross_marquee, divAux, msgIni,marqueewidth, marqueeheight, marqueespeed, pauseit){

this.objetName=objetName;

this.content=content; //Div contenedor
this.cross_marquee=cross_marquee; // Div deslizante
this.divAux=document.getElementById(divAux); // Div auxiliar de contenido de datos (AJAX)
this.msgIni=msgIni;


this.marqueewidth=marqueewidth;//Specify the marquee's width (in pixels)
this.marqueeheight=marqueeheight;//Specify the marquee's height
this.marqueespeed=marqueespeed; //Specify the marquee's marquee speed (larger is faster 1-10)
this.pauseit=pauseit; //Pause marquee onMousever (0=no. 1=yes)?

this.marqueespeed=(document.all)? this.marqueespeed : Math.max(1, this.marqueespeed-1); //slow speed down by 1 for NS
this.copyspeed=this.marqueespeed;
this.pausespeed=(this.pauseit==0)? this.copyspeed: 0;

this.ns_marquee=document.getElementById(this.content);
this.cross_marquee=document.getElementById(this.cross_marquee);

this.actualwidth=this.cross_marquee.offsetWidth;

this.populate = function (){

	//ns_marquee	
	this.ns_marquee.style.width=this.marqueewidth;
	this.ns_marquee.style.height=this.marqueeheight;

	//cross_marquee	
	this.cross_marquee.style.left=parseInt(this.marqueewidth)+8+"px";
	this.cross_marquee.innerHTML="<nobr>" + this.msgIni + "</nobr>";
	this.actualwidth=this.cross_marquee.offsetWidth;
	
	lefttime=setInterval(this.objetName + ".scrollmarquee()",20);
}


this.scrollmarquee = function (){

	if (parseInt(this.cross_marquee.style.left)>(this.actualwidth*(-1)+8)){
		this.cross_marquee.style.left=parseInt(this.cross_marquee.style.left)-this.copyspeed+"px";
	
	}else{ 
		this.load2Marquee(this.cross_marquee, this.divAux);
		this.actualwidth= this.cross_marquee.offsetWidth;
		this.cross_marquee.style.left=parseInt(this.marqueewidth)+8+"px";
	}	

}


this.getMarquee = function (page_action, DIV, DIV2, objetName) {	
		
	var opciones = {
		asynchronous:true,
		frequency: 10,
		onSuccess: function(t) {
		datos = eval(t.responseText);
		eval(objetName + ".displayMarquee(datos,DIV);");
		}
	}
	
	new Ajax.PeriodicalUpdater(DIV2, page_action, opciones);
}


this.displayMarquee = function (datos, DIV) {
		
	msg="&nbsp;&nbsp;&nbsp;&nbsp;";

	for (var i=0; i < datos.length; i++) {
		dato = datos[i];
		msg=msg + "<a class=\""+ dato.css +"\" href=\""+ dato.url +"\">" + dato.msg + " </a>&nbsp;&nbsp;&nbsp;&nbsp;";
	}
	
	document.getElementById(DIV).innerHTML='<nobr>' + msg + '</nobr>';

}


this.load2Marquee = function (DIV1, DIV2){
	
	DIV1.innerHTML= DIV2.innerHTML;

}

}




