	function adaptImage(targetimg) {
		var wheight = $(window).height();
		var wwidth = $(window).width();
		
		// Remove attributes in case img-element has set width and height
	    targetimg.removeAttr("width")
	    		 .removeAttr("height")
	    		 .css({ width: "", height: "" }); // Remove css dimensions as well
		
	    var imgwidth = targetimg.width();
	    var imgheight = targetimg.height();
		
	    var destwidth = wwidth;
	    var destheight = wheight;
	    
		//tamanho da imagem
		if(imgheight < wheight) {
			destwidth = (imgwidth * wheight)/imgheight;
			$('#fundo img').height(destheight);
			$('#fundo img').width(destwidth);
		}
		
		//posicionamento no meio
		destheight = $('#fundo img').height();
		var posy = (destheight/2 - wheight/2);
		var posx = (destwidth/2 - wwidth/2);
		
		if(posy > 0) {
			posy *= -1;
		}
		if(posx > 0) {
			posx *= -1;
		}
		
		//alert(posy);
		
		$('#fundo').css({'top': posy + 'px', 'left': posx + 'px'});
	}
		
	$(window).resize(function() {
		adaptImage($('#fundo img'));
	});
	
	$(document).ready(function() {
	
		
		$("a.fancy").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	false
		});
		
	});
	
