$(document).ready(function() {
	/* Ajustement CSS */
	cssAlaune();
	cssEncemoment();
	//imagesAlaune();
	
	/* Interactions */
	interEmail();
});

function cssAlaune() {	
	/* Ajustement blocs "A la une" */
	var h = 0;
	
	$("#bloc-alaune .actu-contenu").each(function() {
		if ($(this).height() > h) h = $(this).height();
	});
	
	$("#bloc-alaune .actu-contenu").height(h);
}

function cssEncemoment() {
				
	/* Ajustement blocs "En ce moment" */
	h = 0;
	
	$(".encemoment-bloc .encemoment-contenu").each(function() {
		if ($(this).height() > h) h = $(this).height();
	});
	
	$(".encemoment-bloc .encemoment-contenu").height(h);
	
	/* En ce moment */
	var tabH = Array();
	
	for (i = 0; i < 3; i++) {
		tabH[i] = 0;
		
		$(".encemoment-bloc .encemoment-contenu:eq(" + i + ") ul li").each(function() {
			tabH[i] += $(this).height();
		});
	}
	
	var max = 0;
	
	for (i = 0; i < tabH.length; i++) {
		if (tabH[i] > max) max = tabH[i];
	}
	
	for (i = 0; i < 3; i++) {
		var diff = max - tabH[i];

		if (diff > 0) {
			var padding = $(".encemoment-bloc .encemoment-contenu:eq(" + i + ") ul li:first").css("padding-top");
			padding = parseInt(padding.substring(0, padding.indexOf('p')));
			
			var nb = $(".encemoment-bloc .encemoment-contenu:eq(" + i + ") ul li").length;
			var paddingplus = padding + (diff / (nb-1));
									
			$(".encemoment-bloc .encemoment-contenu:eq(" + i + ") ul li").css("padding-bottom", paddingplus + "px");
			
			//$(".encemoment-bloc .encemoment-contenu:eq(" + i + ") ul li:last").css("margin-top", diff);
		}
	}
}

function interEmail() {	
	$("#newsletter-email").focus(function() {
		if ($(this).val() == "Votre email") $(this).val("");
	});		
	
	$("#newsletter-email").blur(function() {
		if ($(this).val() == "") $(this).val("Votre email");
	});
}

function cssAlaune() {
	var h = 0;
	
	$(".actu h2").each(function() {
		if ($(this).height() > h) h = $(this).height();
	});
	
	$(".actu h2").height(h);
	
	h = 0;
	
	$(".actu-texte").each(function() {
		if ($(this).height() > h) h = $(this).height();
	});
	
	$(".actu-texte").height(h);
}

function imagesAlaune() {
	$("#bloc-alaune .actu-image").each(function() {	
		var h = $(this).height();
		
		var img = $(this).find("img")
		if ($(img).height() < h) {
			var diff = (h - $(img).height()) / 2;
			
			$(img).css("margin-top", diff + "px");
		}
	});
}
