(function($) {
	var parent_show;
	var nombre_image_show;
	var widthImage;
	var pas_show;
	var contBtns_show;
	var contCercles_show;
	var act_show;
	var divImages_show;
	var mode_show;
	var alignement_show;
	var easing_show;
	var duree_show;
	var description_show;
	var intAct_show;
	var intAct_show2;
	var intAct_show3;
	var fleche_show;
	var navWidth_show;
	var galleryWidth_show;
	var diffWidth_show;
    var nombrePas_show;
	var nombreThumbs_show;
	var widthNavDefault_show;
	var widthLi_show;
	var miniPas_show;
	var lesPadding_show;
	var heightNavAligner_show;
	var widthNavAligner_show;
	var autoPlay_show;
	var autoPlay_show2;
	var nombreAuto_show;
	var startImage_show;
	var refSetIntervale_show;
	var cercle_show = 0;
	 $.fn.slide_show = function(options){
		 settings = { type: "" , align : "center" , easing_show : "easeInOutQuint" ,  delay : 500 , divDscription: "" , arrow : true , nombreThumb : 10 , start : 3, play_auto:true};
		 jQuery.extend(settings, options);
		 parent_show_show=this;
		 mode_show=settings.type;
		 alignement_show = settings.align;
		 easing_show=settings.easing_show;
		 duree_show = settings.delay;
		 description_show = settings.divDescription;
		 fleche_show=settings.arrow;
		 lespadding=16;
		 nombreThumbs_show = settings.nombreThumb;
		 startImage_show = settings.start;
		 autoPlay_show2 = settings.play_auto;
		/* $(this).find("ul").wrap('<div id="images_show" />');*/
		 divImages_show = $("#image_show");
		 nombre_image_show = $(this).find("img").length;
		 widthImage = $(parent_show_show).find("img").width();
		 heightImage = $(parent_show_show).find("img").height();
		 //widthImage
		 $(divImages_show).width((746+50)*(nombre_image_show));
		 $(divImages_show).css("position" , "relative");
		 $(parent_show_show).find("li").css({"float" : "left" , "display" : "block"});
		 contBtns_show = [nombre_image_show];
		 if(nombreThumbs_show < nombre_image_show) {
			 alignement_show = "center";
		  }
		 if(nombreThumbs_show>nombre_image_show) {
			 nombreThumbs_show = nombre_image_show;
		 }
		 //les condition de mode_show de navigation
				 cercle_show=1;
				 createCercle();
				widthLi_show = $("#nav_show").find("li").width();
				 widthNavDefault_show = (widthLi_show+lespadding)*(nombre_image_show+3);
				 var widthSpeciale = 567;
				// navWidth_show = $("#nav_show").width(nombre_image_show*(17+10));
				 navWidth_show = $("#nav_show").width( widthSpeciale);
				 var navHeight = $("#nav_show").height();
				 $("#cercles_show").width(nombre_image_show*(17+10));
				 var demiImages;
				 if(startImage_show == 0 || startImage_show == "" ) {
					 demiImages = Math.round(nombre_image_show/2);
				 }
				 else {
					 demiImages = startImage_show;
				 }
				 //var intDemiImages = demiImages-1;
				 pas_show = demiImages-1;
				 intAct_show2=pas_show;
				 nombreAuto_show = pas_show;
				  $(".cercle_show").animate({opacity : 1},200);
				  $(".cercle_show").removeClass("cercle_active_show");
				  $(".cercle_show").addClass("cercle_normale_show");
				  $("#img_show"+demiImages).removeClass("cercle_normale_show");
				  $("#img_show"+demiImages).addClass("cercle_active_show");
				 //$("#img_show"+demiImages).animate({opacity : 1},200);widthImage
				 $(divImages_show).animate({ left: -(473*(demiImages-1)) }, {duration: duree_show,easing_show: easing_show}); 
				 var selectN = $("#slide_show").find("li").eq(demiImages-1).find("img").attr("alt");
				 $("#description_slider_home").html(selectN);
				 var espaceLeftAjouter2;
				 var nombreThumbSupporter2 = Math.round(widthImage /54);
				 if(nombre_image_show>nombreThumbSupporter2) {
					 espaceLeftAjouter2 = -10;
				 }
				 else {
					 espaceLeftAjouter2 = 5;
				 }
				 heightNavAligner_show = (navHeight+5);
				 widthNavAligner_show = (nombre_image_show*(17+10))+espaceLeftAjouter2;
				 alignement_show = settings.align;				 
			 autoPlay_show = 0;
			 if(autoPlay_show2){
				 autoPlay_show = 1;
				 refAuto ();
				 $("#play_show").hide();
				 $("#pause_show").show();
			 }
			 var divPlay ='<div id="play_show"></div>';
			 var divPause ='<div id="pause_show"></div>';
			 $("#slide_show").append(divPlay);
			 $("#slide_show").append(divPause);
			 $("#pause_show").hide();
			 $("#play_show").hide();
			 $("#play_show").click(function(){
				 autoPlay_show = 1;
				 refAuto ();
				 $("#play_show").hide();
				 $("#pause_show").show();
			 });
			 
			 $("#pause_show").click(function(){
				 autoPlay_show = 0;
				 refAuto ();
				 $("#pause_show").hide();
				 $("#play_show").show();
			 });
		$(this).width(widthImage);
		$(this).height(heightImage+30);
		 var parent_showWidth = $(this).width();
		 var parent_showHeight = $(this).height();
		 $(description_show).width(parent_showWidth+2); 

		 // les condition de l'alignement_show
		 if(alignement_show=="right" || alignement_show=="center") {
				// alert("le nom de type de carousel n'est pas_show valide");
			 }
			 else {
				alignement_show="center";
			 }
		 if(alignement_show =="right") {
			//$("#nav_show").css({left :parent_showWidth-widthNavAligner_show , top :parent_showHeight-heightNavAligner_show});
		 }
		 if (alignement_show =="center") {
			 var centrerThumbs = (parent_showWidth-widthNavAligner_show)/2;
			 //$("#nav_show").css({left :centrerThumbs , top :parent_showHeight-heightNavAligner_show});
		 }
		 $(".cercle_show").click(function () {
			  var idAct = $(this).attr("id");
			  var pa = idAct.indexOf("w",1); 
			  var apresG = idAct.substring(pa+1,pa+3);   
			  act_show = parseInt(apresG);
			 intAct_show3 = act_show-1; 
			// var titre = $(".video").eq(act_show-1).find("img").attr("alt");
			 var titre = $(this).find("img").eq(1).attr("alt");
			 console.log($(this).find("img").eq(1));
			 $("#description_slider_home").html(titre);
			$(".cercle_show").removeClass("cercle_active_show");
			 $(".cercle_show").addClass("cercle_normale_show");
			 $(this).removeClass("cercle_normale_show");
			 $(this).addClass("cercle_active_show");
			 pas_show=act_show;
			 nombreAuto_show=act_show;
			 autoPlay_show = 0;
			 refAuto ();
			 $("#pause_show").hide();
			 $("#play_show").hide();
			 //widthImage
			 $("#image_show").animate({ left: -(473*(act_show-1)) }, {duration: duree_show,easing_show: easing_show});
			 $("#object_video").html("");
			 $("#object_video").hide();
			 $("#description_slider_home").show();
			 return false;
		 })
    };
    //fonction de creation les cercles de navigation
 
    function createCercle () {
    	/*var num=1;
    	var divCercle = '<div id="nav_show"><div id="cercles_show"></div></div>';
    	$("#cont_nav_show").append(divCercle);
        for(var i =0 ;i<nombre_image_show;i++) {
        	num = i+1;
        	//var srcCercle ="/site_media/images/cercle.png";
        	contBtns_show[i]='<div id=img_show'+num+' class="cercle_show"></div>';
        	$("#cercles_show").append(contBtns_show[i]);
        }*/
    }
    function refAuto() {
    	if(autoPlay_show==1) {
			refSetIntervale_show = setInterval(function(){
					nombreAuto_show++;
					if(nombreAuto_show>nombre_image_show-1) {
						nombreAuto_show=0;
					}
						autoPlaying();
						
					},duree_show*2.5);
		 }
    	else {
    		clearInterval(refSetIntervale_show);
    	}
    }
    function autoPlaying() {
    	$("#play_show").hide();
		$("#pause_show").show();
    	intAct_show= nombreAuto_show;
		pas_show=nombreAuto_show;
		miniPas_show=nombreAuto_show;
		intAct_show2=nombreAuto_show;
		intAct_show3=nombreAuto_show;
		var act_show = nombreAuto_show+1;
		 var title = $("#slide_show").find("li").eq(act_show-1).find("img").attr("alt");
		 $("#description_slider_home").html(title);
		 //widthImage
		  $(divImages_show).animate({ left: -(473*pas_show) }, {duration: duree_show,easing_show: easing_show});
			 $("#object_video").html("");
			 $("#object_video").hide();
		  if(nombreThumbs_show >= nombre_image_show) {
			  var cond=0;
		  }
		  else {
			  $("#miniGallery_show").animate({ left: -((widthLi_show+lespadding)*pas_show+2+(widthLi_show+nombre_image_show))+(widthNavDefault_show/2) }, {duration: duree_show,easing_show: easing_show});
		  }
			 if(cercle_show==1) {
				 $(".cercle_show").removeClass("cercle_active_show");
				 $(".cercle_show").addClass("cercle_normale_show");
				 $("#img_show"+act_show).removeClass("cercle_normale_show");
				 $("#img_show"+act_show).addClass("cercle_active_show");
				 console.log("autoplying");
			 }
			 else {
				 $("#img_show"+act_show).css("opacity" , 1);
				 $("#nav_show li img").css("opacity" , 0.5);
				 $("#nav_show li a").css("opacity" , 0.5);
				 $("#img_show"+act_show).children("a").css("opacity" , 1);
				 $("#img_show"+act_show).children("img").css("opacity" , 1);
			 }  	
    }
})(jQuery);
