jQuery.fn.idle = function(time){
	return this.each(function(){
		var i = $(this);
		i.queue(function(){
			setTimeout(function(){
				i.dequeue();
			}, time);
		});
	});
};

jQuery.fn.addFooter = function(){
	return this.each(function(){
		var a = $(this);
		a.append('<span></span>');
		var span = a.children('span');
		var title = a.children('img').attr("alt");
		span.html(title);
	});
};

jQuery(document).ready(function(){
	var viewportWidth = $(window).width();
	var viewportHeight = $(window).height();
	$('img.portada').width(viewportWidth);
	$('img.portada').height(viewportHeight);		
	
	   $('.content').css({opacity: 0}).animate({opacity:1.0},2000);
	   
		$("a[class=zoom]").add("[class=group]").fancybox({
			'overlayOpacity'	:	0.9,
			'overlayColor'		:	'#000',
			'zoomSpeedIn'		:	300,
			'zoomSpeedOut'		:	300
		});	 
		
		$('a[class=image]').add('a[class=group]').addFooter();
			
		$('a[class=zoom]').hover(function(){
			$(this).children('img').animate({backgroundColor:'#526074'});
		}, function() {
			$(this).children('img').animate({backgroundColor:'#5e6e84'});
		});					
		
		
		$('a[class=image]').add('a[class=group]').hover(function(){
			$(this).closest('div').animate({backgroundColor:'#526074'});
		}, function() {
			$(this).closest('div').animate({backgroundColor:'#5e6e84'});
		});		
		

	   
	   $('a[class!="zoom"][class!="group"][target!="_blank"]').click(function(){
		   var url = $(this).attr('href');
		   if(url != '/home/') {
			   $('.content').animate({opacity:0}, 1000, function() {
				   document.location.href = url;
			   });
			   return false;
		   }
		   
	   });

});

