(function($) {

	// Variables globales de la classe
	var
		show = '',
		hide = '',
		total = '',
		selected = 'selected',
		prefixClass = '',
		list = '',
		screen = '',
		periodical_exec = 'null',
		period = 5000,
		pointerDecal = 0;
	
	/*
		Initialization
	*/

	$(function() {
	});


	/*
		API
	*/

	$.gallery = function() {
	};
	
	$.fn.gallery = function(list, customPeriod) {
		
		//	Configs
		period = customPeriod || period;
		screen = $(this);
		listId = list;
		list = $('#'+list);
		total = $('li', screen).length;
		
		show = prefixClass+total;
		$( 'li img', screen).each(function(){
			$(this).hide();
		});
		
		//	Génération du pointeur de position
		list.append( '<p id="pointer"></p>' );
		list.append( '<div id="legend"><p></p></div>' );
		pointerDecal = $('#pointer').width()/2;
		
		hide = total;
		show = 1;
		
		if( total>1 ){
			appear();
			
			//	Binding Mode
			$( 'li', list).each(function(){
			
				$(this).bind("mouseover", function(e){
					
					clearInterval(periodical_exec);
					periodical_exec = 'null';
					
					var actuel = $(this).attr('class');
					actuel = actuel.replace( ' '+selected, '' );
					
					if( show != actuel ){
					
						hide = show;
						show = actuel;
						appear();
					}
					
				});
				
				//periodical();
	
			});
		}else{
			$('li.'+show+' img', screen).fadeIn('slow');	
		};
		
	}


	/*
		Internal functions
	*/
	
	function appear(){
				
		$('li.'+show+' img', screen).fadeIn('slow');
		$('li.'+hide+' img', screen).fadeOut('slow');
		
		if( 'null' == periodical_exec )
			periodical();
	
	}//	appear()
	
	function auto_mode(){
		
		hide = show;
		if( total == show )
			show = 1;
		else
			++show;
		appear();
		
	}//	auto_mode()
	
	function periodical(){
		
		periodical_exec = setInterval( auto_mode, period );
		
	}//	periodical()

})(jQuery);
