function ScrollBar(textarea) {
	this.textarea = textarea;
	this.timer = null;
	this._initArrows = _initArrows;
	this._initArrow = _initArrow;
	this._initArrows();
	this._scroll = _scroll;
	this.scrollUp = scrollUp;	
	this.scrollDown = scrollDown;
	this.stopScrolling = stopScrolling;
}

function _initArrow(direction) {
	var arrowElem = document.getElementById("arrow" + direction + this.textarea.getId());
	var id = this.textarea.getId();
	var scrFunc = new Function("scr" + direction + "(\"" + id + "\");");
	var stopScrFunc = new Function("stopScr(\"" + id + "\");");
	arrowElem.onmousedown = scrFunc;						
	arrowElem.onmouseup = stopScrFunc;
	arrowElem.onmouseout = stopScrFunc;
	arrowElem.style.visibility = "visible";
}

function _initArrows() {
	if(this.textarea.isScrollable()) {
		this._initArrow("Up");
		this._initArrow("Down");
	}	
}

function _scroll(direction, amount) {	
	this.textarea.changePosition(amount);
		
	this.textarea.clipTop -= amount;
	this.textarea.clipBottom -= amount;	
	this.textarea.divElem.style.clip = "rect(" + this.textarea.clipTop + "px, 320px, " + this.textarea.clipBottom + ", 0px)";		
		
	this.timer = window.setTimeout("scr" + direction + "(\"" + this.textarea.getId() + "\");", 60);
}


// In scroll.js
function scrollDown() {		
	var amount = -speed;
	var topDiff = this.textarea.currentPosition - this.textarea.minPosition;
	if(topDiff < speed){
		amount = -topDiff;
	}		
	this._scroll("Down", amount);	
}

function scrollUp() {	
	var amount = speed;
	var topDiff = this.textarea.maxPosition - this.textarea.currentPosition;
	if(topDiff < speed) {
		amount = topDiff;
	}	
	this._scroll("Up", amount);	
}


function stopScrolling() {
	if(this.timer){
		window.clearTimeout(this.timer);
		this.timer = null;
	}	
}
