//variable global


var i=1;

// i = Math.random() * 10;
// i = Math.round(i) ;
//URI: URL of RSS 2.0 (works with WordPress)
var URI = '/Ng.GlobalWeb.2/Misc/int/livecurious/blog.aspx';
//function: llamarasincrono('URI', 'div-id',i);
llamarasincrono(URI, 'rss',i);
// This function loads the info
function llamarasincrono(url, id_contenedor,N){
	var pagina_requerida = false
	if (window.XMLHttpRequest) {// if Mozilla, Safari etc
		pagina_requerida = new XMLHttpRequest()
	} else if (window.ActiveXObject){ // but if IE
		try {
			pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){ // in case it is an older version
			try{
				pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	} else
		return false
	pagina_requerida.onreadystatechange=function(){ // response function
		cargarpagina(pagina_requerida, id_contenedor,N)
	}
	pagina_requerida.open('GET', url, true) // assign open and send methods
	pagina_requerida.send(null)
}
// Everything is correct and it is time to put the required information
// The web site in xhtml
function cargarpagina(pagina_requerida, id_contenedor,N){
	if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1)){
		//responseXML property use: the server returns data as XML document
		var xml = pagina_requerida.responseXML;
		//total items found in RSS
		var limit = xml.getElementsByTagName('item').length;
		i = Math.random() * limit;
		i = Math.round(i) ;
		//Button "Next"
		//i is the variable that will increase
		var next = "";
		//string where will we create the labels and values
		var rss = "";
		//for 2 cycles to show 2 inputs at once
	//	for (var l=N;l<=N+1;l++){
		for (var l=N;l<=N;l++){// is modified for one only cycle
			//we take the title of the first item, then the second, and so ...
			var titlebig = xml.getElementsByTagName('description').item(l).firstChild.data;
			//alert(title);
			var titlearray = titlebig.split('strong>');
			
			var title = titlearray[1].replace(">","").replace("</","");
			//alert(title);
			//var url = xml.getElementsByTagName('link').item(l).firstChild.data;
			//var pubDate = xml.getElementsByTagName('pubDate').item(l).firstChild.data;
			//var description = xml.getElementsByTagName('description').item(l).firstChild.data;
			//if the length of the input is greater than 200 characters in the cut and we put a link
			//if(description.length>200) { description = description.substr(0,200)+"...<br/><enlace><a href=\""+url+"\"></a></enlace><br/><br/>"; }else description=description+"<br/><br/>";
			//alert(titlearray[2].length);
			description = titlearray[2].substring(0,titlearray[2].length-1);
			//this is to cut the date +0000 WordPress
			//var date = pubDate.split(" +");
			//join our string variables
		
			rss = rss+"<div class='queries'><strong>"+title+"</strong><br><descripcion>"+description+"</descripcion></div>";
			if (limit==l)
			//if we pass the limit, the cut
				break;
		}
		//increased the global variable
		i=i+2;
		//if we pass the limit, we start
		if (i>limit)
			//	i=1;
			i = Math.random() * limit;
			i = Math.round(i) ;
			//we put the string + button in the corresponding div-id
			//document.getElementById(id_contenedor).innerHTML=rss+next;
			$('#'+id_contenedor+'').html(next+rss)
			//a little message to say he is loading info
		}else if (pagina_requerida.readyState == 1)
			//document.getElementById(id_contenedor).innerHTML="<load>Loading...</load>"
			$('#'+id_contenedor+'').html("<div class='load'>Loading...</div>")
		}
