(function($){
	// simplefadeshow
	$.fn.simplefadeshow = function(settings) {
		var fadeshow = $(this);
		var fadebloc = fadeshow.find(".fadeBloc");
		var liste = fadeshow.find("#menuImgs a");	 
		var options = $.extend({
			index: 1,
			maxImgs : 5,
			fdTimeOut: null,
			showDelay: 5000
		}, settings);
		
		this.each(function () {			
			fadeshow.find(".fadeBloc .desc").slice(1).hide();		
			liste.bind('click',function(event){
				event.stopPropagation();
				event.preventDefault(); 
				var n =  liste.index(this);
				if( n != (options.index-1) ) { 
					setStart(n);
					options.index = options.index + 1;
				}
			});
			
			fadeshow.bind("mouseenter", function(e) {				
				setStop(); 
			})
			.bind("mouseleave", function() {				
				options.fdTimeOut = window.setTimeout(function() {
					setStop(); 
					setAuto();
				}, options.showDelay);
			});
			
			start();
			
		});
		
		$(window).unload( function () { 		
			setStop();
			desactif();
		} );
		
		function desactif(){			
			fadeshow.unbind("mouseleave");
		}	
	
		function start() {	
			setStop();
			options.fdTimeOut = setTimeout(function(){ setAuto(); }, options.showDelay);
		}	
		
		function setAuto(){
			if( options.index >= options.maxImgs ) {
				options.index = 0;
			}
			setStart(options.index);
			options.index += 1;
			start() ;
		}
	
		function setStart(n) {				
			/*__________update menu img _______________*/	
			liste.removeClass("on");
			liste.eq(n).addClass("on");
			liste.eq(n).blur();
			/*____________update desc_______________*/
			fadebloc.find(".desc:visible").fadeOut(300,function(){
				fadebloc.find(".desc").eq(n).fadeIn(1000);
			});			
			options.index = parseInt(n);
		}
		
		function setStop(){
			window.clearTimeout(options.fdTimeOut);
			options.fdTimeOut = null;
		}	
		
		return this;
	};
})(jQuery);

jQuery(document).ready(function($) {   
	$("#fadeShow").simplefadeshow();
});
