$(function(){
	
	$("#form-contact span").hide();
	$("#nom,#sujet,#mail,#message").attr({valided : "false"});
	
	empty = function(o){
		if( o.val().length == 0 ){
			o.next("span").show();
			o.attr({ valided : "false" });
		}else{
			o.next("span").hide();
			o.attr({ valided : "true" });
		}
	}
	
	isMail = function(o){
		emailRegEx 	= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		str 		= o.val();
		if( str.match(emailRegEx) ){
			o.next("span").hide();
			o.attr({ valided : "true" });
		}else{
			o.next("span").show();
			o.attr({ valided : "false" });
		}
	}
	
	$("#nom,#sujet").bind("focus",function(){ !empty ( $(this) ); });
	$("#nom,#sujet").bind("keyup",function(){ !empty ( $(this) ); });
	$("#mail").bind("keyup",function(){ isMail ( $(this) ); });
	$("#mail").bind("blur",function(){ isMail ( $(this) ); });
	
	$("#message").focus(function(){
		$(this).parents("fieldset").prev("fieldset").animate({ width : "27%" }, "fast" );
		$(this).parents("fieldset").animate({ width : "67%" }, "fast" );
	});
	
	$("#form-contact").submit(function(){
		reponse = false;
		if( $("#nom,#sujet,#mail,#message").attr("valided") == "true"){
			reponse = true;
		}
		return reponse;
	});

});