var forosmap ={
	cargaXML: function() {
		$.ajax({
			type: "GET",
			url: "/rssforo/rss.php?"+Math.round(Math.random()*1000),
			dataType: "xml",
			success: function(xmlData)
			{
				xmlDataSet = xmlData;
				forosmap.browseXML();
				$('#screen p').ToolTip(
					{
						className: 'tooltip',
						position: 'mouse',
						delay: 100
					}
				);
				rows = $("#screen > p");
				for(i = 0; i < rows.length; i++){          
			     	if(i % 2 == 0){
			       		rows[i].style.background = "#ddd";
			     	}else{
			       		rows[i].style.background = "#eee";
			     	}      
			   	 }
			}
		});
	},
	browseXML: function(){
		strToAppend = ""; 
		$("topic", xmlDataSet).each(function(k){
			topic = $("topic:eq("+ k +")", xmlDataSet);
			nomClass = topic.attr("tipo").toLowerCase();
			  nomClass = nomClass.replace(/[Ã¡Ã Ã¤Ã¢Ã¥]/g, 'a');
			  nomClass = nomClass.replace(/[Ã©Ã¨Ã«Ãª]/g, 'e');
			  nomClass = nomClass.replace(/[Ã­Ã¬Ã¯Ã®]/g, 'i');
			  nomClass = nomClass.replace(/[Ã³Ã²Ã¶Ã´]/g, 'o');
			  nomClass = nomClass.replace(/[ÃºÃ¹Ã¼Ã»]/g, 'u');
			  nomClass = nomClass.replace(/[Ã½Ã¿]/g, 'y');
			  nomClass = nomClass.replace(/[Ã±]/g, 'n');
			  nomClass = nomClass.replace(/[Ã§]/g, 'c');
			  nomClass = nomClass.replace(/['"]/g, '');
			  nomClass = nomClass.replace(/[^a-zA-Z0-9-]/g, ' ');
			  nomClass = nomClass.replace(/\s+/g, '_');
			  nomClass = nomClass.replace(/(_)$/g, '');
			  nomClass = nomClass.replace(/^(_)/g, '');
			
			numResp = topic.attr("respuestas");
			if(numResp >= 200){
				numResp = 120;
			}else if(numResp >= 100){
				numResp = 90;
			}else if (numResp <=40){
				numResp = 40;
			}else if (numResp <= 100){
				numResp = topic.attr("respuestas");
			}

			segundos = topic.attr("fechacreacion");
			horas = segundos / (60 * 60);
			horas = Math.floor(horas);
			dias = segundos / (60 * 60 * 24);
			dias = Math.floor(dias);

			if(horas >= 24){
			    time = dias +' dias';
			}else if(horas > 0){
			    time = horas +' horas';
			}


			strToAppend += '<p> <a style="font-size:'+numResp+'em;" class="' + nomClass +'"  href="'+ topic.text() +'">' + topic.attr("titulo") +'</a>';
			strToAppend += ' <strong>('+ topic.attr("respuestas") +' mensajes)</strong>';
			strToAppend +='</p>';
			
			
		});
		strToAppend +='</div>';
		$("#screen").html(strToAppend);
		var newsitems;
        var curritem=0;
		newsitems = $("#screen > p").hide().size();
		$("#screen > p:first").show();
		setInterval(ticknews, 2000);
		function ticknews() {
			curritem = ++curritem%newsitems;
			$("#screen > p:eq("+ curritem +")").insertBefore($("#screen > p:eq(0)")).slideDown("fast");
		 }		
		
	}
}
$(window).ready(forosmap.cargaXML);

