function Noticia(){
	var self = this;
	self.urlmatch = "cambia.php";
	//contenedor principal
	this.containerID = "noticecont";
	//contenedor dentro de contenedor principal, que es donde se escribe la noticia
	self.capaID = "spnotices";
	//velocidad en que se escriben las palabras
	this.intervalo = 30;
	//arreglo que va almacenar as peticiones AJAX
	this.http = new Array();
	//Tiempo en que se va a tardar en cambia de una palabra a otra
	this.tiempoEntrePalabras = 3500;
	//Arreglo que va a almacenar los titulos de las noticias
	this.arreglo = ["Este es el titulo de la noticia 1","Este es el titulo de la noticia 2","Este es el titulo de la noticia 3"];
	//
	this.pos = 0;
	this.handleIntervalo = null;
	this.indice = 0;
	this.isNewPhrase = false;
	this.popUp = function(URL) {
		day = new Date();
		id = day.getTime();
		ancho = 500;
		alto = 500;
		eval("page" + id + " = window.open(URL, '" + id + "');");
	}
	this.popUp2 = function(URL) {
		day = new Date();
		id = day.getTime();
		ancho = 500;
		alto = 500;
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+ancho+",height="+alto+"');");
	}
	self.loadExternalRSS =  function(){
		var peticionNota = new MyServer();
		peticionNota.url = self.urlmatch;
		peticionNota.vars = "pg=rssfrnotes";
		//prompt("",peticionNota.url + "?" + peticionNota.vars);
		self.arreglo =  new Array();
		self.indice=0;
		self.pos = 0;
		clearInterval(self.handleIntervalo);
		self.handleIntervalo = null;
		self.isNewPhrase = false;
		capa = document.getElementById(self.capaID); 
		capa.innerHTML = "Leyendo Notas RSS...";
		peticionNota.onFinish = function(){
			capa.innerHTML  = '';
			var response = peticionNota.responseXML;
			var items = response.getElementsByTagName('item');
			
			for(i=0;i<items.length;i++){
				obj = new Object();
				obj.titulo = (items[i].getElementsByTagName("title")[0].childNodes[0].data);
				obj.url = items[i].getElementsByTagName("link")[0].childNodes[0].data;
				obj.descripcion = items[i].getElementsByTagName("description")[0].childNodes[0].data;
				self.arreglo.push(obj);
			}
			self.Escribir(); 
		}
		peticionNota.doAction();

	}
	self.last = function(){
		try{
			clearInterval(this.handleIntervalo);
			capa = document.getElementById(self.capaID); 
			capa.innerHTML = "";
			if(this.indice == 0){
				this.indice = this.arreglo.length -1;
				this.pos = 0;
			}else{
				this.indice--;
				this.pos = 0;
			}
			if(!this.isNewPhrase){
				this.Escribir();
			}else{
				this.CambiarDePalabra();
			}
		}catch(ex){}
	}
	self.next = function(){
		try{
			clearInterval(this.handleIntervalo);
			capa = document.getElementById(self.capaID); 
			capa.innerHTML = "";
			if(!this.isNewPhrase){
				if(this.indice == this.arreglo.length){
					this.indice = 0;
					this.pos = 0;
				}else{
					this.indice++;
					this.pos = 0;
				}
				this.Escribir();
			}else{
				this.CambiarDePalabra();				
			}
		}catch(ex){}
	}
	self.ShowContainerImg = function(){
		var container = document.getElementById(self.containerID);
		imgs = container.getElementsByTagName("IMG");
		for(var i=0;i<imgs.length;i++){
			if(imgs[i].className == "Puntero"){
				imgs[i].style.visibility = "visible";	
			}	
		}
	}
	self.HideContainerImg = function(){
		var container = document.getElementById(self.containerID);
		imgs = container.getElementsByTagName("IMG");
		for(var i=0;i<imgs.length;i++){
			if(imgs[i].className == "Puntero"){
				imgs[i].style.visibility = "hidden";	
			}	
		}

	}
	self.Escribir = function(){
		var palabra = this.arreglo[this.indice].titulo;
		var url = this.arreglo[this.indice].url;
		var rssdesc =this.arreglo[this.indice].descripcion;
		capa = document.getElementById(self.capaID); 
		capa.setAttribute("title",rssdesc);
		caracter = palabra.charAt(this.pos);
		if(this.pos == 0){
			var selfObj = this;
			capa.onclick =  function(){
				self.popUp(url);
			}
			capa.style.cursor = "pointer";
		}
		capa.innerHTML += caracter;
		this.pos++;
		if(this.pos == palabra.length){
			this.indice++;
			this.pos = 0;
			this.isNewPhrase = true;
			
		}
		if(this.indice == this.arreglo.length){
			this.indice = 0;	
		}
		if(!this.isNewPhrase){
			this.handleIntervalo = setTimeout("oNoticia.Escribir()",this.intervalo);
		}else{
			this.HideContainerImg();
			this.handleIntervalo = setTimeout("oNoticia.CambiarDePalabra()",this.tiempoEntrePalabras);
		}
	}
	self.CambiarDePalabra =  function(){
		capa = document.getElementById(self.capaID); 
		capa.innerHTML = "";
		this.ShowContainerImg();
		this.isNewPhrase = false;
		oNoticia.Escribir();	
	}
}
var oNoticia = new Noticia();
//AgregarEventos(window,"load",oNoticia.loadExternalRSS);