$(document).ready(function(){
	$("#jaimelogo, .item, .creado, #fondo1").fadeOut(1);
	$("#jaimelogo").delay(1000).fadeIn(2000);
	$(".item").delay(3000).fadeIn(2000);
	$("#fondo1").delay(3000).fadeIn(2000);	
	$(".creado").delay(4000).fadeIn(2000);
	$("#sonido").delay(4000).fadeIn(2000);
	$("#ascendente").fadeOut(10);
	$("#flecha").mouseenter(function(){
			$("#ascendente").fadeIn(1000);
		});
	$("#flecha").mouseleave(function(){
			$("#ascendente").fadeOut(1000);
		});
	
	$('.titulo').each(function(i){
		$(this).click(function() {
			$('.desplegable').slideUp('slow');
			$('.titulo a, .subtitulo a').removeClass('activo');
			$(".filosofia").fadeOut(200);
			if($(this).next().css('display') == "none"){
				$(this).next().slideDown('slow');
				$(this).find('a').addClass('activo');
				$(".filosofia").eq(i).delay(300).fadeIn("slow");
			}else {
				$(this).next().slideUp('slow');
			}
			return false;
		});
	});
	$('.subtitulo').each(function(i){
		$(this).click(function() {
			$('.subitem .desplegable').slideUp('slow');
			$('.subtitulo a').removeClass('activo');
			if($(this).next().css('display') == "none"){
				$(this).next().slideDown('slow');
				$(this).find('a').addClass('activo');
			}else {
				$(this).next().slideUp('slow');
			}
			return false;
		});
	});
	$('.desplegable').hide();
	
	$('li.thumb').click(function(){
		/*$("#foto").attr('src',$(this).find('img').attr("alt"));*/
		$("#derecha img").fadeOut(600, function(){ $(this).remove();}).delay(400);
		$("#derecha").prepend('<img alt="Imagen Grande" />');
		$("#derecha img").eq(0).attr('src',$(this).find('img').attr("alt"));
		$("#derecha img").eq(0).fadeOut(0);
		$("#derecha img").eq(0).fadeIn(600).delay(100);
	});
	$('.desplegable .listagaleria').each(function(i){
		var espaciado2 = Math.round(360/$(this).find('li').length);
		if(espaciado2 > 90) espaciado2 = 90;
		$(this).find('li').animate({width: espaciado2},{duration:100, queue: false});
		$(this).find('li').each(function(j){
			$(this).mouseenter(function(){
				$('.desplegable .listagaleria').eq(i).find('li').each(function(z){
					var espaciado = Math.round(270/($('.desplegable .listagaleria').eq(i).find('li').length-1));
					if(espaciado > 90) espaciado = 90;
					if(j == z)
						$(this).animate({width: 90},{duration:100, queue: false});
					else
						$(this).animate({width: espaciado},{duration:100, queue: false});
				});
			});
		});
		$(this).mouseleave(function(){
			$(this).find('li').animate({width: espaciado2},{duration:100, queue: false});
		});
	});
	
	$(".coleccion-recortador").scrollable({
			size: 1,
			clickable: false,
			disabledClass: "hidden",
			speed: 600,
			items: ".coleccion-dentro",
			next: ".fder",
			prev: ".fizq"
	});
	$(".fizq").addClass("hidden");
	$("li.thumb img[title!='']").hide();
	function replaceImage(){
		var img = $("li.thumb img[title!='']").eq(0);
		img.attr('src', img.attr('title'));
		img.attr('title','');
		img.show();
		if($("li.thumb img[title!='']").length > 0)
			window.setTimeout(replaceImage, 5);
	}
	window.setTimeout(replaceImage, 2000);
});
