jQuery(document).ready(function($) {

	$("img").removeAttr("title");
	$("a").removeAttr("title");

    $('.projects .post').hover(  
	     function() {  
	     	$(this).addClass('hover');  	     
		},  
	     function() {  
	     	$(this).removeClass('hover');  
		}  
   	);

	$("#info_link").click(function() {
		
		$("#overlay").width($(window).width());
		$("#overlay").height($(window).height());
		
		$("#overlay").hide();
		$("#info").hide();

		marginLeft = ( $(window).width() - $("#info").width() ) / 2;
		$("#info").css("left",marginLeft+"px")
		
		$("#content").css("overflow-x","hidden");

		
		$("#overlay").fadeIn("quick");
	 	$("#info").fadeIn("quick");	
		$("#info_link").css("visibilty","hidden");
	
		$("#overlay").click(function() {
			$("#content").css("overflow-x","visible");
			$(this).fadeOut("slow");
			$("#info").fadeOut("slow");
			$("#info_link").css("visibilty","auto");
		});
	
		$("#close_button").click(function() {
			$("#content").css("overflow-x","visible");
			$("#overlay").fadeOut("slow");
			$("#info").fadeOut("slow");
			$("#info_link").css("visibilty","auto");
		});
	
	});
	
	
	// GALLERY - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	
	$("#gallery-container").width( $(window).width() -281 -10 );
	
	g_width = 40;
	
	$("#gallery img").each(function(index){ 
		g_width += $(this).width() +12; 
		
		$(this).wrap("<span class='img_cnt'></span>");
		
		if($(this).parent("#post-42").length > 0){

			$("<span class='caption'>"+alt+"</span>").insertAfter($(this));			
		}
	});
	
	//Guarrada brutal para meter captions solo en algunos sitios y no tener que borrar todos los alts.
	$("#post-42 #gallery img").each(function(index){ 
		alt = $(this).attr("alt");
		$("<div class='caption'>"+alt+"</div>").insertAfter($(this));		
	});

	$("#post-50 #gallery img").each(function(index){ 
		alt = $(this).attr("alt");
		$("<div class='caption'>"+alt+"</div>").insertAfter($(this));		
	});



	
	$("#gallery").width(g_width);

	
	
	
	if( ($(window).height()-88) > 466 ){$("#gallery-container").height($(window).height()-88);	
	}else{$("#gallery-container").height(466);}

	p_width=50;
	
	$(".projects .post").each(function(index){ p_width += $(this).width() +12; });
	$(".projects").width(p_width);
	
	
	
	
	
	/*if( $('body').hasClass("blog") ){
		$(window).scroll(function () { 
	  		$('#header').css("marginLeft",document.documentElement.scrollLeft+"px");
	    });
	}*/
	
	
	
	// REAJUSTE segun variacio de ventana - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	function reajusta() {
		
		if ( $('#gallery-container').length ) {

			if( ($(window).height()-88) > 466 ){ $("#gallery-container").height($(window).height()-88);	
			}else{ $("#gallery-container").height(466);}

			$("#gallery-container").width( $(window).width() -281 -10 );
		
		}
		
		if ( $('#overlay').length ) {
		
			$("#overlay").width($(window).width());
			$("#overlay").height($(window).height());
		
		}
		
	    	
	};

	var resizeTimer = null;
	$(window).bind('resize', function() {
	    if (resizeTimer) clearTimeout(resizeTimer);
	    resizeTimer = setTimeout(reajusta, 100);
	});


});
