var slideShow = new Class({

	Implements: Options,
	
	options: {
		dureeTransition: 5000,
		dureeAffichage: 1500,
		imagesSrc: false
	},
	
	initialize: function(element, options){
		this.setOptions(options);
		var imagesSrc = this.options.imagesSrc;
		var dureeAffichage = this.options.dureeAffichage;
		var dureeTransition = this.options.dureeTransition;
		
		if(element && imagesSrc){
			function slideshow(imagesSrc){
				var myImages = new Asset.images(imagesSrc, {
				    onComplete: function(){
					
					
					
					
						imagesSrc.each(function(e){
							new Element('img', {src: e}).inject(element, 'top');
						});
						
						var images = element.getElements('img');
						images.each(function(e, index){
							e.setStyle('z-index', index);
						});
						
						var currentImage = (images.length)-1;
						var inRotation = true;
						(function(){ rotation(images); }).delay(dureeAffichage);
						
						function rotation(images){
							var backEffect = new Fx.Morph(images[currentImage], {duration: 20, transition: Fx.Transitions.Cubic.easeOut});						
							images[currentImage].set('morph', {
								duration: dureeTransition,
								transition: 'cubic:out',
								'onComplete': function(e){
									if(inRotation==true){
										images.each(function(el, index){
											var currentIndex = el.getStyle('z-index');
											el.setStyle('z-index', (parseInt(currentIndex)+1));
										});
										backEffect.start({
											opacity: 1,
											zIndex: 0
										});
										if(currentImage==0){currentImage = (images.length)-1;}
										else{currentImage--;}
										(function(){ rotation(images); }).delay(dureeAffichage);
									}
								}
							});
							if(images.length > 1){
								images[currentImage].morph({opacity: 0});
							}
						}
						
						
						

				    }
				});
			}
			slideshow(imagesSrc);
		}
		
		
		
	}

});
