GLOBAL_RESIZE=1;
GLOBAL_IMG_W=0;
GLOBAL_IMG_H=0;

function init() {
	$(document).ready(function() {
		$("#fond").hide()
        .one("load", function() {
			$(this).show();
			GLOBAL_IMG_W = $(this).width();
			GLOBAL_IMG_H = $(this).height();

			if(GLOBAL_RESIZE) {			
				$(this).hAlign();
				$(this).vAlign();
				GLOBAL_RESIZE=1;
			}
        })
        .attr("src", "img_hotel_biarritz/hotel_biarritz.jpg")
        .each(function() {
          if(this.complete) $(this).trigger('load');
        });
        
        $("#fond").load(function() {
			GLOBAL_IMG_W = $(this).width();
			GLOBAL_IMG_H = $(this).height();
			
			if(GLOBAL_RESIZE) {			
				$(this).hAlign();
				$(this).vAlign();
				GLOBAL_RESIZE=1;
			}
		});
	});
}

function init_resize() {
	$(document).ready(function() {
		GLOBAL_IMG_W = $("#fond").width();
		GLOBAL_IMG_H = $("#fond").height();
		
		if(GLOBAL_RESIZE) {			
			$("#fond").hAlign();
			$("#fond").vAlign();
			GLOBAL_RESIZE=1;
		}
	});
}

(function ($) {
	$.fn.hAlign = function() {
		return this.each(function(i){
			GLOBAL_RESIZE=0;
			var maxW = $(window).width();
			var imgW = GLOBAL_IMG_W;
			var margin = 0;
			if (maxW < imgW) {
				margin = - (imgW - maxW) / 2;
				$(this).css({"margin-left" : margin+"px"});
			}
		});
	};
})(jQuery);

(function ($) {
	$.fn.vAlign = function() {
		return this.each(function(i){
			GLOBAL_RESIZE=0;
			var maxH = $(window).height();
			var imgH = GLOBAL_IMG_H;
			var margin = 0;
			if (maxH < imgH) {
				$(this).css({"margin-top" : margin+"px"});
			}
			if (maxH > imgH) {
				margin =  (maxH - imgH) / 2;
				$(this).css({"margin-top" : margin+"px"});
			}
		});
	};
})(jQuery);



