var MoeCarousel = new Class({

	options: {
		restart_beginning:	true,
		btn_previous:		null,
		btn_next:		null,
		btn_pause:		null,
		container_height:	200,					// Height for the Container Div
		container_width:	500,					// Width for the Container Div
		heightunit:		'px',
		widthunit:		'px',
		debug:			false,
		direction:		1,					// Direction to scroll 1 = normal, -1 = opposite
		duration:		50,					// Duration for Transition
		el_container:		null,					// The container div that houses the UL
		el_ul:			null,					// The UL element that houses the LI's
		li_fixedwidth:		true,					// Should we give the LI's a fixed width (horizontal scroll)
		li_fixedheight:		true,					// Should we give the LI's a fixed height (vertical scroll)
		next_image:		null,
		prev_image:		null,
		play_image:		null,
		pause_image:		null,
		pauseable:		false,					// Is the scroller pausable?
		pausetime:		2000,					// Pause time after transition
		scrollaxis:		'x',	 				// Horizontal = horz, Vertical = vert, ZigZag = zig
		scroll_jump:		2,
		scroll_speed:		2,
		transition:		'Fx.Transitions.Bounce.easeOut',	// Transition effect to use
		wheelstop:		true					// Whether or not the mouse wheel halts the transition
	},

	el_debug:		null,
	el_container:		null,
	el_ul:			null,
	item_length:		0,
	paused:			false,

	initialize: function(options){
		this.setOptions(options);
		this.el_container	= $(this.options.el_container);
		this.el_ul		= $(this.options.el_ul);
		this.moeScroller	= new Fx.Scroll(this.el_container, {
			duration:	this.options.duration,
			wait:		false,
			wheelStops:	this.options.wheelstop,
			transition:	this.options.transition,
			onComplete:	this.moveItem.bind(this)
		});

		if (this.options.pausetime < 10) this.options.pausetime = 1000;
		if (this.options.debug) { this.el_debug = new Element('div', {'styles': {'border': '1px solid pink', 'display': 'block', 'clear': 'both' }}).injectAfter(this.el_container); }

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

		$(this.options.el_container).addEvent('mouseover', this.stopScroller.bind(this));
		$(this.options.el_container).addEvent('mouseout', this.startScroller.bind(this));

		this.moveItem.periodical(this.options.pausetime, this);
	},

	moveItem: function() {
		if (this.paused === true) return;
		if (this.options.direction == 1) {
			this.el_ul.getLast().injectBefore(this.el_ul.getFirst());
		} else if (this.options.direction == -1) {
			this.el_ul.getFirst().injectAfter(this.el_ul.getLast());
		}
	},

	pauseScroller: function() { if (this.paused) this.startScroller(); else this.stopScroller(); },
	startScroller: function() { this.paused = false; },
	stopScroller: function() { this.paused = true; },
	debug_msg: function(msg) { if (this.el_debug != null) this.el_debug.innerHTML = msg+'<br style="clear: both" />'; }

});

MoeCarousel.implement(new Options, Chain);
