(function($) {
	$.fn.idwebFade = function (settings) {
		var idFa=this;

		options={
			duree_affiche : 3000,
			duree_transition : 3000,
			elements: '',
			effet_in: { },
			effect_out: { }
		};
		
		var options = $.extend(options, settings);

		$(idFa).css({
			position: 'relative',
			overflow: 'hidden'
		});
		
		idFa.init=function(){
			if($(options.elements).size()<2)
				return true;
			
			var max_height=0;
			$(options.elements).each(function(){
				if($(this).height()>max_height)
					max_height=$(this).height();
			});
			
			$(options.elements).css({
				position: 'absolute',
				left: '0px',
				top: '0px',
				zIndex: function(index){return (5000)},
				height: max_height+'px',
				paddingTop: function(){ return parseInt((max_height-$('img', $(this)).height()) / 2)+'px'; }
			});
			
			/*$(options.elements+' :first-child').each(function(){
				$(this).parent().css({
					paddingTop: parseInt((max_height-$('img', $(this)).height()) / 2)+'px',
					height: parseInt(max_height - parseInt((max_height-$('img', this).height()) / 2))+'px'
				});
			});*/
			
			$(idFa).css('height', max_height+'px');
			
			setTimeout(function(){ idFa.animation_start(); }, options.duree_affiche);
		}
		
		idFa.animation_start=function(){
			$(options.elements+':last').animate(options.effet_out, options.duree_transition, function(){
				$(this).css('zIndex', function(){
					return $(this).css('zIndex')-1;
				});

				$(this).css(options.effet_in);

				$(idFa).prepend($(this).remove());
				
				setTimeout(function(){ idFa.animation_start(); }, options.duree_affiche);
			});
		}
		
		idFa.init();
	}	
})(jQuery);
