
var diaArray = new Array('Domingo', 'Lunes', 'Martes', 'Mi&eacute;rcoles', 'Jueves', 'Viernes', 'S&aacute;bado', 'Domingo');
var mesArray = new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
var profundidad = 100; 
var act = '0';

$(document).ready(function() {

	$("#loading").show();
	
	cargaContenidos();

	function cargaContenidos(){

		cargaDatos("http://www.veo.es/estaticas/xml/portada_elmundo.xml", "elmundo");
		cargaDatos("http://www.veo.es/estaticas/xml/portada_marca.xml", "marca");
		cargaDatos("http://www.veo.es/estaticas/xml/portada_expansion.xml", "expansion");
		cargaDatos("http://www.veo.es/estaticas/xml/portada_yodona.xml", "yodona");
		cargaDatos("http://www.veo.es/estaticas/xml/portada_telva.xml", "telva");
	}

	function cargaDatos(p_xml, p_dest){
		$.ajax({
			type: "GET",
			url: p_xml,
			dataType: "xml",
			success:  function(xml) {

				var pos = 0;

				$(xml).find("item").each(function() {

					var notice = "";

					if(pos < 7){
						notice = notice + '<li class="noticia" id="noticia_'+ p_dest +'_'+ pos +'" >';
						
						notice = notice + '<ul id="tools_'+ p_dest +'_'+ pos +'"><li class="num">' + (pos + 1) + '</li>';
						notice = notice + '</ul>';
						if($(this).find("[nodeName=media:title]").text() ){
							notice = notice + '<p class="antetitulo">' + $(this).find("[nodeName=media:title]").text() + '</p>';
						}
						notice = notice + '<h4><a href="'+ $(this).find("link").text() +'" target="_blank">';
						notice = notice  + $(this).find("[nodeName=title]").text();
						notice = notice + '</a></h4>';
						notice = notice + '<div class="desplegable" id="desplegable_'+ p_dest +'_'+ pos +'" >';
						
						
						if($(this).find("[nodeName=media:thumbnail]").attr("url")){

								notice = notice + '<div class="media">';
								notice = notice + '<a href="'+ $(this).find("link").text() +'" target="_blank">';
								notice = notice + '<img src="' + $(this).find("[nodeName=media:thumbnail]").attr("url") + '" border="1">';
								notice = notice + "</a></div>";
						}

						
						notice = notice + '<p class="descripcion">' + $(this).find("[nodeName=description]").text() + '</p>';
						notice = notice + '</div>';
						
						notice = notice + '</li>';
						
						$("ul#" + p_dest).append(notice);
						$(".loading").hide();

						pos = ++pos;
						
						
						
					}
					});
				}
			});
		}
	});


	/* El boton del desplegable */


	$(function(){  
		    $("#version").click(function(event) {  
		    event.preventDefault();  
		    $("div.desplegable").slideToggle();  
			if(act == '0'){ act = 1; document.getElementById('version').innerHTML = 'Versi&oacute;n extendida'; $("#version").addClass("titulares"); }
			else{ act = 0; document.getElementById('version').innerHTML = 'Versi&oacute;n titulares'; $("#version").removeClass("titulares"); }

			});  
		});

	/* El refresco de la ventana */
	function refrescoVentana(){
		window.location = location.href;
	}

	setTimeout('refrescoVentana()', eval(600 * 1000));


	/* La función que pinta la fecha */
	function fecha(){

		var fecha = new Date();
		var dia_semana = diaArray[fecha.getDay()];
		var dia = fecha.getDate();
		var mes = mesArray[fecha.getMonth()];
		var agno = fecha.getFullYear();

		var hora = fecha.getHours();
		if(hora < 10){ hora = '0' + hora;	}
		var minutos = fecha.getMinutes();
		if(minutos < 10){ minutos = '0' + minutos;	}
		var segundos = fecha.getSeconds();
		if(segundos < 10){ segundos = '0' + segundos; }

		document.write("Actualizado: <span>" + hora  +": "+ minutos  +": "+ segundos +"</span>, del "+ dia_semana  +" "+  dia +" de "+ mes +" de "+ agno );

	}


