$(document).ready(function(){	
	novedades_ajax('./novedades/novedades_' + idioma + '.htm');
	setInterval("novedades_ajax('./novedades/novedades_' + idioma + '.htm')",58000);
	
});

function novedades_ajax(pagina){
	$("#ajax").load(pagina,function(){
		//Una vez cargada la pagina, ejecuto estas funciones:
		resaltadoNovedades();
		cambiar_enlaces();
		enlazarReveladoDetalles();
		asignarReadMore();	
	});
}

function resaltadoNovedades(){
	//resaltado de las novedades:
	$("div.novedad_activa").hover(
		function () {
			$(this).removeClass("novedad_activa").addClass("novedad_activa_destaca");
		}, 
		function () {
			$(this).removeClass("novedad_activa_destaca").addClass("novedad_activa");
		}
	);
}

var titNovedad;
var orgNovedad;
var descNovedad;
var emision_directo = "0";
var enlace1 = "";
var enlace2 = "";
function cambiar_enlaces(){
	$("div.novedad_activa").children(".enlace_novedad").hide();
	$("div.novedad_activa").bind("click",function(){
		titNovedad = $(this).children(".tituloNovedades").html();
		orgNovedad = $(this).find(".orgNovedad").html();
		descNovedad = $(this).children(".descripcionNovedad").html();
		//emision_directo = ;
		enlace1 = "";
		enlace2 = "";
		var enlaces = $(this).children(".enlace_novedad");
		if(enlaces.length > 0){
			enlace1 = enlaces.eq(0).attr("href");
			if(enlaces.length > 1) enlace2 = enlaces.eq(1).attr("href");
		}
		$("div#tabVisor").load("./player/dsp_player.cfm", function(){
			$("div#tab1").hide();
			$("div#tabVisor").fadeIn(500);
		});
	})	
}

function enlazarReveladoDetalles(){
	//Corta el texto de la descripcion de la novedad, y aņade un "+Info"
	$(".descripcionNovedad").css("height","3em");
	
}

function asignarReadMore(){
	//Asigno la funcion de todos los "LEER MAS"
	var t;
	$(".descripcionNovedad").hover(
		function(){
			var $this = $(this);
			t=setTimeout(function(){
				$this.css("height","auto");
				if($this.height() < parseFloat($this.css("line-height")) * 2){
					$this.css("height","3em");
				}
			},600);
		},
		function(){
			clearTimeout(t);
			$(this).css("height","3em");
		}
	);
}