$(function () {
	var listTitre = $("article.featured-article h2, .moinsInfo");
	var listPlusInfo = $(".plusInfo");
	var listArticle = $("article.featured-article");
	var INIT_SIZE = 168; // Hauteur initial de l'article //
	
	// Ouvre ou ferme l'article //
	function OpenCloseArticle (article) {
		if (!article.data("isOpen")) {
			// Ouverture //
			article.animate({ height : article.data("originalHeight") }, 500);
			article.next(".plusInfo").hide();
		} else {
			// Fermeture //
			article.animate({ height : INIT_SIZE }, 500, function () {
				// Double check pour éviter que ça glitch quand on clique rapidement //
				if (!article.data("isOpen")) {
					article.next(".plusInfo").show();
				}
			});
		}
		
		// Inverse l'état d'ouverture de l'article //
		article.data("isOpen", !article.data("isOpen"));
	}
	
	// Initialisation des variables pour chaque article //
	listArticle.each(function () {
		$(this).data("originalHeight", $(this).height() + 5);
		$(this).data("isOpen", false);
		$(this).height(INIT_SIZE);
	});
	
	// Code pour les liens "Plus" //
	listPlusInfo.show();
	
	listPlusInfo.click(function (e) {
		var article = $(this).prev("article");
		
		OpenCloseArticle(article);
	});
	
	// Code pour les titres //
	listTitre.click(function (e) {
		var article = $(this).closest("article");
		
		OpenCloseArticle(article);
	});
});
