(function($){
	var max;
	var current = 0;
	var images;
	var myId;
	var index = 100;
 	$.fn.extend({ 
 		//plugin name - animatemenu
 		slideshow: function() {
 		
    		return this.each(function() {
    		
    			$("#" + this.id).css({position: 'relative'});
    			
    			myId = this.id;
	    		images = $("#" + this.id + " img");
	    		images.css({ left:0, top:0, position:'absolute' });
	    		/*images.each(function (i) {
					//alert(this + " " + i);
					$(this).css({zIndex : 100 - i}); 
					//if(i)$(this).css({opacity : 0});   			
	    			}
	    		);*/
	    		max = images.length;
				//alert("nombre d'images : " + max);
				slideImages();
				
			});
		
		}
    	
	});
	
	function slideImages()
	{
		
		$(images).eq(current).css({zIndex: index + max, opacity: 1 });
		
				var eq = current;
				if(current + 1 < max)
				{
					current++;
				}
				else {
					current = 0;
					/*images.each(function (i) {
					//alert(this + " " + i);
					//$(this).css({zIndex : 100 - i}); 
					if(i)$(this).css({opacity : 0});   			
	    			}
	    			);*/
					//$(images).eq(current).nextAll().each(function(i){alert(i + " " + this)});
					//.css({zIndex: index + max - 1, opacity: 0 });
				}
				$(images).eq(current).css({zIndex: index + max - 1, opacity: 1 });
				
				$(images).eq(eq).animate({opacity: 0}, 3000, '', function(){
				/*if(!current)
				{
					$(images).eq(max - 1).css({zIndex: index + max, opacity: 0 });
				}*/
				slideImages();
			}
		);
	}
	
})(jQuery);

jQuery(function ($)  {
	$("#slideshow-images").slideshow();
});
