function afficherApercu() {	
	margeGauche = 20;
	margeDroite = -500; // image = 400 + 2 marge = 10 + 20 (image de 470 max)
	margeHaut = 10;				
	$("#portfolio ul li a").hover(function(e){											
		this.titre = $(this).attr("title"); 
		$(this).attr("title", ""); // masque l'attribut title
		this.imageApercu = $(this).attr("href").replace("_xl", "_l");
		$("body").append("<div id='imageApercu'><img src='"+ this.imageApercu +"' alt='"+ this.titre +"' /></div>");										 		
		var largeur = $(document).width();
		var milieu = (largeur / 2);				
		if (e.pageX >= milieu) { // position de l'aperçu (à droite ou à gauche de la souris)
			$("#imageApercu").css("left",(e.pageX + margeDroite) + "px");
		} else {
			$("#imageApercu").css("left",(e.pageX + margeGauche) + "px");
		}
		$("#imageApercu")
			.css("top",(e.pageY - margeHaut) + "px")		
			.fadeIn("fast");		
    },
	function(){			
		$(this).attr("title", this.titre);
		$("#imageApercu").remove();		
    });	    
	$("#portfolio ul li a").mousemove(function(e){
		var largeur = $(document).width();
		var milieu = (largeur / 2);
		if (e.pageX >= milieu) {
			$("#imageApercu").css("left",(e.pageX + margeDroite) + "px");
		} else {
			$("#imageApercu").css("left",(e.pageX + margeGauche) + "px");
		}		
		$("#imageApercu")
			.css("top",(e.pageY - margeHaut) + "px");
	});		
	$("#portfolio ul li a").click(function(e){	
		$(this).attr("title", this.titre);
		$("#imageApercu").remove();	
	});	
};	
var chargement = "false";		
function chargementFini() { // fonction appellé depuis flash lorsque le chargement de l'animation est terminée
	//alert("chargé");
	chargement = "true";			
};
function afficherAnimation(nom) { // change l'animation dans le flash
	if (chargement == "true") {
		document.getElementById("animation").fin(nom);
	}
};

$(document).ready(function() {
	
	// Intégration de l'animation flash avec swfobject	
	var flashvars = {};
	var params = {
		menu: "false",
		scale: "noscale",
		wmode: "transparent"
	};
	var attributes = {
		id: "animation"
	};
	swfobject.embedSWF("images/animation.swf", "accueilAnimation", "500", "570", "9.0.0", "images/expressInstall.swf", flashvars, params, attributes);	   	
	
	// Menu
	
	$("#accueilMenuPortfolio > a").mouseover(function() { 											
		afficherAnimation("portfolio"); 
	});	
	$("#accueilMenuApropos > a").mouseout(function() { 
		afficherAnimation("accueil"); 
	});		
	$("#accueilMenuApropos > a").mouseover(function() { 
		afficherAnimation("apropos"); 
	});
	$("#accueilMenuPortfolio > a").mouseout(function() { 
		afficherAnimation("accueil"); 
	});		
	$("#accueilMenuContact > a").mouseover(function() {												
		afficherAnimation("contact"); 
	});	
	$("#accueilMenuContact > a").mouseout(function() { 
		afficherAnimation("accueil"); 
	});	

		
	// Gestion de l'aperçu des images dans le porfolio			
	afficherApercu();
	
	// Scroll vertical
	$.localScroll.hash({
		duration:1500,
		hash:true
	});
	$.localScroll({
		duration:1500,
		hash:true
		/* NE FONCTIONNE PAS SOUS IE6
		onBefore:function(e, anchor, $target) { 
			if (this.blur) {
				this.blur(); // supprime les lignes durant le scroll
			}
		}
		*/
	});	
	
	// Formulaire de contact
	$(".erreur").fadeOut("fast"); // masque les messages d'erreurs	
	$("#merci").fadeOut("fast"); // masque le message		
	$(":input[@type!='submit']").focus(function () { // lorsque un champ prend le focus
		$(this).removeClass();
		$(this).addClass("focus");
		if ($(this).val() == $(this).attr("title")) {	
			$(this).val("");
		}				
	}); 	
	$(":input[@type!='submit']").blur(function () { // lorsque un champ perd le focus
		var valeur = $(this).val();
		valeur = jQuery.trim(valeur);
		$(this).removeClass();		
		var nom = $(this).attr("name");
		if (valeur == "") {
			$(this).val($(this).attr("title"));	
			var texte = "Vous n'avez pas saisi votre "+nom+" !";
			$(this).parent().find(".erreur").text(texte)
			.fadeIn("slow");			 
		} else {
			var re1 = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/; 
			if (nom == "email" && !valeur.match(re1)) {
				$(this).parent().find(".erreur").text("Vous avez saisi un email non valide !")
				.fadeIn("slow");
			} else {			
				$(this).parent().find(".erreur").fadeOut("slow");  
			}
		}
	}); 		 	 
	$("#bouton").click(function() { // validation du formulaire   	
		$(".erreur").fadeOut("fast"); // masque les messages d'erreurs
		var erreur = false;
		$(":input[@type!='submit']").each(function() {
    		var valeur = $(this).val(); 
			valeur = jQuery.trim(valeur);
    		var nom = $(this).attr("name");
    		if (valeur == "" || valeur == $(this).attr("title")) { 
    			var texte = "Vous n'avez pas saisi votre "+nom+" !";
    			$(this).parent().find(".erreur").text(texte)
    			.fadeIn("slow");
    			erreur = true;
    		}    		
			if (valeur != "" && nom == "email" && valeur != $(this).attr("title")) {
				var re1 = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/; 
				if (!valeur.match(re1)) {
					$(this).parent().find(".erreur").text("Vous avez saisi un email non valide !")
					.fadeIn("slow");
					erreur = true;
				}
			}   		
    				
		});		
		if (erreur == true) {
			return false;
		} else {								
			$(this).fadeOut("fast");
			var nom = $("#nom").val();
			var email = $("#email").val();
			var message = encodeURIComponent($("#message").val());	
			var donnees = "nom="+nom+"&email="+email+"&message="+message; 			
			$.ajax({ 
				type: "POST",        
				url: "envoi.php",          
				data: donnees,          
				cache: false, 
				error:  function(objet, type) { 
					$("#bouton").fadeIn("slow");
					alert("Une erreur est survenue lors de l'envoi du message. (jsl173)");					
				},        
				success: function(msg) { 
					if (msg != "") {
						$("#bouton").fadeIn("slow");
						alert(msg); 
					} else {
						$("#merci").fadeIn("slow");
					}     
				}        
			});	
			return false;				
		}		
	});		
});	