(function( $ ) {
	$.fn.diaporama = function(myWidth, myHeight) {
		var i = 0;
        var time = 20000;
        var mvtTime = 600;
		var nbr = this.children('.containerDiaporama').children('li').size();
		var length = myWidth*nbr;
		var root = this.children('.containerDiaporama');
		var navbar = this.find('.navigationDiaporama li a');
		this.css({
			width: myWidth,
			height: myHeight
		});
		root.css({
			width: length,
			height: myHeight
		});
		root.children('li').css({
			width: myWidth,
			height: myHeight
		});
		root.children('li').each(function(e) {
				var imgCharg = $(this).children('img');
				imgCharg.load(function(){
					if ($(this).height() < myHeight) {
						$(this).css({
							marginTop : ''+(myHeight-$(this).height())/2+'px'
						});
					};
				});
		});
		if( nbr > 1 ) {
			this.children('.navigationDiaporama').css('display', 'block');
			var animation = function(){
				i++;
				if(i === nbr) { i = 0 }
				root.animate({
					left:-(i*myWidth)
				}, mvtTime, 'easeOutQuart');
			}
			var timer = setInterval(animation, time);
			this.find('.navigationDiaporama li a').hover(function() {
				clearInterval(timer);
			},function() {
				timer = setInterval(animation, time);
			}).click(function() {
				switch($(this).attr('class')) {
					case 'left':
							if (i <= 0) {
									i = nbr-1;
							} else {
								i--;
							};
						break;
					case 'right':
							if (i >= (nbr-1)) {
									i = 0;
							} else {
								i++;
							};
						break;
				}
				root.animate({
					left:-(i*myWidth)
				}, mvtTime, 'easeOutQuart');
				return false;
			});
		}
	};
})( jQuery );
