jQuery(function( $ ){
/*
 *
 * Préchargement d'images
 *
 *
 */
	$(window).load(function () {
		$.preloadCssImages();
	});

/*
 *
 * Initialisation Facebox pour images
 *
 *
 */
	$('a[rel*=facebox]').facebox() ;

/*
 *
 * images experience
 *
 *
 */
	$("a.visu").children('span').fadeTo(0,0);
	$("a.visu1").children('span').fadeTo(0,0);
	$("a.visu2").children('span').fadeTo(0,0);
	$("a.visu3").children('span').fadeTo(0,0);
	$("a.visu4").children('span').fadeTo(0,0);
	
	
	
	$("a.visu").hover(function(){
		$(this).children('span').stop().animate({
			opacity: 0.5
		}, 300);
	},function(){
		$(this).children('span').stop().animate({
			opacity: 0
		}, 300);
	});
	
	$("a.visu1").hover(function(){
		$(this).children('span').stop().animate({
			opacity: 0.5
		}, 300);
	},function(){
		$(this).children('span').stop().animate({
			opacity: 0
		}, 300);
	});
	
	$("a.visu2").hover(function(){
		$(this).children('span').stop().animate({
			opacity: 0.5
		}, 300);
	},function(){
		$(this).children('span').stop().animate({
			opacity: 0
		}, 300);
	});
	
	$("a.visu3").hover(function(){
		$(this).children('span').stop().animate({
			opacity: 0.5
		}, 300);
	},function(){
		$(this).children('span').stop().animate({
			opacity: 0
		}, 300);
	});
	
	$("a.visu4").hover(function(){
		$(this).children('span').stop().animate({
			opacity: 0.5
		}, 300);
	},function(){
		$(this).children('span').stop().animate({
			opacity: 0
		}, 300);
	});

/*
 *
 * linkto menu
 *
 *
 */
	$("a.home").mouseover(function(){
		$("li.home").stop().animate({
			width:211
		},{duration: 145,queue: false});
	}).mouseout(function(){
		$("li.home").stop().animate({
			width:30
		},{duration: 140,queue: false});
	}).click(function(){
		$("li.home").stop().animate({
			width:30
		},{duration: 15,queue: false});
	});
	
	$("a.site").mouseover(function(){
		$("li.site").stop().animate({
			width:150
		},{ duration: 145,queue: false});
	}).mouseout(function(){
		$("li.site").stop().animate({
			width:30
		},{duration: 140,queue: false});
	}).click(function(){
		$("li.site").stop().animate({
			width:30
		},{duration: 15,queue: false});
	});
	
	$("a.site1").mouseover(function(){
		$("li.site1").stop().animate({
			width:150
		},{ duration: 145,queue: false});
	}).mouseout(function(){
		$("li.site1").stop().animate({
			width:30
		},{duration: 140,queue: false});
	}).click(function(){
		$("li.site1").stop().animate({
			width:30
		},{duration: 15,queue: false});
	});
	
	$("a.site2").mouseover(function(){
		$("li.site2").stop().animate({
			width:150
		},{ duration: 145,queue: false});
	}).mouseout(function(){
		$("li.site2").stop().animate({
			width:30
		},{duration: 140,queue: false});
	}).click(function(){
		$("li.site2").stop().animate({
			width:30
		},{duration: 15,queue: false});
	});
	
	$("a.next").mouseover(function(){
		$("li.next").stop().animate({
			width:180
		},{duration: 145,queue: false});
	}).mouseout(function(){
		$("li.next").stop().animate({
			width:30
		},{duration: 140,queue: false});
	}).click(function(){
		$("li.next").stop().animate({
			width:30
		},{duration: 15,queue: false});
	});
	
	$("a.back").mouseover(function(){
		$("li.back").stop().animate({
			width:198
		},{duration: 145,queue: false});
	}).mouseout(function(){
		$("li.back").stop().animate({
			width:30
		},{duration: 140,queue: false});
	}).click(function(){
		$("li.back").stop().animate({
			width:30
		},{duration: 15,queue: false});
	});
	
	$("a.info").mouseover(function(){
		$("li.info").stop().animate({
			width:295
		},{duration: 145,queue: false});
	}).mouseout(function(){
		$("li.info").stop().animate({
			width:30
		},{duration: 140,queue: false});
	}).click(function(){
		$("li.info").stop().animate({
			width:30
		},{duration: 15,queue: false});
	});
	
/*
 *
 * anchor
 *
 *
 */
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	
	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	//$.localScroll.defaults.axis = 'yx';
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#profil', // Could be a selector or a jQuery object too.
		queue:true,
		duration:1500
	});
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$('.navigation').localScroll({
		target: '#contain_main', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash:false,
		axis:'x',
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
	
	$('.pub').localScroll({
		target: '#contain_main', // could be a selector or a jQuery object too.
		queue:false,
		duration:1000,
		hash:false,
		axis:'x',
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
	
	$('.blanc_main').each(function() {
		var wrapper = this.id;
		$('#ss_menu' + wrapper, this).localScroll( {						
			target: $('#contain_text' + wrapper, this), 
			duration: 1000,
			hash: false,
			axis: 'y',
			queue: true,
			onBefore: function(e, anchor, $target, $wrapper){
				$('.' + wrapper + 'first').removeClass(wrapper + 'first');
				$(this).addClass(wrapper + 'first');
				this.blur();
				}
		});
		
		//test anchor local
		$('#contain_text' + wrapper).localScroll({
			target: $('#contain_text' + wrapper, this), 
			duration: 1000,
			hash: false,
			axis: 'y',
			queue: true
		});
	});	
	
/*
 *
 * formulaire
 *
 *
 */
	$('#formcontact').submit(function() {
		var final = "";
		
		nom = $(this).find("input[name=nom]").val();
		prenom = $(this).find("input[name=prenom]").val();
		courriel = $(this).find("input[name=courriel]").val();
		objet = $(this).find("input[name=objet]").val();
		message = $(this).find("textarea[name=message]").val();
		
		if(nom == "") {final += "- nom <br />";}
		if(prenom == "") {final += "- pr&eacute;nom <br />";}
		if(courriel == "") {final += "- courriel <br />";}
		if(courriel != "") {
			var verifMail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/ ;
			if(verifMail.exec(courriel) == null) {final += "- courriel incorrect. <br />";}
		}
		if(objet == "") {final += "- objet <br />";}
		if(message == "") {final += "- message <br />";}
		if(final != "") {
			$.facebox("<div class='alert'>Attention</div>Veuillez réviser le(s) champ(s) suivant(s) : <br />" + final);
			return false;
		}
		
		$('#loader').show();
		
		//post du message
		$.post("traitement/contact.php", {nom: nom, prenom: prenom, courriel: courriel, objet: objet, message: message}, function(data){
		$('#loader').hide();
		if(data!="ok"){
			$.facebox("<div class='alert'>Attention</div>" + data);
		}else{
			$.facebox("<div class='clean'>Ok!</div>Votre message a bien été envoyé!<br />");
			$('#formcontact')[0].reset();
		}
		});
		return false;
	});
});
