var g2scroller = new Class({
	setOptions: function (a) {
		this.options = Object.extend({
			speed: 1500,
			delay: 5000,
			transition: Fx.Transitions.Bounce.easeOut,
			direction: 'vertical',
			fade: 'no',
			onComplete: Class.empty,
			onStart: Class.empty
		},
		a || {})
	},
	initialize: function (c, d) {
		this.setOptions(d);
		this.el = $(c);
		this.items = this.el.getElements('li');
		this.auto = null;
		var w = 0;
		var h = 0;
		if (this.options.direction.toLowerCase() == 'horizontal') {
			h = this.el.getSize().size.y;
			this.items.each(function (a, b) {
				w += a.getSize().size.x
			})
		} else {
			w = this.el.getSize().size.x;
			this.items.each(function (a, b) {
				h += a.getSize().size.y
			})
		}
		if (this.options.fade == "yes") {
			this.el.setStyles({
				position: 'absolute',
				top: 0,
				left: 0,
				width: w,
				height: h,
				opacity: 1
			});
			this.fx = new Fx.Styles(this.el, {
				duration: this.options.speed,
				transition: this.options.transition,
				onComplete: function () {
					var i = (this.current == 0) ? this.items.length: this.current;
					this.items[i - 1].injectInside(this.el);
					this.el.setStyles({
						left: 0,
						top: 0,
						opacity: 1
					})
				}.bind(this)
			})
		} else {
			this.el.setStyles({
				position: 'absolute',
				top: 0,
				left: 0,
				width: w,
				height: h
			});
			this.fx = new Fx.Styles(this.el, {
				duration: this.options.speed,
				transition: this.options.transition,
				onComplete: function () {
					var i = (this.current == 0) ? this.items.length: this.current;
					this.items[i - 1].injectInside(this.el);
					this.el.setStyles({
						left: 0,
						top: 0
					})
				}.bind(this)
			})
		}
		this.current = 0;
		this.next()
	},
	pause: function () {
		$clear(this.auto);
		this.auto = null
	},
	resume: function () {
		if (this.auto == null) {
			this.next()
		}
	},
	next: function () {
		this.current++;
		if (this.current >= this.items.length) this.current = 0;
		var a = this.items[this.current];
		if (this.options.fade == "yes") {
			this.fx.start({
				top: -a.offsetTop,
				left: -a.offsetLeft,
				opacity: 1
			})
		} else {
			this.fx.start({
				top: -a.offsetTop,
				left: -a.offsetLeft
			})
		}
		this.auto = this.next.bind(this).delay(this.options.delay + this.options.speed)
	}
});
