var ContentScroller = new Class({
	options: {
		slides: [],
		slideDuration: 7000,
		fadeDuration: 1000
	},
	initialize: function(options){
		this.setOptions(options);
		this.current = 0;
		this.slides = [];
		this.addSlides(this.options.slides);
	},
	addSlides: function(slides){
		$$(slides).each(function(el) {
			this.addSlide(el);
		}, this);
	},
	addSlide: function(slide){
		var s = new Fx.Tween(slide, { property: 'opacity', duration: this.options.fadeDuration });
		if (this.slides.length > 0) s.start(0);
		this.slides.push(s);
	},
	nextSlide: function(){
		this.current %= this.slides.length;
		var lastElement = this.current > 0 ? this.current - 1 : this.slides.length - 1;

		this.slides[lastElement].start(0);
		this.slides[this.current].start(1);
		
		this.current++;
	},
	start: function(){
		if (this.slides.length > 1) {
			this.nextSlide();
			this.nextSlide.periodical(this.options.slideDuration, this);
		}
	}
});

ContentScroller.implement(new Options, new Events);
