var RokIntroScroller = new Class({
	Implements: [Options],
	version: '1.0',
	options: {
		'scroll': {
			'duration': 500,
			'itemsPerClick': 2,
			'transition': Fx.Transitions.Quad.easeOut
		},
		'arrows': {
			'effect': false,
			'opacity': 1,
			'align': 'center'
		}
	},
	initialize: function (b, c) {
		this.element = document.id(b);
		if (!this.element) return this;
		this.setOptions(c);
		this.container = new Element('div', {
			'class': 'rokintroscroller-container'
		}).inject(this.element, 'before').setStyle('position', 'relative');
		this.wrapper = new Element('div', {
			'class': 'rokintroscroller-wrapper'
		}).inject(this.container).adopt(this.element);
		if (Browser.Engine.trident4) this.wrapper.setStyle('width', this.element.getCoordinates().width);
		var d = this.element.getCoordinates().width;
		this.elements = this.element.getChildren().filter(function (a) {
			return a.get('tag') == 'div'
		});
		this.elements[0].addClass('first');
		this.elements[this.elements.length - 1].addClass('last');
		this.size = this.getSize(this.elements);
		this.size.x += d;
		this.current = 0;
		this.element.setStyles({
			'width': this.size.x,
			'height': this.size.y
		});
		var e = this.wrapper.getStyle('width').toInt() + this.wrapper.getStyle('padding-left').toInt() + this.wrapper.getStyle('padding-right').toInt() + this.wrapper.getStyle('margin-left').toInt() + this.wrapper.getStyle('margin-right').toInt() + this.wrapper.getStyle('border-left').toInt() + this.wrapper.getStyle('border-right').toInt();
		if (this.size.x > e) {
			this.scroller = new Fx.Scroll(this.wrapper, {
				'duration': this.options.scroll.duration,
				'transition': this.options.scroll.transition,
				'link': 'cancel'
			});
			this.scroller.set(0, 0);
			this.makeArrows()
		}
		return this
	},
	makeArrows: function () {
		this.leftArrow = new Element('div', {
			'class': 'rokintroscroller-leftarrow'
		}).inject(this.container, 'top');
		this.rightArrow = new Element('div', {
			'class': 'rokintroscroller-rightarrow'
		}).inject(this.container);
		if (Browser.Engine.trident4) {
			this.leftArrow.inject(this.container.getParent(), 'top');
			this.rightArrow.inject(this.container.getParent())
		};
		var c = $$(this.leftArrow, this.rightArrow);
		c.setStyles({
			'position': 'absolute',
			'top': 0,
			'cursor': 'pointer'
		});
		if (this.options.arrows.align == 'center') {
			var d = this.wrapper.getCoordinates().height;
			var e = this.leftArrow.getCoordinates().height;
			var f = this.rightArrow.getCoordinates().height;
			var g = {
				'left': (d - e) / 2,
				'right': (d - f) / 2
			};
			this.leftArrow.setStyle('top', g.left);
			this.rightArrow.setStyle('top', g.right)
		} else if (this.options.arrows.align == 'bottom') {
			c.setStyles({
				'top': '',
				'bottom': 0
			})
		};
		this.leftArrow.setStyle('left', 0);
		this.rightArrow.setStyle('right', 0);
		if (this.options.arrows.effect) {
			var h = this.options.arrows.opacity,
			scroller = this.scroller;
			c.each(function (a) {
				var b = new Fx.Tween(a, {
					duration: 200,
					link: 'cancel'
				}).set('opacity', 1);
				a.addEvents({
					'mouseenter': function () {
						b.start('opacity', 1)
					},
					'mouseleave': function () {
						b.start('opacity', 1)
					},
					'click': function () {
						if (a.hasClass('rokintroscroller-rightarrow')) {
							this.current = this.setCurrent('right');
							scroller.toElement(this.elements[this.current])
						} else {
							this.current = this.setCurrent('left');
							scroller.toElement(this.elements[this.current])
						}
					}.bind(this)
				})
			},
			this)
		}
	},
	setCurrent: function (a) {
		var b = this.current,
		amount = this.options.scroll.itemsPerClick;
		if (a == 'left') {
			if (b - amount >= 0) this.current -= amount;
			else this.current = 0
		} else {
			if (b + amount < this.elements.length) this.current += amount
		}
		return this.current
	},
	getSize: function (f) {
		var g = {
			'x': 0,
			'y': 0
		};
		f.each(function (a) {
			var b = a.getSize();
			var c = {
				'x': a.getStyle('padding-left').toInt() + a.getStyle('padding-right').toInt(),
				'y': a.getStyle('padding-top').toInt() + a.getStyle('padding-bottom').toInt()
			};
			var d = {
				'x': a.getStyle('margin-left').toInt() + a.getStyle('margin-right').toInt(),
				'y': a.getStyle('margin-top').toInt() + a.getStyle('margin-bottom').toInt()
			};
			var e = {
				'x': a.getStyle('border-left-width').toInt() + a.getStyle('border-right-width').toInt(),
				'y': a.getStyle('border-top-width').toInt() + a.getStyle('border-bottom-width').toInt()
			};
			g.x += b.x + d.x + c.x + e.x;
			if (b.y > g.y) g.y = b.y + c.y + d.y + e.y
		});
		return g
	}
});
