var speed = 6;
var timer = null;

var scrollbars = new Array();

/*function initArrow(textarea, direction) {
	var arrowElem = document.getElementById("arrow" + direction + textarea.getId());
	var id = textarea.getId();
	var func = new Function("scroll" + direction + "(\"" + id + "\");");
	arrowElem.onmousedown = func;						
	arrowElem.onmouseup = stopScrolling;
	arrowElem.onmouseout = stopScrolling
	arrowElem.style.visibility = "visible";
	return arrowElem;
}

function initArrows(textarea) {
	if(textarea.isScrollable()) {
		initArrow(textarea, "Up");
		initArrow(textarea, "Down");
	}	
}

function scroll(textarea, direction, amount) {	
	textarea.top += amount;
	textarea.divElem.style.top = textarea.top;	
	textarea.clipTop -= amount;
	textarea.clipBottom -= amount;	
	textarea.divElem.style.clip = "rect(" + textarea.clipTop + "px, 320px, " + textarea.clipBottom + ", 0px)";
	
	timer = window.setTimeout("scroll" + direction + "(\"" + textarea.getId() + "\");", 60);
}

function scrollDown(textareaId) {	
	var textarea = textareas[textareaId];
	var amount = -speed;
	var topDiff = textarea.top - textarea.minTop;
	if(topDiff < speed){
		amount = -topDiff;
	}		
	scroll(textarea, "Down", amount);	
}

function scrollUp(textareaId) {	
	var textarea = textareas[textareaId];
	var amount = speed;
	var topDiff = textarea.maxTop - textarea.top;
	if(topDiff < speed) {
		amount = topDiff;
	}	
	scroll(textarea, "Up", amount);	
}


function stopScrolling() {
	if(timer){
		window.clearTimeout(timer);
		timer = null;
	}	
}*/

function scrUp(id) {
	scrollbars[id].scrollUp();
}

function scrDown(id) {
	scrollbars[id].scrollDown();	
}

function stopScr(id) {
	var scrollbar = scrollbars[id];	
	if(scrollbar != null) {			
		scrollbar.stopScrolling();
	}
}

divs = document.getElementsByTagName("div");
for(i = 0; i < divs.length; i++) {
	if(divs[i].className.indexOf("textarea") > -1){
		var viewer = new Viewer(divs[i]);
		scrollbars[viewer.getId()] = new ScrollBar(viewer);		
	}
}

