// JavaScript Document
(function($) {
	$.fn.equalHeights = function() {
		var maxheight = 0;
		$(this).each(function(){
			maxheight = ($(this).height() > maxheight) ? $(this).height() : maxheight;
		});
		$(this).css('height', maxheight);
	}
})(jQuery);

$(document).ready(function() {
	$('body').addClass('js');

	if ($('#home-pictures').length > 0) {
	
		var imgs = [];
		$('#home-pictures img').each(function (index) {
			var i = new Image();
			i.onload = function () {
				var h = i.height;
				var w = i.width;
				imgs[index] = [w, h];
				$(window).trigger('resize');
			}
			i.src = $(this).attr('src');
		});

		$(window).resize(function () {
			
			var height = $(window).height() - 137 - 40; //- 137 - 40;
            
            if(height <= 408) {
                $('#pied-blocs').hide();
                $('#pied-blocs-small').show();
            }
            else {
                $('#pied-blocs').show();
                $('#pied-blocs-small').hide();
            }

			var width = $(window).width();
			$('#home-pictures').height(height);
			
			$('#home-pictures').css({
				'width': width,
				'height': height
			});
			
			$('#home-pictures img').each(function (index) {
				var self = this;
				
				if (imgs[index] && imgs[index].length === 2) {
					var w = imgs[index][0];
					var h = imgs[index][1];
					
					if ((height/width) > (h/w)) {
                        c_width = parseInt((w/h) * height);
						$(self).css({
							'width': c_width,
							'height': height,
                            'margin-left': parseInt((width - c_width) / 2)
						});
                        /*$(self).attr('width', (w/h) * height);
                        $(self).attr('height', height);*/
						
					} else {
						$(self).css({
							'width': width,
							'height': parseInt((h/w) * width),
                            'margin-left': 0
						});
                        /*$(self).attr('width', width);
                        $(self).attr('height', (h/w) * width);*/
					}
				}
				
				
			});
			
		}).trigger('resize');
	}
	
});

