﻿LM.Scroll = new Class({

	initialize: function(divID, elements, step, elementWidth) {
		//	initialize all the variables
		this.step = step;
		this.elements = elements;
		this.index = 0;
		this.scroller = $(divID)
		this.left = 0;
		this.top = 0;
		this.elementWidth = elementWidth;

		this.transitionOptions = {
			duration: '1000',
			transition: Fx.Transitions.Quad.easeInOut
			//fps: 60
		};
	},
	moveToLR: function(e, i) {
		//var i = 3;
		if (Browser.Engine.trident) {
			if ($chk(e)) e.stop();
		}
		else {
			var evt = new Event(e);
			evt.stop();
		}
		this.left = -this.elementWidth * (i - 1);
		this.scroller.set('tween', this.transitionOptions);
		this.scroller.tween('left', this.left);
		this.index = (i - 1);
	},
	scrollRight: function(e) {
		if (Browser.Engine.trident) {
			if ($chk(e)) e.stop();
		}
		else {
			var evt = new Event(e);
			evt.stop();
		}
		if ((this.index + 1) * this.step < this.elements.length) {
			this.left += -this.elementWidth * this.step;
			this.scroller.set('tween', this.transitionOptions);
			this.scroller.tween('left', this.left);
			this.index++;
		}
	},
	scrollLeft: function(e) {
		if (Browser.Engine.trident) {
			if ($chk(e)) e.stop();
		}
		else {
			var evt = new Event(e);
			evt.stop();
		}
		if (this.index != 0) {
			this.left += this.elementWidth * this.step;
			this.scroller.set('tween', this.transitionOptions);
			this.scroller.tween('left', this.left);
			this.index--;
		}
	},
	scrollUp: function(e) {
		if (Browser.Engine.trident) {
			if ($chk(e)) e.stop();
		}
		else {
			var evt = new Event(e);
			evt.stop();
		}
		if (this.index != 0) {
			this.top += this.elementWidth * this.step;
			this.scroller.set('tween', this.transitionOptions);
			this.scroller.tween('top', this.top);
			this.index--;
		}
	},
	scrollDown: function(e) {
		if (Browser.Engine.trident) {
			if ($chk(e)) e.stop();
		}
		else {
			var evt = new Event(e);
			evt.stop();
		}
		if ((this.index + 1) * this.step < this.elements.length) {
			this.top += -this.elementWidth * this.step;
			this.scroller.set('tween', this.transitionOptions);
			this.scroller.tween('top', this.top);
			this.index++;
		}
	},
	resetX: function() {
		this.scroller.tween('left', 0);
	},
	resetY: function() {
		this.scroller.tween('top', 0);
	}
});
