$(document).ready(function(){
	
	// NIVO
	if($('#slider').length )//on vérifie si l'id est présent dans la page
	{
		
		var total = $('#slider img').length;
		var rand = Math.floor(Math.random()*total);
		$('#slider').nivoSlider({
	    	startSlide:rand,
			slices:20,
			animSpeed:800,
			pauseTime:4000,
			startSlide:0,
			directionNav:true,
			directionNavHide:false,
			controlNav:true,
			controlNavThumbs:false,
	      	controlNavThumbsFromRel:false,
	      	controlNavThumbsSearch: '.jpg',
			controlNavThumbsReplace: '_thumb.jpg',
			keyboardNav:true,
			pauseOnHover:true,
			manualAdvance:false,
			captionOpacity:0.8,
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){}
		});
		//on affiche le slider que lorsqu'il est prêt
		$("#slider_slice").css("display", "block");
		$("#slider").css("display", "block");
		
	}
		
	



	if ( $('#galeries').length ){//on vérifie si l'id est présent dans la page
		$('#galeries').pajinate({
		items_per_page : 6,
			item_container_id : '.galeries_content',
			nav_panel_id : '.galeries_nav'
			//nav_label_first : '<h2>Galeries</h2>'
		});
	}
	
	
	
	/* contact */
	/*$('#contact_form').jqTransform();*/

	$(".send, .reset").click(function(){

		$(".formError").hide();

	});

	var use_ajax=true;
	$.validationEngine.settings={};

	$("#contact_form").validationEngine({
		inlineValidation: false,
		promptPosition: "centerRight",
		success :  function(){use_ajax=true},
		failure : function(){use_ajax=false},
		openDebug: true 
	 });
	
	$("#contact_form").submit(function(e){

			if(!$('#subject').val().length)
			{
				$.validationEngine.buildPrompt(".formError","* Ce champs est obligatoire","error")
				return false;
			}
			
			if(use_ajax)
			{
				$('#ajax_loading').css('visibility','visible');
				$.post('submit.php',$(this).serialize()+'&ajax=1',
				
					function(data){
						if(parseInt(data)==-1)
							$.validationEngine.buildPrompt("#captcha","* Code faux!","error");
							
						else
						{
							$("#contact_form").hide('slow').after('<h5 style="color:#fff;">Merci!</h5>');
						}
						
						$('#ajax_loading').css('visibility','hidden');
					}
				
				);
			}
			e.preventDefault();
	});
	/* easing nav */
	
	$('.scroll_link, #nav_arrow a').click(function(event){
        //prevent the default action for the click event
       

        //get the full url - like mysitecom/index.htm#home
        var full_url = this.href;
	 
        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
        var parts = full_url.split("#");
        var trgt = parts[1];

       //get the top offset of the target anchor
        var target_offset = $("#"+trgt).offset();
      var target_top = target_offset.top;

       //goto that anchor by setting the body scroll top to anchor top
        $('html, body').animate({scrollTop:target_top}, 1300,'easeInOutExpo');
		 
		event.preventDefault();
    });
	
	/*$('#header ul li a, #footer ul li a, #nav_arrow a').bind('click',function(event){
		var $anchor = $(this);
		var topOff = $($anchor.attr('hash')).offset().top;
	
		$('html, body').stop().animate({
			scrollTop: topOff
		}, 1500,'easeInOutExpo');
		/*
		if you don't want to use the easing effects:
		$('html, body').stop().animate({
			scrollTop: $($anchor.attr('href')).offset().top
		}, 1000);
		*/
		/*event.preventDefault();
	});*/
	/* main nav */
	
	
	$("#header ul.menu li a").click(function(){
  		if (!$(this).hasClass("active")) 
  		{
    		$("#header ul.menu li a.active").removeClass("active");
    		$(this).addClass("active");
  		}
	});
	
	
	/*caption*/
	$('.boxgrid.captionfull').hover(function(){
		$(".cover", this).stop().animate({top:'128px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'158px'},{queue:false,duration:160});
	});
	//Caption Sliding (Partially Hidden to Visible)
	/*$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'220px'},{queue:false,duration:160});
	});
	*/
	
	
});
