(function($) {

	$.fn.fullBg = function(){
		var bgImg = $(this).hide();
						
		function resizeImg(bgImg) {
			var imgwidth = bgImg.width();
			var imgheight = bgImg.height();
			
			var winwidth = $(window).width();
			var winheight = $(window).height();
			
			var widthratio = winwidth / imgwidth;
			var heightratio = winheight / imgheight;
			
			var widthdiff = heightratio * imgwidth;
			var heightdiff = widthratio * imgheight;
		
			if(heightdiff>winheight) {
				bgImg.css({
					width: winwidth+'px',
					height: heightdiff+'px'
				});
			} else {
				bgImg.css({
					width: widthdiff+'px',
					height: winheight+'px'
				});		
			}
			bgImg.fadeIn(200, function(){
				$('#wrapper img').fadeIn(200, function(){
					$('#wrapper a').fadeIn()
				});
			});
		}
		resizeImg(bgImg);
		$(window).resize(function() { resizeImg(bgImg); });
	};
})(jQuery)


jQuery(function($) {
	var img = new Image();
	$(img)
		.load(function () {
			var html = $('body').append($(this));
			$(this).fullBg();
		})
		.error(function () {
			alert('Erreur de chargement !');
		})
		.attr('src', 'https://c610660.ssl.cf2.rackcdn.com/uploads/4cd82c135316be11e4000005/asset/file/4d752dcc588af64ee90000c5/papier_peint.jpg')
		.attr('id', 'background')
		.hide()
		.css('width', '1440px')
		.css('height', '956px')
		.css('z-index', '0');
	//.attr('src', 'https://c610660.ssl.cf2.rackcdn.com/uploads/4cd82c135316be11e4000005/asset/file/4d752dcc588af64ee90000c5/background-big.jpg')	
	$("#wrapper").center();
	$(window).resize(function() { $('#wrapper').center(); });
	$('a').click(function(){ $('body').css('background', 'black'); $('#wrapper, #background').animate({ opacity: 'hide' }); });	
});

$(window).load(function(){
	$(window).resize();
	
});
