function Scroll(mainLayerId, contentLayerId) {
	this.id = _scrolls.length;
	_scrolls[_scrolls.length] = this;

	this.mainLayer = document.getElementById(mainLayerId);
	this.mainStyle = new xbStyle(this.mainLayer);
				
	this.contentLayer = document.getElementById(contentLayerId);
	this.contentStyle = new xbStyle(this.contentLayer);
	this.contentTop = this.contentStyle.getTop();
	
	this.top = this.contentTop;
	this.vertStep = 5;
	
	this.timerId = 0;
	
	this.syncContent();
	this.autoSync = true;
}

Scroll.prototype.up = Scroll_Up;
Scroll.prototype.down = Scroll_Down;
Scroll.prototype.stop = Scroll_Stop;
Scroll.prototype.syncContent = Scroll_SyncContent;

function Scroll_SyncContent() {
	this.mainHeight = this.mainStyle.getHeight();
	this.contentHeight = this.contentStyle.getHeight();
}

function Scroll_MoveUp(id) {
	var scroll = _scrolls[id];
	if(scroll.top > -(scroll.contentHeight - scroll.mainHeight)) {
		scroll.top = Math.max(-(scroll.contentHeight - scroll.mainHeight), scroll.top - 10);
		scroll.contentStyle.setTop(scroll.top);
		alert();
	} else {
		scroll.stop();
	}
}

function Scroll_Up() {
	this.stop();

	if (this.autoSync) {
		this.syncContent();
	}
	
	this.timerId = setInterval('Scroll_MoveDown('+this.id+')', 100);
}

function Scroll_MoveDown(id) {
	var scroll = _scrolls[id];
	if(scroll.top < scroll.contentTop) {
		scroll.top = Math.min(scroll.contentTop, scroll.top + 10);
		scroll.contentStyle.setTop(scroll.top);
	} else {
		scroll.stop();
	}
}

function Scroll_Down() {
	this.stop();

	if (this.autoSync) {
		this.syncContent();
	}

	this.timerId = setInterval('Scroll_MoveUp('+this.id+')', 100);
}

function Scroll_Stop() {
	if (this.timerId) {
		clearInterval(this.timerId);
		this.timerId = 0;
	}
}

var _scrolls = new Array();