var sbaches_diapo = (function() {

	var _images;


	var _animate = function(index) {

		$(_images.get(index)).fadeOut(1000);

		var next = index + 1;
		if(next == _images.length) {
			next = 0;
		}
		$(_images.get(next)).fadeIn(1000);

		setTimeout(function() {
			_animate(next);
		}, 2000);
	}


	var _p = {

		init: function() {

			_images = $('#diapo-images').children('img');

			_images.each(function(i, img) {
				if(i > 0) {
					$(img).hide();
				}
			});


			if(_images.length > 1) {

				$(window).load(function() {
					setTimeout(function() {
						_animate(0)
					}, 2000);
				});
			}
		}
	}
	return _p;
}());

$(document).ready(sbaches_diapo.init);
