var feedsCargados = 0;
var host_name = window.location.hostname;

var urls = 	[
				{url:"http://feeds.feedburner.com/electronicIntifada",nodos:4},
				{url:"http://feeds.feedburner.com/palsolidarity",nodos:5},
			 	{url:"http://"+host_name+"/com/licuit/consultas.cfc?method=getAsRss&tabla=noticias",nodos:4}  //cambiar por la direccion de mewando
			];

function cargarFeeds(){
	if(feedsCargados >= urls.length){
		feedsCargados = 0;
		return;
	}
	
	if(feedsCargados == 0){
		for(var a = 1; a <= urls.length; a++ ){
			cargandoPanel("panel" + a);
		}
	}
	
	obtenerFeed(urls[feedsCargados].url,urls[feedsCargados].nodos);
}

function obtenerFeed(url,nodos){
	var consulta = new feeds();
	consulta.setCallbackHandler(feedRecibido);
	consulta.setErrorHandler(feedNoRecibido);
	consulta.getFeedBurner(url,nodos);
}

function feedRecibido(datos){
	rellenaPanel("panel" + (feedsCargados + 1),datos);
	feedsCargados++;
	cargarFeeds();
}

function feedNoRecibido(datos){
	alert("error loading feed")
}

function cargandoPanel(panel){
	var obj = document.getElementById(panel);
	obj.innerHTML = '<div id="cabecera_rss" style="margin-bottom:20px;"><img src="/images/general/rss.jpg" style="margin-left:5px; margin-top:3px; margin-right:5px;  margin-bottom:3px; " /><span style="vertical-align:.9ex;*vertical-align:.5ex">Cargando...</span></div>';
}

function rellenaPanel(panel,datos){
		
	var obj = document.getElementById(panel);
	obj.innerHTML = cabeceras[panel];
	
	for(var a = 1; a <= urls[feedsCargados].nodos; a++){
		if(datos.length < a)
			break;
		
		var noticia = '<div class="noticia">';
		
		noticia += '<h5 style="padding-left:5px;">';
		noticia += datos[a-1].FECHA;
		noticia += '</h5>';
		noticia += '<div class="espacio3"></div>';
		noticia += '<h3 class="titular">';
		noticia += datos[a-1].TITULO;
		noticia += '</h3>';
		noticia += '<h3 class="contenido_noticia" >';
		noticia += datos[a-1].DESCRIPCION;
		noticia += '</h3>';
		noticia += '<span class="ampliar"><a href="';
		noticia += datos[a-1].ENLACE;
		noticia += '" target="_blank" >[ + ]</a></span>';
		noticia += '</div>';
		noticia += '<div class="espacio3"></div>';

		
		obj.innerHTML += noticia;
	}
}

var cabeceras = new Object;
cabeceras.panel1 = '<div id="cabecera_rss"><img src="/images/general/rss.jpg" style="margin-left:5px; margin-top:3px; margin-right:5px;  margin-bottom:3px; " /><span class="link_rss" style="vertical-align:.9ex;*vertical-align:.5ex">feed: <a href="http://www.electronicIntifada.net" target="_blank">electronicintifada.net </a></span></div>';

cabeceras.panel2 = '<div id="cabecera_rss"><img src="/images/general/rss.jpg" style="margin-left:5px; margin-top:3px; margin-right:5px;  margin-bottom:3px; " /><span class="link_rss" style="vertical-align:.9ex;*vertical-align:.5ex">feed: <a href="http://www.palsolidarity.org" target="_blank">palsolidarity.org </a></span></div>';

cabeceras.panel3 = '<div id="cabecera_rss"><img src="/images/general/rss.jpg" style="margin-left:5px; margin-top:3px; margin-right:5px;  margin-bottom:3px; " /><span style="vertical-align:.9ex;*vertical-align:.5ex">Mewando</span></div>';