var MoeFade = new Class({

	options: {
		container_height:	200,					// Height for the Container Div
		container_width:	500,					// Width for the Container Div
		heightunit:		'px',
		widthunit:		'px',
		duration:		2000,					// Duration for Transition
		el_container:		null,					// The container div that houses the UL
		classsfx:		'',
		pausetime:		2000					// Pause time after transition
	},

	curslide:		0,
	prevslide:		0,
	el_items:		null,

	initialize: function(options){
		this.setOptions(options);
		var el_container	= $(this.options.el_container);
		this.el_items		= $$('#'+this.options.el_container+' div.mditem'+this.options.classsfx);

		el_container.setStyle('height', this.options.container_height+this.options.heightunit);
		el_container.setStyle('width', this.options.container_width+this.options.widthunit);

		var container_width     = el_container.getSize().size.x;
		var container_height    = el_container.getSize().size.y;

		this.el_items.each( function(item,i) {
			item.setStyles({
				position: 'absolute',
				left: 0,
				top: 0,
				width: parseFloat(container_width)+'px',
				height: parseFloat(container_height)+'px',
				opacity: 0
			});
		}.bind(this));

		this.curslide = 0;
		this.prevslide = 0
		this.el_items[this.curslide].effect('opacity', {duration: this.options.duration}).start(1);
		this.prevslide = this.curslide;
		this.curslide += 1;
		this.repeater.delay(this.options.pausetime+this.options.duration, this);
	},

	repeater: function() {

		if(this.el_items[this.prevslide].fx){this.el_items[this.prevslide].fx.stop();}
		if(this.el_items[this.curslide].fx){this.el_items[this.curslide].fx.stop();}
		this.el_items[this.prevslide].fx = this.el_items[this.prevslide].effect('opacity', {duration: this.options.duration}).start(0);
		this.el_items[this.curslide].fx = this.el_items[this.curslide].effect('opacity', {duration: this.options.duration}).start(1);

		this.prevslide = this.curslide;
		this.curslide += 1;
		if (this.curslide >= this.el_items.length) this.curslide = 0;
		this.repeater.delay((this.options.pausetime+(this.options.duration*2)), this);

	}
});

MoeFade.implement(new Options, Chain);

