(function($) {
	
/* *********************************************
 * Diaporama
 */

	$.fn.diaporama = function(t) {
		var elt 		= this,
			navbar	 	= elt.find('a'),
			count		= elt.find('.list > li').size(),
			widthLi		= elt.find('.list > li').width(),
			widthUl		= widthLi * count,
			time		= t;
			if(time) var timer = setInterval(animation, time);
		elt.css('backgroundColor','black');
		elt.find('.list').width( widthUl ).children('.list > li:eq(0)').addClass('view');
		if (count > 1) {
			$(navbar).hover(function() {
				clearInterval(timer);
			}, function() {
				if(time) timer = setInterval(animation, time);
			}).click(function() {
				animation($(this).attr('class'));
				return false;
			});
		} else {
			$(navbar).hide();
		}
		function animation(e) {
				if(e!=undefined) var direction = e;
				var index = elt.find('.list > .view').index();
				if (direction == 'prev') {
					index--;
					if (index <= -1) index = count-1;
				} else {
					index++;
					if (index >= count) index = 0;
				}
				elt.find('.list > .view').removeClass('view');
				elt.find('.list > li:eq('+index+')').addClass('view');
				elt.find('.list').animate({ 'left' : -widthLi*(index) },'slow','easeOutCubic');
			}
		return elt;
	}
	
})(jQuery);
