var Scroller = function(id, cfg) {
	this.init(id, cfg);
};

Scroller.prototype = {
	
	offsets: {
		x: 0,
		y: 310
	},
	
	init: function(id, cfg) {
		this.id = id;
		this.el = $(id);
		this.cfg = cfg || {};
		
		this.el.set('move', {duration: 0, transition: 'none'});
	},
	
	start: function() {
		if (!this.scrolling) {
			this.scrolling = this.scroll.periodical(150, this, ['u', 2]);
		}
	},
	
	stop: function() {
		if (this.scrolling) {
			clearInterval(this.scrolling);
			delete this.scrolling;
		}
	},
	
	scroll: function(dir, disp) {
		switch (dir) {
			case 'd':
				this.offsets.y += disp;
				break;
			case 'l':
				this.offsets.x -= disp;
				break;
			case 'r':
				this.offsets.x += disp;
				break;
			case 'u':
			default:
				this.offsets.y -= disp;
		}
//		console.debug(this.offsets)
//		this.offsets = {
//			x: 0,
//			y: 300
//		};
		this.el.move({
			relativeTo: this.el.getParent(),
			offset: this.offsets
		});
		
		var pos = this.el.getPosition(this.el.getParent());
		var size = this.el.getSize();
		
		switch (dir) {
			case 'u':
			default:
				if (-pos.y > size.y) {
					this.offsets.y = this.el.getParent().getSize().y + 300;
				}
		}
	}
	
};
