(function($){
		$("#portfolio ul.items li").unbind();
		$("#portfolio ul.items li").mouseover(function(){
			/*$(this).find("figcaption").animate({height:"86px"
		  }, 1000);*/
			$(this).addClass("hoverImg");
			$(this).find("figcaption").animate({height:"84px"
		  }, 200);
			$(this).find("figure").find("div").find("img").animate({width:"296px",left:"-52px",top:"-52px"}, 200);
		}).mouseleave(function(){
			$(this).find("figcaption").animate({height:"0px"
		  }, 10);
		  $(this).find("figure").find("div").find("img").animate({width:"196px",left:"0px",top:"0px"}, 200);
			$(this).removeClass("hoverImg");
		});
		
		$('#go_top').click(function(){
			$('html, body').animate({scrollTop:0}, '1000', 'swing');
			return false;
		});
		
 		var recherche = /mail/;
		$.fn.validate = function(){
			error='';
			files='';
			$("input.obligatoire, textarea.obligatoire, select.obligatoire", this).each(function(){
				if($(this).is('input:radio')||$(this).is('input:checkbox')){
					console.log($("input[name="+$(this).attr('name')+"]:checked").length);
					if(!$("input[name="+$(this).attr('name')+"]:checked").length){
						$("input[name="+$(this).attr('name')+"]").parent().css({"backgroundColor":"#FFCCCC"});
						$("input[name="+$(this).attr('name')+"]").focus(function(){$("input[name="+$(this).attr('name')+"]").parent().css({"backgroundColor":""});});
						error=$(this).attr("name");
						return false;
					}
				}else if($(this).is('input:file')){
					if(!$(this).val().match(/(.*?)\.(doc|pdf)$/)){
						$(this).css({"backgroundColor":"#FFCCCC"});
						error=$(this).attr("name");
						return false;
					}else	files="ok";
				}else{
					valeur= jQuery.trim($(this).val());
					if(valeur != "" && $(this).val() != $(this).attr("rel")){
						if(recherche.test($(this).attr("name"))){
							if(!$(this).validmail())error='mail';
						}
						//return true
					}else{
						$(this).css({"backgroundColor":"#FFCCCC"});
						error='champ '+$(this).attr("name");
						return false;
					}
				}
			});
			if(error==''){
				e= $(this);
				if(files!=''){
					if(!document.getElementById('findenvoi'))$(this).before('<iframe id="findenvoi"></iframe>');
					else $('#findenvoi').replaceWith('<iframe id="findenvoi"></iframe>');
					$(this).submit();
					$('html, body').animate({scrollTop:$("#findenvoi").position().top}, '1000', 'swing', function() {
							//$('#findenvoi').replaceWith('<div id="findenvoi" style="text-align:center; color:#FFCCCC">'+$('#findenvoi').html()+'</div>');//$('#findenvoi').html(msg);
					});
				}else{
					if(!document.getElementById('findenvoi'))$(this).before('<div id="findenvoi" style="text-align:center"></div>');
					else $('#findenvoi').replaceWith('<div id="findenvoi" style="text-align:center; color:#FFCCCC"></div>');
				//if(!document.getElementById('findenvoi'))$('<iframe id="findenvoi"></iframe>').insertbefore(this);
					$.ajax({
						url: '/envoi.html',
						cache: false,
						data: $(this).serialize(),
						type: 'POST',
						success: function(msg){
							console.log(e.serialize());
							$('html, body').animate({scrollTop:$("#findenvoi").position().top}, '1000', 'swing', function() {
								$('#findenvoi').html(msg);
						 });
						}
					});
				}
				$('input, textarea, select',this).attr({"readOnly":true,"disabled":"disabled"});
				$('a.button',this).remove();//alert('ok pour envoi');
			}
		}
		$.fn.validmail = function() {
			valeur=this.val();
			var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			if(pattern.test(valeur)===false){
				this.css({"backgroundColor":"#FFCCCC"});
				return false;
			}else{return true}
		}	
		
		$.fn.initChamp=function(){
			//alert($(this).attr("name"));
			$(this).val($(this).attr("rel")).focusin(function(){
				$(this).css({"backgroundColor":""});
				if($(this).val()==$(this).attr("rel"))$(this).val("");
			}).focusout(function(){
				if($(this).val() != "" && $(this).val() != $(this).attr("rel")){
					if(recherche.test($(this).attr("name")))$(this).validmail();
				}else{
					$(this).val($(this).attr("rel"));
				}
			});
		}
		initForm=function(){
			$("input:text, textarea, select").each(function(){
				$(this).initChamp();
			});		
			$(".sendform").click(function(){
				$("#formulaire").validate();
				return false;
			});
		}
		initForm();
		var ajoutChamp=new Object();
		$("input:radio").each(function(index){
			if($(this).attr("affiche")){
				name=jQuery.trim($(this).attr("name"));
				ajoutChamp[name]=name;
			}
		});
		
		for (x in ajoutChamp){
			e=document.getElementById('add_'+ajoutChamp[x]);
			if(e){
				$("input[name="+ajoutChamp[x]+"]").click(function(){
					add='#add_'+$(this).attr("name");
					if($(this).attr("affiche")){
						aff='#'+$(this).attr("affiche");
						$(add).slideUp("slow",function(){
							$(this).html($(aff).html()).slideDown("slow");
							$("input:text, textarea, select",this).each(function(){
								$(this).initChamp();
							});
						});
					}else{
						$(add).slideUp("slow",function(){
							$(this).html("");
						});
					}
				});
			}
		}
})(jQuery);
























