/* ANTI IFRAME */
if (top.location != self.location) {
	top.location = self.location;
}


$(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 + ")");
		}		
	});
});
$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto();
});

zg_insert_badge = function() {
	var zg_bg_color = 'ffffff';
	var zgi_url = 'http://www.flickr.com/apps/badge/badge_iframe.gne?zg_bg_color='+zg_bg_color+'&zg_person_id=35924055%40N04';
	document.write('<iframe style="background-color:#'+zg_bg_color+'; border-color:#'+zg_bg_color+'; border:none;" width="113" height="151" frameborder="0" scrolling="no" src="'+zgi_url+'" title="Flickr Badge"><\/iframe>');
	if (document.getElementById) {
		document.write('<div id="zg_whatlink"><a href="http://www.flickr.com/badge.gne"	style="color:#3993ff;" onclick="zg_toggleWhat(); return false;">¿Qué es esto?<\/a><\/div>');
	}
}
zg_toggleWhat = function() {
	document.getElementById('zg_whatdiv').style.display = (document.getElementById('zg_whatdiv').style.display != 'none') ? 'none' : 'block';
	document.getElementById('zg_whatlink').style.display = (document.getElementById('zg_whatdiv').style.display != 'none') ? 'none' : 'block';
	return false;
}



$(document).ready( function(){
	var contador_banners = $(".santano").length - 1;
	if (contador_banners > 1) {
		var actual = 1;
		var tiempo = 5000;
		var temporizador = setInterval(function(){
			mostrarSiguiente();
		},tiempo);

	function mostrarSiguiente() {
		$("#header div.santano_" + actual++).fadeOut("slow");
		if (actual > contador_banners) {
			actual = 1;
		}
		$("#header div.santano_" + actual).fadeIn("slow");
	}}
});


var cuantos_banners = 0;
function mostrarSiguiente() {
	var elemento_activo = $("#carrusel_botonera a.activo").attr("id");
	id_elemento = elemento_activo.replace("carrusel_banner_", "");
	$("#carrusel_banner_" + id_elemento).removeClass("activo");
	$("#carrusel_banner_" + id_elemento).addClass("inactivo");
	$(".carrusel_banner_" + id_elemento).removeClass("activo");
	$(".carrusel_banner_" + id_elemento).addClass("inactivo");
	$(".carrusel_banner_" + id_elemento).fadeOut(1000, function() {
		if (id_elemento == cuantos_banners) {
			id_elemento = 1;
		} else {
			id_elemento++;
		}
		$("#carrusel_banner_" + id_elemento).removeClass("inactivo");
		$("#carrusel_banner_" + id_elemento).addClass("activo");
		$(".carrusel_banner_" + id_elemento).fadeIn(600);
		$(".carrusel_banner_" + id_elemento).removeClass("inactivo");
		$(".carrusel_banner_" + id_elemento).addClass("activo");
	});
}
$(document).ready( function(){
	var contador_carrusel = 1;
	// Si hay más de un banner cargamos el contenedor de banners
	cuantos_banners = $(".carrusel_banner").length;
	if (cuantos_banners == 1) {
		$(".carrusel_banner").addClass("activo");
	} else if (cuantos_banners > 1) {
		$("#carrusel_banners").append('<div id="carrusel_botonera"></div>');
		// Para cada banner
		$.each($(".carrusel_banner"), function(){
			// Marcamos cada banner como "banner_x"
			$(this).addClass("carrusel_banner_" + contador_carrusel);
			if (contador_carrusel == 1) {
				$(this).addClass("activo");
			}
			// Creamos el botón de cada banner
			if (contador_carrusel == 1) {
				$("#carrusel_botonera").append('<a href="#" id="carrusel_banner_' + contador_carrusel + '" class="activo">' + contador_carrusel++ + '</a>');
			} else {
				$("#carrusel_botonera").append('<a href="#" id="carrusel_banner_' + contador_carrusel + '" class="inactivo">' + contador_carrusel++ + '</a>');
			}
		});
		
		// Variables de los timmers
		var tiempo = 7000;
		var temporizador_carrusel = setInterval(function(){
			mostrarSiguiente();
		},tiempo);
		// A cada botón, al hacer click, paramos el timer y mostramos la capa que procede.
		$("#carrusel_botonera a").click(function(){
			$(this).blur();
			// Paramos el temporizador_carrusel
			clearInterval(temporizador_carrusel);
			// Cambiamos los class para marcar el clickado
			$("#carrusel_botonera a").removeClass("seleccionado");
			$("#carrusel_botonera a").removeClass("activo");
			$("#carrusel_botonera a").addClass("inactivo");
			$(this).addClass("seleccionado");
			// Ocultamos todos los banners y mostramos el banner correspondiente
			$(".carrusel_banner").removeClass("activo").addClass("inactivo").hide();
			var elemento_clickado = $(this).attr("id");
			$("." + elemento_clickado).removeClass("inactivo").addClass("activo").fadeIn(600);
			return false;
		});
	}
});
