$(document).ready(
    function () 
    {
		$("#SliderButtonUp a").click(function() { move("down"); });
		$("#SliderButtonDown a").click(function() { move("up"); });
    	
    	positionAllThumbnails();
    	positionAllPictures();
    	setThumbnailClick();

		function move(direction)
    	{
    		moveThumbs(direction);
    		movePictures(direction);
    		setThumbnailClick();
    	}
    	
    	function setThumbnailClick()
    	{
    		$("#SliderThumbs li").unbind();
    		$("#SliderThumbs li.active").prev().click(function() { move("down"); });
    		$("#SliderThumbs li.active").next().click(function() { move("up"); });
    	}

    	function positionAllThumbnails()
    	{
    		var center = 127;
    		var tmp = $("#SliderThumbs li.active");
    		tmp.css("top", center + "px");
    		
    		var i = 1;
    		while (tmp.prev().length)
    		{
    			tmp = tmp.prev();
    			tmp.css("top", (center - i * 96) + "px");
    			i++;
    		}
    		
    		var tmp = $("#SliderThumbs li.active");
    		
    		var i = 1;
    		while (tmp.next().length)
    		{
    			tmp = tmp.next();
    			tmp.css("top", (center + i * 96) + "px");
    			i++;
    		}
    	}
    	
    	function positionAllPictures()
    	{
    		var center = 0;
    		var tmp = $("#SliderPictures li.active");
    		tmp.css("top", center + "px");
    		
    		var i = 1;
    		while (tmp.prev().length)
    		{
    			tmp = tmp.prev();
    			tmp.css("top", (center - i * 350) + "px");
    			i++;
    		}
    		
    		var tmp = $("#SliderPictures li.active");
    		
    		var i = 1;
    		while (tmp.next().length)
    		{
    			tmp = tmp.next();
    			tmp.css("top", (center + i * 350) + "px");
    			i++;
    		}

    	}
    	
    	function moveThumbs(direction)
    	{
    		var activeThumbnail = $("#SliderThumbs li.active");
    		
    		// Vers le bas
    		if (direction == "down")
    		{
 				$("#SliderThumbs li:last-child").prependTo("#SliderThumbs");
 				
 				positionAllThumbnails();
 				
    			$("#SliderThumbs li").stop().animate(
    				{top: '+=96'}, 
    				300, 
    				function(){}
    			);
    			
 				activeThumbnail.prev().addClass("active");
    		}
    		
    		// Vers le haut
    		else
    		{
    			var activeThumbnail = $("#SliderThumbs li.active");

 				$("#SliderThumbs li:first-child").appendTo("#SliderThumbs");
 			
 				positionAllThumbnails();
 			
    			$("#SliderThumbs li").stop().animate(
    				{top: '-=96'}, 
    				300, 
    				function(){ }
    			);
    			
	 			activeThumbnail.next().addClass("active");
    		}
    		
    		activeThumbnail.removeClass("active");
    	}
    	
    	function movePictures(direction)
    	{
    		var activePicture = $("#SliderPictures li.active");
    		
    		// Vers le bas
    		if (direction == "down")
    		{
 				$("#SliderPictures li:last-child").prependTo("#SliderPictures");
 				
 				positionAllPictures();
 				
    			$("#SliderPictures li").stop().animate(
    				{top: '+=350'}, 
    				300, 
    				function(){ }
    			);
    			
 				activePicture.prev().addClass("active");
    		}
    		
    		// Vers le haut
    		else
    		{
 				$("#SliderPictures li:first-child").appendTo("#SliderPictures");
 			
 				positionAllPictures();
 			
    			$("#SliderPictures li").stop().animate(
    				{top: '-=350'}, 
    				300, 
    				function(){ }
    			);
    			
	 			activePicture.next().addClass("active");
    		}
    		
    		activePicture.removeClass("active");
    	}
    }
);
