jQuery(function ($)  {
				var index = 0;
				var max;
				var jID;
 	$.fn.extend({ 
 		//plugin name - animatemenu
 		sweetGallery: function() {
 		
    		return this.each(function() {
    			//alert(this.id);
    			jID = this.id;
				max = $("#" + jID + " > div").length;
				//alert(max + " enfants");
				var curdiv = $("#" + jID + " > div:first");
				//alert(curdiv);
				if(max > index + 1)
				{
					$("<a href='#' id='" + jID + "_prev' class='prev'>précédent</a>").insertBefore("#" + jID + ":parent");
					$("<a href='#' id='" + jID + "_next' class='next'>suivant</a>").insertBefore("#" + jID + ":parent");
					//$("#" + jID).before("<a href='#' id='" + jID + "_prev' class='prev'>précédent</a> <a href='#' id='" + jID + "_next' class='right'>suivant</a>");
					updateNav();				
				}
				$("#" + jID + " > div:not(#" + jID + " > div:first)").hide();
				
				
    			$("#" + jID + "_next").click( function() {
					if(index >= max - 1 ) return false;
					index++;
					
					//alert(curdiv);
					curdiv.hide();
					
					curdiv = $("#" + jID + " > div:eq(" + index + ")");

					curdiv.show("slide", { direction: "left" }, 400);
					updateNav();	
					
					return false;
				});

	
				$("#" + jID + "_prev").click( function() {
					if(index == 0) return false;
					index--;
					
					curdiv.hide();
					curdiv = $("#" + jID + " > div:eq(" + index + ")");
					curdiv.show("slide", { direction: "right" }, 400);
					updateNav();					
					
					return false;
					
				});
			});
		
		}
    	
	});
		
    function updateNav() {
    	//alert(index);
    	if(index == 0)
		{
			//$("#" + jID + "_prev").removeClass("on").addClass("off");
			$("#" + jID + "_prev").css("opacity", 0.5);
		}
		else
		{
			//$("#" + jID + "_prev").removeClass("off").addClass("on");
			$("#" + jID + "_prev").css("opacity", 1);
		}
		
		
		if(index >= max - 1)
		{
			//$("#" + jID + "_next").removeClass("on").addClass("off");
			$("#" + jID + "_next").css("opacity", 0.5);
		}
		else
		{
			//$("#" + jID + "_next").removeClass("off").addClass("on");
			$("#" + jID + "_next").css("opacity", 1);
		}
    }
    

});

jQuery(function ($)  {
$("#clips").sweetGallery();
});