(function($) {
	//declaration des variables globales de plugin
	var p;
	var imageW;
	var imageH;
	var nombreImage;
	var imageW;
	var imageH;
	var pourcentageImage;
	var adaptation;
	var widthNext;
	var heightNext;
	var auto;
	var resSetIntervale;
	var settings;
	var timer;
	var alignDesc;
	var barreDiv;
	var delaiNumber=5;
	var visibilityOverlay;
	var pl;
	var navBtn;
    // définition du plugin
	 $.fn.lightB = function(options){
		 settings = { adaptatif: false , pourcentagePhoto : 0.9 ,playing :true,  autoPlay : true, descriptionAlign:"slide", btnNav:false};
		 jQuery.extend(settings, options);
		 pourcentageImage = settings.pourcentagePhoto;
		 auto = settings.autoPlay;
		 pl = settings.playing;
		 var htmlAutoPlay;
		 htmlAutoPlay = "              <div id='contPlay'> <div id='play'><img src='/site_media/images/lightBox/play1.png' /></div> <div id='stop' style='display:none;' ><img src='/site_media/images/lightBox/pause.png' /></div> </div>";
		 alignDesc = settings.descriptionAlign;
		 navBtn = settings.btnNav;
		 //code html, de lightBox  
		 var overlayDiv = "<div id='overlay'></div>";
		 var lightBoxDiv ="<div id='lightBox'>\r\n" + 
		 		"			<div id='contCarousel'>\r\n" + 
		 		"				<div id='imageB'></div>\r\n" + 
		 		"				<div id='nextB'></div>\r\n" + 
		 		"				<div id='prevB'></div>\r\n" + 
		 		"			</div>\r\n" + 
		 		"			<div id='nav'>\r\n" + 
		 		"				<div id='fermer'></div>\r\n" + htmlAutoPlay+
		 		"				\r\n" + 
		 		"               <div id='contNav'>\r\n "+
		 		"			  <div id=\'descriptionL\'> <div id='contenuDescL'></div>  </div>" +  
		 		"               <div id='leftNav'><img src="+$festival.config.static+"/images/lightBox/prevNav.png /> </div>\r\n"+
		 		"               <div id='centreNav'> <div id='descriptionBas'></div>   </div>\r\n"+
		 		"               <div id='rightNav'><img src="+$festival.config.static+"/images/lightBox/nextNav.png /> <br /> <div id='contDelai'><input type='text' name='delai' id='delai' value='5' maxlength='3' /> <ul id='plus'> <li id='plusS'>+</li> <li id='moins'>-</li> </ul> </div> </div>\r\n"+
		 		"            </div>\r\n"+
		 		"			</div>\r\n" +  		
		 		"		</div>";
		 var overlayVar = $("#overlay").width();
		 var lightBoxVar = $("#lightBox").width();
		 var widthPage =$("#page").width();
		 var heightPage =$("#page").height();
		
		 if(overlayVar && lightBoxVar) {
		 }
		 else {
			 $("#page").prepend(lightBoxDiv);
		     $("#page").prepend(overlayDiv); 
		 } 
		 $("#overlay").width(widthPage);
		 $("#overlay").height(heightPage);
		 var parentUL = $(this).parent("li").parent('ul');
		 var nombreVideo = $(parentUL).find(".video").length;
		
		
			
		
		// $(".video").find("a").prepend
		 $("#contCarousel").append("");
		    $("#overlay").hide();
			$("#lightBox").hide();
			$("#overlay").animate( {opacity : 0.7},50);
			nombreImage = $("#liste2").find("a").length;
			for(var i=0;i<nombreImage;i++){
				var j=i+1;
				$("#liste2").find("li").eq(i).attr("id" , "img"+j);
			}
			if (!pl){
				$("#contPlay").remove();
			}
			if (!navBtn){
				$("#nextB").remove();
				$("#prevB").remove();
			}
			if(settings.descriptionAlign=="top") {
				$("#descriptionBas").hide();
				$("#descriptionL").show();
			}
			if(settings.descriptionAlign=="bottom") {
				$("#descriptionBas").show();
				$("#descriptionL").hide();
			}
			if(settings.descriptionAlign=="slide") {
				$("#descriptionBas").hide();
				$("#descriptionL").show();
			}
			$("#nextB").hide();
			$("#prevB").hide();
			p=0;
			widthNext = 97;
			heightNext = 46;
			$("#nextB").animate({opacity:0.3},20);
			$("#prevB").animate({opacity:0.3},20);
			$("#contDelai").hide();
			delaiNumber=5;
			
			////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////	
			var src;
			barreDiv = "<div id='barre'></div>";
			$(this).click(function(){
				src= $(this).attr("rel");
				var li_existe = $(this).parent("li").width();
				var liste2_existe = $("#liste2").attr("id");
				if(li_existe!=null && liste2_existe!=null){
					var idLi = $(this).parent("li").attr("id");
					var moins;
					var lengthID = idLi.length;
					if(lengthID==4) {
						moins=1;
					}
					if(lengthID==5) {
						moins=2;
					}
					if(lengthID==6) {
						moins=3;
					}
					var numberID = idLi.substring(lengthID-moins,lengthID);
			    	var intAct = parseInt(numberID);
			    	p=intAct;
			    	var act= $(this);
				}
				else {
					$("#rightNav").remove();
					$("#leftNav").remove();
				}
				$("#stop").hide();
				auto = settings.autoPlay;
			    $("#lightBox").show();
				$("#imageB").empty();
				$("#overlay").show();
				visibilityOverlay = true;
				$("#nextB").hide();
				$("#prevB").hide();
				$("#imageB").html("<div id=\'loading\'><img src=\'images/loadingF.gif\'  /></div>");
				$("#imageB").show(200);
				imageW = $("#imageB").width();
				imageH = $("#imageB").height();
				$("#loading").width(imageW+16);
				$("#loading").css( "margin-top",(imageH-32)/2 );
					var photo = new Image();
					var widthLi;
					var heightLi;
					$("#contNav").hide();
					$("#contPlay").hide();
					var parente = $(this).parent("li").hasClass("video");
					if(parente){
						if(p==nombreImage){
							$("#nextB").hide();
							$("#prevB").show();
							$("#rightNav img").hide();
							$("#leftNav img").show();
						}
						else {
							$("#nextB").show();
							$("#rightNav img").show();
						}
						if(p<=1){
							$("#prevB").hide();
							$("#nextB").show();
							$("#rightNav img").show();
							$("#leftNav img").hide();
						}
						else {
							$("#prevB").show();
							$("#leftNav img").show();
						}
						
						console.log(src);
						$("#imageB").html(src);
						$("#imageB").show();
						$("#contNav").show();
						$("#contPlay").show();
						$("#descriptionL").hide();
						if($("#imageB").find("iframe").length > 0){
							widthLi = $("#imageB").find("iframe").width();
							heightLi = $("#imageB").find("iframe").height();
						}else if($("#imageB").find("object").length > 0){
							widthLi = $("#imageB").find("object").width();
							heightLi = $("#imageB").find("object").attr("height");
						}
						heightLi = parseInt(heightLi);
						$("#contCarousel").animate({width : widthLi+40 , height :heightLi+(40) },600);
						$("#imageB").animate({width : widthLi , height :heightLi },600);
						 $("#nav").animate({width : widthLi+40},600,function() {
							 $("#nav").css("margin-top" , -15);
								$("#imageB").show();
								$("#contNav").show();
								$("#contPlay").show();
								$("#prevB").css({"margin-left" : 18 , "margin-top":(heightLi-heightNext)/2 });
								$("#nextB").css({"margin-left" : widthLi-widthNext+22 , "margin-top":(heightLi-heightNext)/2 });;
							});
						 $("#contNav").animate({width : widthLi-7 },600);
					}
					else {
					photo.onload = function() {
							if(auto) {
								$("#imageB").html("<img src='"+src+"' />");
							    $("#overlay").show()
							    $("#descriptionL").show();
							    var description = $(act).parent("li").find("img").attr("alt");
								widthLi = $("#imageB").find("img").width();
								heightLi = $("#imageB").find("img").height();
								var pourcentageImage = settings.pourcentagePhoto;
								adaptation = settings.adaptatif;
								$("#lightBox").css("top" , "8%");
								if(adaptation) {
									var widthWindow = $("#page").width();
									var heightWindow = $("#page").height();
									console.log(widthLi);
									console.log(widthWindow);
									if(widthLi>widthWindow || heightLi>heightWindow*pourcentageImage ) {	
									 var ratioWindow = widthWindow/heightWindow; 
									 var ratioImage = widthLi/heightLi;
									 var pi;
									 if(ratioWindow>=ratioImage) {
										 pi = heightWindow/heightLi;
									 }
									 if(ratioWindow<=ratioImage) {
										pi =widthWindow/widthLi;
									 }
				                     resultatW = pourcentageImage*pi*widthLi;
				                     resultatH = pourcentageImage*pi*heightLi;
				                     widthLi= resultatW;
				                     heightLi = resultatH;
									 $("#imageB").width(resultatW);
									 $("#imageB").height(resultatH);
									 $("#imageB").find("img").width(resultatW);
									 $("#imageB").find("img").height(resultatH);
									 $("#lightBox").css("top" , (heightWindow-(heightLi+55+20))/2);
									}
								}
								else {
									widthLi = $("#imageB").find("img").width();
									heightLi = $("#imageB").find("img").height();
								}
								$("#contCarousel").animate({width : widthLi+40 , height :heightLi+40 },600);
								$("#imageB").animate({width : widthLi , height :heightLi-10 },600);
								$("#nav").animate({width : widthLi+40},600,function() {
									$("#imageB").show();
									$("#contNav").show();
									$("#contPlay").show();
									if(alignDesc=="slide") {
										$("#contenuDescL").html(barreDiv+description);
									    $("#contenuDescL").animate({top:42},500);
									    $("#barre").hover(function() {
											$("#contenuDescL").animate({top:0},500);
										});
									}
									else {
										$("#contenuDescL").html(description);
									}
									 $("#descriptionBas").html(description);    
									if(intAct==nombreImage){
										$("#nextB").hide();
										$("#rightNav img").hide();
									}
									else {
										$("#nextB").show();
										$("#rightNav img").show();
									}
									if(intAct<=1){
										$("#prevB").hide();
										$("#leftNav img").hide();
									}
									else {
										$("#prevB").show();
										$("#leftNav img").show();
									} 
									$("#prevB").css({"margin-left" : 18 , "margin-top":(heightLi-heightNext)/2 });
									$("#nextB").css({"margin-left" : widthLi-widthNext+22 , "margin-top":(heightLi-heightNext)/2 });
								});
								$("#contNav").animate({width : widthLi-7},600);
								var timerImage = setTimeout(function() {
									refAuto();
								}
								,2000*3);
								clearTimeout(timerImage);
							}
							else {
								$("#overlay").hide();
							}
					}//function onload
					photo.src=src;		
				}
				return false;	
			});
			if (alignDesc=="slide") {
				$("#contCarousel").mouseout(function(){
					$("#contenuDescL").animate({top:42},500);
				});
			}
			$("#fermer").click(function(){
				$("#overlay").hide();
				$("#lightBox").hide();
				auto = false;
				refAuto();
				autoPlaying();
				$("#play").show();
				$("#contDelai").hide();
				visibilityOverlay = false;
			});
			$(window).keydown(function(event){
				if(event.keyCode==27){
					$("#overlay").hide();
					$("#lightBox").hide();
					auto = false;
					refAuto();
					autoPlaying();
					$("#play").show();
					$("#contDelai").hide();
					visibilityOverlay = false;
				}
				if(visibilityOverlay) {
					if(event.keyCode==39) {
					    nextImage();	
					}
					if(event.keyCode==37) {
					    prevImage();	
					}
					if(event.keyCode==80) {
						auto = true;
						refAuto();
						$("#stop").show();
						$("#play").hide();
						$("#contDelai").show();	
					}
					if(event.keyCode==83) {
						auto = false;
						refAuto();
						$("#stop").hide();
						$("#play").show();
						$("#contDelai").hide();
					}
					if(event.keyCode==38) {
					delaiNumber+=1;
	    			$("#delai").val(delaiNumber);
					}
					if(event.keyCode==40) {
						delaiNumber-=1;
	    				$("#delai").val(delaiNumber);
					}
				}
			});
			$("#play").click(function(){
				auto = true;
				refAuto();
				$("#stop").show();
				$("#play").hide();
				$("#contDelai").show();
			});
			$("#stop").click(function(){
				auto = false;
				refAuto();
				$("#stop").hide();
				$("#play").show();
				$("#contDelai").hide();
			});
			$("#plusS").click(function() {
    			delaiNumber+=1;
    			$("#delai").val(delaiNumber);
    		});
    		$("#moins").click(function() {
    				delaiNumber-=1;
    				$("#delai").val(delaiNumber);
    		});
			$("#nextB").click(function(){
				nextImage();
			});
			$("#rightNav img").click(function(){
				nextImage();
			});
			$("#prevB").click(function(){
				prevImage();
			});
			$("#leftNav img").click(function(){
				prevImage();
			});
			$("#nextB").hover(function(){
				$(this).animate({opacity:0.8},200);
				},
				function(){
					$(this).animate({opacity:0.3},200);
			});
			$("#prevB").hover(function(){
				$(this).animate({opacity:0.8},200);
				},
				function(){
					$(this).animate({opacity:0.3},200);
			});
	};
	var src2;
	function refAuto() {
    	if(auto) {
    		if(p==nombreImage){
    			$("#nextB").hide();
    			$("#prevB").show();
    			$("#rightNav img").hide();
    			$("#leftNav img").show();
    		}
    		if(p<=1){
    			$("#prevB").hide();
    			$("#nextB").show();
    			$("#rightNav img").show();
    			$("#leftNav img").hide();
    		}
    		src2= $("#liste2").find("li").find("a").eq(p-1).attr("rel");
    		var parente = $("#liste2").find("li").eq(p-1).hasClass("video");
			if(parente){
				$("#imageB").html(src2);
				$("#imageB").show();
				$("#contNav").show();
				$("#contPlay").show();
				auto = false;
				refAuto();
				$("#stop").hide();
				$("#play").hide();
				$("#contDelai").hide();
				clearTimeout(timer);
				$("#descriptionL").hide();
				$("#contCarousel").animate({width : widthLi+40 , height :heightLi+40 },600);
				$("#imageB").animate({width : widthLi , height :heightLi },600);
				 $("#imageB").width(widthLi);
				 $("#imageB").height(heightLi);
				 $("#nav").animate({width : widthLi+40},600,function() {
					 $("#nav").css("margin-top" , -15);
						$("#imageB").show();
						$("#contNav").show();
						$("#contPlay").show();
						$("#prevB").css({"margin-left" : 18 , "margin-top":(heightLi-heightNext)/2 });
						$("#nextB").css({"margin-left" : widthLi-widthNext+22 , "margin-top":(heightLi-heightNext)/2 });;
					});
				 $("#contNav").animate({width : widthLi-7},600);
			}
			else {
				$("#descriptionL").show();
				autoPlaying();
			}
		 }
    	else {
    		clearTimeout(timer);
    	}
    }
	function autoPlaying() {
			$("#nextB").hide();
			$("#prevB").hide(20);
			$("#imageB").html("<div id=\'loading\'><img src=\'../../site_media/images/loadingF.gif\'  /></div>");
			$("#imageB").show();
			var imageW = $("#imageB").width();
			var imageH = $("#imageB").height();
			$("#loading").width(imageW+16);
			$("#loading").css( "margin-top",(imageH-32)/2 );
			var photo = new Image();
			var widthLi;
			var heightLi;
			$("#contNav").hide();
			$("#contPlay").hide();
			photo.onload = function() {
				if(auto) {
					var act= $("#liste2").find("li").find("a").eq(p-1);
						$("#imageB").html("<img src='"+src2+"' />");
						$("#overlay").show();
						 var description = $(act).parent("li").find("img").attr("alt");
						widthLi = $("#imageB").find("img").width();
						heightLi = $("#imageB").find("img").height();
						if(adaptation) {
							$("#lightBox").css("top" , "8%");
							var widthWindow = $("#page").width();
							var heightWindow = $("#page").height();
							if(widthLi>widthWindow || heightLi>heightWindow*pourcentageImage ) {
							 var ratioWindow = widthWindow/heightWindow; 
							 var ratioImage = widthLi/heightLi;
							 var pi;
							 if(ratioWindow>=ratioImage) {
								 pi = heightWindow/heightLi;
							 }
							 if(ratioWindow<=ratioImage) {
								pi =widthWindow/widthLi;
							 }
		                     resultatW = pourcentageImage*pi*widthLi;
		                     resultatH = pourcentageImage*pi*heightLi;
		                     widthLi= resultatW;
		                     heightLi = resultatH;
							 $("#imageB").width(resultatW);
							 $("#imageB").height(resultatH);
							 $("#imageB").find("img").width(resultatW);
							 $("#imageB").find("img").height(resultatH)
							 $("#lightBox").css("top" , (heightWindow-(heightLi+55+20))/2);
							}
						 }
						else {
							widthLi = $("#imageB").find("img").width();
							heightLi = $("#imageB").find("img").height();
						}
						$("#imageB").hide();
						$("#contCarousel").animate({width : widthLi+40 , height :heightLi+40 },600);
						$("#imageB").animate({width : widthLi , height :heightLi-10 },600);
						$("#nav").animate({width : widthLi+40},600,function() {
							$("#imageB").show();
							$("#contNav").show();
							$("#contPlay").show();
							if(alignDesc=="slide") {
								$("#contenuDescL").html(barreDiv+description);
							    $("#contenuDescL").animate({top:42},500);
							    $("#barre").hover(function() {
									$("#contenuDescL").animate({top:0},500);
								});
							}
							else {
								$("#contenuDescL").html(description);
							}
							 $("#descriptionBas").html(description);
							if(p==nombreImage){
								$("#nextB").hide();
								$("#prevB").show();
								$("#rightNav img").hide();
								$("#leftNav img").show();
							}
							else {
								$("#contNav").show();
								$("#contPlay").show();
								$("#prevB").show();
								$("#nextB").show();
								$("#rightNav img").show();
								$("#leftNav img").show();
							}
							$("#prevB").css({"margin-left" : 18 , "margin-top":(heightLi-heightNext)/2 });
							$("#nextB").css({"margin-left" : widthLi-widthNext+22 , "margin-top":(heightLi-heightNext)/2 });;
						});
						$("#contNav").animate({width : widthLi-7},600);
						   timer = setTimeout(function() {
							p++;
							refAuto();
						}
						,delaiNumber*1000);
				}
				else {
					$("#overlay").hide();	   
				}
			}//onload
			src2= $("#liste2").find("li").find("a").eq(p-1).attr("rel");
			photo.src=src2;
			if(p>=nombreImage) {
				p=0;
			}
	}
	// fin de fonction autoPlaying
	function nextImage() {
		if(p<nombreImage){
			p++;
			auto = false;
			refAuto();
			$("#stop").hide();
			$("#play").show();
			$("#contDelai").hide();
			$("#nextB").hide();
			$("#prevB").hide();
			$("#imageB").html("<div id=\'loading\'><img src=\'images/loadingF.gif\'  /></div>");
			$("#imageB").show();
			var imageW = $("#imageB").width();
			var imageH = $("#imageB").height();
			$("#loading").width(imageW+16);
			$("#loading").css( "margin-top",(imageH-32)/2 );
			var photo = new Image();
			var widthLi;
			var heightLi;
			$("#contNav").hide();
			$("#contPlay").hide();
			var src= $("#liste2").find("li").find("a").eq(p-1).attr("rel");
			var parente = $("#liste2").find("li").eq(p-1).hasClass("video");
			
			if(parente){
				$("#leftNav img").show();
				$("#imageB").html(src);
				$("#imageB").show();
				$("#contNav").show();
				$("#contPlay").show();
				$("#descriptionL").hide();
				if($("#imageB").find("iframe").length > 0){
					widthLi = $("#imageB").find("iframe").width();
					heightLi = $("#imageB").find("iframe").height();
				}else if($("#imageB").find("object").length > 0){
					widthLi = $("#imageB").find("object").width();
					heightLi = $("#imageB").find("object").attr("height");
				}
				heightLi = parseInt(heightLi);
				$("#contCarousel").animate({width : widthLi+40 , height :heightLi+40 },600);
				$("#imageB").animate({width : widthLi , height :heightLi },600);
				// $("#imageB").width(widthLi);
				// $("#imageB").height(heightLi);
				 $("#nav").animate({width : widthLi+40},600,function() {
					 $("#nav").css("margin-top" , -15);
						$("#imageB").show();
						$("#contNav").show();
						$("#contPlay").show();
						$("#prevB").css({"margin-left" : 18 , "margin-top":(heightLi-heightNext)/2 });
						$("#nextB").css({"margin-left" : widthLi-widthNext+22 , "margin-top":(heightLi-heightNext)/2 });;
					});
				 $("#contNav").animate({width : widthLi-7 },600);
			}
			else {
			photo.onload = function() {
				var act= $("#liste2").find("li").find("a").eq(p-1);
					$("#imageB").html("<img src='"+src+"' />");
					$("#overlay").show();
					$("#descriptionL").show();
					 var description = $(act).parent("li").find("img").attr("alt");
					widthLi = $("#imageB").find("img").width();
					heightLi = $("#imageB").find("img").height();
					var pourcentageImage = settings.pourcentagePhoto;
					if(adaptation) {
						$("#lightBox").css("top" , "8%");
						var widthWindow = $("#page").width();
						var heightWindow = $("#page").height();
						if(widthLi>widthWindow || heightLi>heightWindow*pourcentageImage ) {
						 var ratioWindow = widthWindow/heightWindow; 
						 var ratioImage = widthLi/heightLi;
						 var pi;
						 if(ratioWindow>=ratioImage) {
							 pi = heightWindow/heightLi;
						 }
						 if(ratioWindow<=ratioImage) {
							pi =widthWindow/widthLi;
						 }
	                     resultatW = pourcentageImage*pi*widthLi;
	                     resultatH = pourcentageImage*pi*heightLi;
	                     widthLi= resultatW;
	                     heightLi = resultatH;
						 $("#imageB").width(resultatW);
						 $("#imageB").height(resultatH);
						 $("#imageB").find("img").width(resultatW);
						 $("#imageB").find("img").height(resultatH)
						 $("#lightBox").css("top" , (heightWindow-(heightLi+55+20))/2);
						}
					}
					else {
						widthLi = $("#imageB").find("img").width();
						heightLi = $("#imageB").find("img").height();
					}
					$("#imageB").hide();
					$("#contCarousel").animate({width : widthLi+40 , height :heightLi+40 },600);
					$("#imageB").animate({width : widthLi , height :heightLi-10 },600);
					$("#nav").animate({width : widthLi+40},600,function() {
						$("#imageB").show();
						$("#contNav").show();
						$("#contPlay").show();
						if(alignDesc=="slide") {
							$("#contenuDescL").html(barreDiv+description);
						    $("#contenuDescL").animate({top:42},500);
						    $("#barre").hover(function() {
								$("#contenuDescL").animate({top:0},500);
							});
						}
						else {
							$("#contenuDescL").html(description);
						}
						 $("#descriptionBas").html(description);
						if(p==nombreImage){
							$("#nextB").hide();
							$("#prevB").show();
							$("#rightNav img").hide();
							$("#leftNav img").show();
						}
						else {
							$("#contNav").show();
							$("#contPlay").show();
							$("#prevB").show();
							$("#nextB").show();
							$("#rightNav img").show();
							$("#leftNav img").show();
						}
						$("#prevB").css({"margin-left" : 18 , "margin-top":(heightLi-heightNext)/2 });
						$("#nextB").css({"margin-left" : widthLi-widthNext+22 , "margin-top":(heightLi-heightNext)/2 });;
					});
					$("#contNav").animate({width : widthLi-7},600);
				}
			}
			
			photo.src=src;
		}
		if(p==nombreImage){
			$("#nextB").hide();
			$("#prevB").show();
			$("#rightNav img").hide();
			$("#leftNav img").show();
		}
	}// fin de fonction nextImage
	function prevImage() {
		if(p>1){
			p--;
			auto = false;
			refAuto();
			$("#stop").hide();
			$("#play").show();
			$("#contDelai").hide();
			$("#nextB").hide(20);
			$("#prevB").hide();
			$("#imageB").html("<div id=\'loading\'><img src=\'images/loadingF.gif\'  /></div>");
			$("#imageB").show();
			var imageW = $("#imageB").width();
			var imageH = $("#imageB").height();
			$("#loading").width(imageW+16);
			$("#loading").css( "margin-top",(imageH-32)/2 );
			var photo = new Image();
			var widthLi;
			var heightLi;
			$("#contNav").hide();
			$("#contPlay").hide();
			var widthWindow;
			var heightWindow;
			var ratioWindow; 
			var ratioImage;
			var pi;
			var src= $("#liste2").find("li").find("a").eq(p-1).attr("rel");
			var parente = $("#liste2").find("li").eq(p-1).hasClass("video");
			if(parente){
				//$("#nextB").show();
				$("#rightNav img").show();
				$("#imageB").html(src);
				$("#imageB").show();
				$("#contNav").show();
				$("#contPlay").show();
				$("#descriptionL").hide();
				if($("#imageB").find("iframe").length > 0){
					widthLi = $("#imageB").find("iframe").width();
					heightLi = $("#imageB").find("iframe").height();
				}else if($("#imageB").find("object").length > 0){
					widthLi = $("#imageB").find("object").width();
					heightLi = $("#imageB").find("object").attr("height");
				}
				heightLi = parseInt(heightLi);
				$("#contCarousel").animate({width : widthLi+40 , height :heightLi+40 },600);
				$("#imageB").animate({width : widthLi , height :heightLi },600);
				 $("#nav").animate({width : widthLi+40},600,function() {
					 $("#nav").css("margin-top" , -15);
						$("#imageB").show();
						$("#contNav").show();
						$("#contPlay").show();
						$("#prevB").css({"margin-left" : 18 , "margin-top":(heightLi-heightNext)/2 });
						$("#nextB").css({"margin-left" : widthLi-widthNext+22 , "margin-top":(heightLi-heightNext)/2 });;
					});
				 $("#contNav").animate({width : widthLi-7 },600);
			}
			else {
			photo.onload = function() {
				var act= $("#liste2").find("li").find("a").eq(p-1);
					$("#imageB").html("<img src='"+src+"' />");
					$("#overlay").show(0,function() {
					//$(act).attr("href" , src);
					});
					$("#descriptionL").show();
					 var description = $(act).parent("li").find("img").attr("alt");
					widthLi = $("#imageB").find("img").width();
					heightLi = $("#imageB").find("img").height();
					var pourcentageImage = settings.pourcentagePhoto;
					if(adaptation) {
						$("#lightBox").css("top" , "8%");
						widthWindow = $("#page").width();
						heightWindow = $("#page").height();
						if(widthLi>widthWindow || heightLi>heightWindow*pourcentageImage ) {
						 ratioWindow = widthWindow/heightWindow; 
						ratioImage = widthLi/heightLi;
						 
						 if(ratioWindow>=ratioImage) {
							 pi = heightWindow/heightLi;
						 }
						 if(ratioWindow<=ratioImage) {
							pi =widthWindow/widthLi;
						 }
	                     resultatW = pourcentageImage*pi*widthLi;
	                     resultatH = pourcentageImage*pi*heightLi;
	                     widthLi= resultatW;
	                     heightLi = resultatH;
						 $("#imageB").width(resultatW);
						 $("#imageB").height(resultatH);
						 $("#imageB").find("img").width(resultatW);
						 $("#imageB").find("img").height(resultatH)
						 $("#lightBox").css("top" , (heightWindow-(heightLi+55+20))/2);
						}
					}
					else {
						widthLi = $("#imageB").find("img").width();
						heightLi = $("#imageB").find("img").height();
					}
					$("#imageB").hide();
					$("#contCarousel").animate({width : widthLi+40 , height :heightLi+40 },600);
					$("#imageB").animate({width : widthLi , height :heightLi-10 },600);
					$("#nav").animate({width : widthLi+40},600,function() {
						$("#imageB").show();
						$("#contNav").show();
						$("#contPlay").show();
						if(alignDesc=="slide") {
							$("#contenuDescL").html(barreDiv+description);
						    $("#contenuDescL").animate({top:42},500);
						    $("#barre").hover(function() {
								$("#contenuDescL").animate({top:0},500);
							});
						}
						else {
							$("#contenuDescL").html(description);
						}
						 $("#descriptionBas").html(description);
						if(p<=1){
							$("#prevB").hide();
							$("#nextB").show();
							$("#rightNav img").show();
							$("#leftNav img").hide();
						}
						else {
							$("#contNav").show();
							$("#contPlay").show();
							$("#prevB").show();
							$("#nextB").show();
							$("#rightNav img").show();
							$("#leftNav img").show();
						}
						$("#prevB").css({"margin-left" : 18 , "margin-top":(heightLi-heightNext)/2 });
						$("#nextB").css({"margin-left" : widthLi-widthNext+22 , "margin-top":(heightLi-heightNext)/2 });;
					});
					$("#contNav").animate({width : widthLi-7},600);	
				}
			}
			photo.src=src;
		}
		if(p<=1){
			$("#prevB").hide();
			$("#nextB").show();
			$("#rightNav img").show();
			$("#leftNav img").hide();
		}
	}// fin de fonction prevImage 
})(jQuery);
