
var miTimer;
var estaActivo=false;
var mover=true;
var velocidad=100;
var recorrido=1;
var objTicketer=null;
var altoTicketer=0;
var altoNoticias=166;
var urlConsulta="http://blogs.myspace.com/Modules/BlogV2/Pages/RssFeed.aspx?friendID=64574486";
//var urlConsulta="http://www.centrosocialcaixanova.com/nt/blog/?feed=rss2";

function rss_getHTTPObject() {
	var xhr = false;
	if(window.XMLHttpRequest) {
		var xhr = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		try {
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				var xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
			xhr = false;
	
		}	
	
	}
	
	}
	return xhr;//return the value of xhr
}

function ticketerOn(){

	objTicketer=document.getElementById("blog_content");
	document.getElementById("celda_blog_content").style.backgroundImage="url(imagenes/ajax-loader.gif)";
	document.getElementById("celda_blog_content").style.backgroundRepeat="no-repeat";	
	mover=false;
	objTicketer.innerHTML="";
	cargarXML()
}
function cargarXML(){
	var reqRSS = rss_getHTTPObject();
	reqRSS.open("get","crossSite.php?url="+urlConsulta,true);
	reqRSS.onreadystatechange=function (){
		if(reqRSS.readyState!=4)return;
		objXML = reqRSS.responseXML
		datos = objXML.getElementsByTagName("item");
		if(datos.length>0){
			document.getElementById("celda_blog_content").style.backgroundImage="none";
			for(i=0;i<datos.length;i++){
				titulo = datos[i].getElementsByTagName("title")[0].firstChild.data;
				enlace = datos[i].getElementsByTagName("link")[0].firstChild.data;
				descripcion = datos[i].getElementsByTagName("description")[0].firstChild.data;
				fecha = datos[i].getElementsByTagName("pubDate")[0].firstChild.data;
				creaDivDeNodo(titulo,descripcion,enlace,fecha);
			}
		}
		else{
			document.getElementById("celda_blog_content").style.backgroundImage="none";
			objTicketer.innerHTML="<b>No se pudieron recuperar datosXML</b>";
			objTicketer.innerHTML="<p>Posiblemente el sitio web se encuentre sin conexión</p>";
		}
	};
	reqRSS.send(null);
}

				
				
function creaDivDeNodo(titulo,descripcion,enlace,fecha){
	var midiv= document.createElement("div");
	midiv.setAttribute("class","nodo_rss")
	var atitulo = document.createElement("a");
	atitulo.setAttribute("class","titulo");
	atitulo.setAttribute("target","_blank");
	atitulo.setAttribute("href",enlace)	;
	atitulo.innerHTML=titulo;
	
	var spandesc = document.createElement("span");
	spandesc.setAttribute("class","descripcion")
	spandesc.innerHTML=procesaFecha(fecha);

	var imgsep = document.createElement("img");
	imgsep.setAttribute("src","imagenes/separador_blog.gif");
	imgsep.setAttribute("width","495");	
	imgsep.setAttribute("height","2");		
	
	midiv.appendChild(atitulo);
	midiv.appendChild(spandesc);
	midiv.appendChild(imgsep);	
	objTicketer.appendChild(midiv);
	
/*	midiv.onmouseover = function(){
		this.style.backgroundColor="#ddd";
	}
	midiv.onmouseout = function(){
		this.style.backgroundColor="";
	}
	midiv.onclick = function(){
		window.open(enlace);
	}*/
	

}

function procesaFecha(lafecha){
	var objFecha = new Date(lafecha);	
	var meses= new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
	var dias = new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","S&aacute;bado");
	//				$fechatexto= $dias[date('w',$fecha)].", ".date('d',$fecha)." de ".$meses[date('n',$fecha)]." del ".date('Y',$fecha)." ".date('H:i',$fecha);
	
	var horas=objFecha.getHours();
	var minutos=objFecha.getMinutes();
	if(horas<10)horas="0"+horas;
	if(minutos<10)minutos="0"+minutos;	
	
	var cadenaFecha=dias[objFecha.getDay()]+", "+objFecha.getDate()+" de "+meses[objFecha.getMonth()]+" de "+objFecha.getFullYear()+" "+horas+":"+minutos;
	return cadenaFecha;
}
