$(document).ready(function(){
	
	/* ------------ */
	/* MENU SECTION */
	/* ------------ */
	var nbrSections = $(".section").length; // Nombre de sections
	var visibleSection = 0;
	
	$(".section").hide(); // Masque toutes les sections sauf la première
	$("#content .section:eq("+visibleSection+")").show();
	
	$("#menu a:lt("+nbrSections+")").click(function() {
		var diesePos = $(this).attr("href").lastIndexOf("#");
		var idWanted = $(this).attr("href").substr(diesePos+1);
		//alert($("#"+idWanted).index());
		
		$("#content .section:eq("+visibleSection+")").fadeOut("slow", function() {
			
			$("#"+idWanted).fadeIn("slow");
			visibleSection = $("#"+idWanted).index()-1;
		});
		
		return false; // Annuler le rechargement de page
	});
	
	
	
	/* --------- */
	/* PORTFOLIO */
	/* --------- */
	var nbrPortfolio = $(".viewer img").length; // Nombre d'images
	var visiblePortfolio = 1; // Image visible
	
	$(".viewer img:gt(0)").hide(); // Masque toutes les images sauf la première
	
		// Bouton précédent
		$("#previous").click(function(){
			$(".viewer img:nth-child("+visiblePortfolio+")").fadeOut("slow", function() { // Masque l'image actuelle
				//alert(visiblePortfolio +" --- "+ nbrPortfolio);
				if (visiblePortfolio == 1) { // Calcul de l'image à afficher
					visiblePortfolio = nbrPortfolio;
				}else{
					visiblePortfolio --;
				}
				$(".viewer img:nth-child("+visiblePortfolio+")").fadeIn("slow"); // Affiche l'image précédente
				
			});
			return false; // Annuler le rechargement de page
		});
		
		// Bouton suivant
		$("#next").click(function(){
			$(".viewer img:nth-child("+visiblePortfolio+")").fadeOut("slow", function() { // Masque l'image actuelle
				
				if (visiblePortfolio == nbrPortfolio) { // Calcul de l'image à afficher
					visiblePortfolio = 1;
				}else{
					visiblePortfolio ++;
				}
				
				$(".viewer img:nth-child("+visiblePortfolio+")").fadeIn("slow"); // Affiche l'image suivante
				
			});
			
			return false; // Annuler le rechargement de page
		});
});
