var DESImageRotator = Class.create({


	DEFAULT_OPTIONS: {
		effectDuration: 1,
		interval: 8,
		firstInterval: 2
	},

	initialize: function(containerElement, imageSrcs, opts) {

		this.options = Object.extend(this.DEFAULT_OPTIONS, opts || {});

		containerElement = $(containerElement);

		var imgDims = containerElement.getDimensions();

		containerElement.setStyle({
			position: 'relative'
		});


		this.images = new Array();

		for (var i = 0; i < imageSrcs.length; i++)
			this.images.push( containerElement.appendChild( new Element('img', {
				src: imageSrcs[i]
			}) ).setStyle({
				position: 'absolute',
				left: '0px',
				top: '0px',
				width: imgDims.width + 'px',
				height: imgDims.height + 'px',
				margin: '0'
			}).hide() );


		this.currentImage = Math.floor( Math.random()*this.images.length );

		this.images[this.currentImage].show();

		setTimeout( this.rotate.bind(this), this.options.firstInterval * 1000);

	},

	rotate: function() {

		this.images[this.currentImage].fade({
			duration: this.options.effectDuration
		});

		this.currentImage++;
		if (this.currentImage == this.images.length) 
			this.currentImage = 0;

		this.images[this.currentImage].appear({
			duration: this.options.effectDuration
		});

		setTimeout( this.rotate.bind(this), this.options.interval * 1000);

	}

}); 
