// JavaScript Document

var mvt=false;


//--- effet mouvement
jQuery.extend( jQuery.easing,
{

	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	}

});


//--- fin du mouvement
function callback(){
	mvt=false;
}

//---init
$(function(){ 

	//var step =  $("#galerie ul").width();
	var step = 528;
	var marge = 2; //marge right entre les LI
	var moveX = (130 + marge)*4;
	var $subnav = $("#galerie ul");
	subListItems = $subnav.find("li").size();
	


	//$subnav.width(subListItems*moveX);
	$subnav.width(subListItems*(130+marge));
	
	$("a.lessthumbz").css({display: "none"})
	
	if 	($subnav.width() <= step){	
		$("a.morethumbz").css({display: "none"})
	}
	
	
	
		
	
	$("a.morethumbz").click(function () {
		
		
		if (mvt==false){
			mvt=true;
		
			if($subnav.css("marginLeft").replace("px", "") <= -$subnav.width() + step + moveX +marge){
				$(this).fadeOut("slow");
			}
			if($subnav.css("marginLeft") <= 1+"px"){
				$("a.lessthumbz").fadeIn("slow");
			}
			
			$subnav.filter("ul:not(:animated)").animate({ marginLeft: parseInt($subnav.css("marginLeft").replace("px", "")) - moveX }, 500, "easeOutSine",callback);
			
			return false;
		}
	});
	
	
	$("a.lessthumbz").click(function () { 

		if (mvt==false){
			mvt=true;
		
			if($subnav.css("marginLeft").replace("px", "") <= $subnav.width()+ moveX){
				$("a.morethumbz").fadeIn("slow");
			}
			
			if($subnav.css("marginLeft").replace("px", "") >= -moveX){
				$(this).fadeOut("slow");
			}
				
			$subnav.filter("ul:not(:animated)").animate({ marginLeft: parseInt($subnav.css("marginLeft").replace("px", "")) + moveX }, 500, "easeOutSine", callback);
			
			
			return false;
		}
	});




}); 

