var mooBlender = new Class({
	Implements: [Options, Events],
	options: {
		timer: 7000,
		onChange: false,
		onStop: false,
		onPlay: false
	},
	current: 0,
	_items: [],
	_stop: false,
	initialize: function(items, options) {
		this.setOptions(options);
		this._items = items;
		this.initItems();
		if ($type(this.options.onChange) == 'function')
			this.addEvent('change', this.options.onChange);
		if ($type(this.options.onStop) == 'function')
			this.addEvent('stop', this.options.onStop);
		if ($type(this.options.onPlay) == 'function')
			this.addEvent('stop', this.options.onPlay);
	},
	play: function() {
		this._stop = false;
		this.showPlay.delay(this.options.timer, this);
	},
	stop: function() {
		this.fireEvent('stop');
		this._stop = true;
	},
	showFrame: function(index) {
		var root = this;
		this.fireEvent('change', index);
		var fx = new Fx.Tween(this._items[this.current], {
			onComplete: function() {
				root._items[index].fade('in');
			}
		});
		fx.start('opacity', 0);
		this.current = index;
	},
	showNext: function() {
		var next = this.current + 1;
		if (this.current == this._items.length - 1)
			next = 0;
		this.showFrame(next);
	},
	showPrev: function() {
		var prev = this.current - 1;
		if (this.current == 0)
			prev = this._items.length - 1;
		this.showFrame(prev);
	},
	showPlay: function() {
		if (this._stop)
			return;
		this.showNext();
		this.showPlay.delay(this.options.timer, this);
	},
	initItems: function() {
		this.fireEvent('play');
		this._items.each(function(item, index) {
			if (index > 0)
				item.setStyle('opacity', 0);
			item.setStyle('visibility', 'visible'); 
		});
	},
	hideAll: function() {
		this._items.each(function(item, index) { item.fade('hide'); });
	}
});


