/**
 * @author Chwan Ren
 */

var rotatingImage = new Class({		
	getOptions: function() {	
		return {
			fadeInterval: 2000,
			transitionTime: 500
		};
	},

	initialize: function(elements, options) {		
		this.setOptions(this.getOptions(), options);
		
		this.elements = $$(elements);
		this.current = 0;

		this.elements.each(function(el, i){
			el.setStyle('opacity', 0);
		});
		
		this.elements[0].setStyle('opacity', 1);
		
		this.animate.periodical(this.options.fadeInterval, this);
	},
	
	animate: function() {	
		next = (this.current + 1) % this.elements.length;
				
		this.elements[this.current].effect('opacity', {duration: this.options.transitionTime}).start(0);		
		this.elements[next].effect('opacity', {duration: this.options.transitionTime}).start(1);
				
		this.current = next;
	}
});

rotatingImage.implement(new Options);