var idsSeccionesDeportes = new Array();

var noticiasRSSDeportes = new Array();

function inicializarDeportes()
{
	idsSeccionesDeportes[1] = "6";
	idsSeccionesDeportes[2] = "11";
	idsSeccionesDeportes[3] = "47";
	idsSeccionesDeportes[5] = "11";
	idsSeccionesDeportes[6] = "12";
	idsSeccionesDeportes[9] = "11";
	idsSeccionesDeportes[10] = "12";
	idsSeccionesDeportes[11] = "11";
	idsSeccionesDeportes[12] = "11";
	idsSeccionesDeportes[13] = "10";
	idsSeccionesDeportes[15] = "8";
	idsSeccionesDeportes[16] = "11";
	idsSeccionesDeportes[17] = "7";
	idsSeccionesDeportes[18] = "3";
	idsSeccionesDeportes[31] = "1";
	idsSeccionesDeportes[32] = "19";
	idsSeccionesDeportes[33] = "15";
	idsSeccionesDeportes[40] = "14";
}

function cargarXMLDeportes(idPortal, entorno)
{	
	var url = "";
	if(entorno=="PRE")
		url = "/elementosInt/rss/rss_"+idsSeccionesDeportes[idPortal]+".xml";
	else 
		url = "/elementosInt/rss/"+idsSeccionesDeportes[idPortal];
		
	var iterador = 0;

	$.ajax({  
		type: "GET", 
		async:false,
		ifModified:true,
		contentType: "application/x-www-form-urlencoded;charset=UTF-8",
		url: url +"?"+ Math.random(), 			 	
		dataType: "xml",
		success: function(xml) {		
			$(xml).find('item').each(function(){
				var noticia = new Array();
				$(this).find('title').each(function(){
					noticia['title'] = $(this).text();
				});
				$(this).find('link').each(function(){
					noticia['link'] = $(this).text();
				});
				$(this).find('description').each(function(){
					noticia['description'] = $(this).text();
				});
				$(this).find('enclosure').each(function(){
					noticia['enclosure'] = $(this).attr('url');
				});
				
				noticiasRSSDeportes[iterador] = noticia;
				iterador++;
				noticia = null;
			});
		}
	});   
}

function generaDeportesED(idPortal, ruta, entorno)
{
	inicializarDeportes();
	cargarXMLDeportes(idPortal, entorno);
	
	var html = "";
	var noticia = null;
	var elemento = null;
	
	html = html + "<div class=\"cuadroDeportes\">\n";
									      
	html = html + "<h2><img src=\""+ruta+"comun/img/triangu_deporte.gif\" alt=\"Deportes\" title=\"Deportes\" > noticias deportes</h2>\n";
	html = html + "<div class=\"icono\"><img border=\"0\" src=\""+ruta+"comun/img/reloj_icono.png\"></div>\n";
	html = html + "<div class=\"borde\"></div>\n";
	html = html + "<div class=\"cuerpoDeportes\">\n";
	html = html + "<table>\n";
	
	for(var i=0;i<noticiasRSSDeportes.length;i++)
	{
		noticia = noticiasRSSDeportes[i];
		
		html = html + "<tr>\n";
		html = html + "<td>\n";
		
		elemento = noticia['enclosure'];
		if(elemento!=null && elemento!='undefined')
			html = html + "<div class=\"avatar\"><img border=\"0\" src=\""+elemento+"\"></div>\n";
		html = html + "<span><a href=\""+noticia['link']+"\" target=\"_blank\">"+noticia['title']+"</a></span><br>\n";
		html = html + noticia['description']+"\n";
		html = html + "</td>\n";
		html = html + "</tr>\n";
	}

	html = html + "</table>\n";
	html = html + "</div>\n";
	html = html + "</div>\n";
	
	document.write(html);
}

