var CKRE_Slideshow = new Class(
{
	Implements: Options,
	
	options: {
		delay: 2000,
		duration: 2000,
		images: []
	},
	
	initialize: function(container, options) {
		this.setOptions(options);
		this.container = container;
		this.imageContainer = new Element('div', {
			styles: {
				'position': 'relative'
			}
		}).inject(this.container);
		
		if( this.options.images.length > 0 ) { 
			this.play(0);
		}
	},

	play: function(imageNo) {
		this.imageNo = imageNo;
		
		this.currentImage = new Asset.image(this.options.images[this.imageNo]);
		this.currentImage.setStyles({
			'position': 'absolute',
			'z-index': 1,
			'opacity': 0
		});
		
		var wait = function() { this.next.delay(this.options.delay, this) };
		
		this.currentImage.inject(this.imageContainer);
		this.currentImage.set('tween', {duration: this.options.duration});
		this.currentImage.get('tween', {
			property: 'opacity',
			duration: this.options.duration
		}).start(1).chain(wait.bind(this));
	},
	
	next: function() {
		if( this.options.images.length == 1 ) {
			return;
		}
		if( this.imageNo < this.options.images.length-1 ) {
			this.imageNo++
		} else {
			this.imageNo = 0;
		}
		
		if( this.lastImage ) {
			this.lastImage.dispose();
		}
		this.lastImage = this.currentImage;
		
		this.play(this.imageNo);
	}
});