// Enlaces externos
$(document).ready(function() {
	$("a[rel*='external']").each(function(){
		$(this).attr("target", "_blank");
		if (!$(this).attr("title")) {
			$(this).attr("title", ventana_nueva);
		} else {
			$(this).attr("title", $(this).attr("title") + " (" + ventana_nueva + ")");
		}		
	});
});

//Muestra y oculta los menús
$(document).ready(function() {
	$('#menu ul li:has(ul)').hover(
		function(e) {
			$(this).find('ul:first').stop(true,true).slideDown();
		},
		function(e)
		{
			$(this).find('ul:first').stop(true,true).slideUp();
		}
	);
});


$(document).ready(function() {
	$('.destacadoHome').each(function(){
		var enlace = $(this).find("a").attr("href");
		$(this).click(function(){
			document.location.href = enlace;
		});
		$(this).focus(function(){
			document.location.href = enlace;
		});	
		$(this).css("cursor","pointer");		
		$(this).hover(
			function(e){
				$(this).fadeTo("fast", .7)
			},
			function(e){
				$(this).fadeTo("fast", 1);
			}
		);
	});
});

$(document).ready(function() {
	$('.esparragos').each(function(){
		var enlace = $(this).find("a").attr("href");
		$(this).click(function(){
			document.location.href = enlace;
		});
		$(this).focus(function(){
			document.location.href = enlace;
		});	
		$(this).css("cursor","pointer");		
	});
});


// http://www.no-margin-for-errors.com/projects/prettyPhoto/
$(document).ready(function(){
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 0, /* padding for each side of the picture */
		opacity: 0.65, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
	});
});

//Banners rotativos en home
$(document).ready( function(){
	var contador_banners = 1;
	// Si hay más de un banner cargamos el contenedor de banners
	var cuantos_banners = $(".baner img").length;
	if (cuantos_banners > 1) {
		// Variables de los timmers
		var tiempo = 5000;
		var temporizador = setInterval(function(){
			mostrarSiguiente();
		},tiempo);
	}

	function mostrarSiguiente() {
		var elemento_activo = $(".baner img.banner_visible").attr("id");
		var id_elemento = elemento_activo.replace("banner_", "");
		if (id_elemento == cuantos_banners) {
			id_elemento_siguiente = 1;
		} else {
			id_elemento_siguiente = parseInt(id_elemento) + 1;
		}
		$("#banner_" + id_elemento).fadeOut(2000, function() {
			$("#banner_" + id_elemento).removeClass("banner_visible").addClass("banner_oculto");
		});
		$("#banner_" + id_elemento_siguiente).fadeIn(2000, function() {
			$("#banner_" + id_elemento_siguiente).removeClass("banner_oculto").addClass("banner_visible");
		});
	}
});




