(function($) {
	$.fn.slideShow = function(options){
		var defaults = {
			show_width : 960,
			show_height: 290,
			show_element: 3,
			nav_width: 30,
			nav_next : "next",
			nav_prev : "prev",
			slide_speed: 500
		};
		
		// On Ã©tend les options
		var opt = $.extend({}, defaults, options);
		
		// On dÃ©finie la largeur et la hauteur de ce qui sera visible 
		var wrap_width = (opt.show_width * opt.show_element) ;
		var wrap_height = opt.show_height;
		
		// On crÃ©e une variable pour notre objet
		var obj = $(this);
		
		// On compte le nombre d'enfant 
		var objChild = obj.children().size();
		
		// On crÃ©e une div qui englobe le tout
		obj.wrap("<div id='"+obj.attr("class")+"_slide'></div>");
		
		// On vÃ©hicule une variable currentlymoving sur notre objet
		obj.data("currentlyMoving", false);
		
		// Creation d'une variable pour l'enfant qui est visible
		var currentlyShow = 0;
		
		// On crÃ©e une variable pour notre conteneur principal
		var wrap = $("#"+obj.attr("class")+"_slide");
		
		// Opacity des images non sÃ©lÃ©ctionnez
		var opacityThumb = 0.2;

		// On applique les css nÃ©cessaire pour le fonctionnement
		wrap.css({
			"width":wrap_width+"px",
			"height":wrap_height+"px",
			"overflow":"hidden",
			"float":"left" ,
			"position":"relative"
		});
		obj.css({
			"height":wrap_height+"px",
			"width":(opt.show_width * objChild)+"px",
			"overflow":"hidden"
		});
		$("> li", obj).css({
			"float":"left",
			"position":"relative"
		});
		$("#thumb > li:first").addClass("over");
		
		$("#thumb > li").css({
			"opacity":opacityThumb
		}).click(function(){
			i = $("#thumb > li").index(this);
			moveMe(i);		
			return false;
		});
				
		// On crÃ©e la navigation
		wrap.before("<span class='nav_prev' style='z-index:400;width:"+opt.nav_width+"px;height:"+wrap_height+"px;float:left;display:block;cursor: pointer;position:relative;'>"+opt.nav_prev+"</span>");
		wrap.after("<span class='nav_next' style='z-index:400;width:"+opt.nav_width+"px;height:"+wrap_height+"px;float:right;display:block;cursor: pointer;position:relative;margin-left:-30px;'>"+opt.nav_next+"</span>");
		$(".nav_next").after("<span style='clear:both;display:block;'></span>");
		wrap.css("margin-left","-30px");
		$(".nav_prev").css({"opacity":0.6});
		$(".nav_next").css({"opacity":0.6});
		
		// On crÃ©e les fonctions pour la navigation
		$(".nav_next").click(function(){
			moveMe(currentlyShow + 1);
			return false;
		});
		$(".nav_prev").click(function(){
			moveMe(currentlyShow - 1);
			return false;
		});
		
		function moveMe(nb){
			if(obj.data("currentlyMoving") === false){
				obj.data("currentlyMoving",true);
				if(nb > (objChild - opt.show_element)){
					currentlyShow = 0;
				} else if( nb < 0 ){
					currentlyShow = (objChild - opt.show_element);
				} else {
					currentlyShow = nb;
				}
				newPosition = currentlyShow * opt.show_width *-1;


				$(" > li",obj).animate({"left":newPosition},opt.slide_speed,"linear",function(){
					obj.data("currentlyMoving",false);
				});
				
			}
		}

	};
})(jQuery);