function ScrollBar(container, width, height) {
	this.superClass();
	
	this.container = (container != null) ? container : document.body;
	this.width = (width != null) ? width : container.offsetWidth;
	this.height = (height != null) ? height : container.offsetHeight;
	
	this.init();
	this.loadScroll();
}

ScrollBar.IMG_THUMB = "img/scrollThumb.gif";
ScrollBar.THUMB_WIDTH = 12;
ScrollBar.THUMB_HEIGHT = 21;
ScrollBar.BG_WIDTH = 2;
ScrollBar.BG_COLOR = "#444";
ScrollBar.MARGIN_X = 0;
ScrollBar.MARGIN_Y = 12;

ScrollBar.prototype.superClass = DisplayElement;
ScrollBar.prototype.container;
ScrollBar.prototype.placeholder;
ScrollBar.prototype.width;
ScrollBar.prototype.height;

ScrollBar.prototype.init = function() {
	this.placeholder = LZ.drawRectangle(this.width - ScrollBar.THUMB_WIDTH, this.height, null, true)

	this.placeholder.style.position = "relative";
	this.placeholder.style.overflow = "hidden";
	this.placeholder.innerHTML = this.container.innerHTML;
	this.container.innerHTML = "";
	
	this.container.appendChild(this.placeholder);
};

ScrollBar.prototype.loadScroll = function() {
	if (this.placeholder.scrollHeight > this.placeholder.offsetHeight) {
		if (this.container["scroll"] == null) {
			var ref = this;
			var phHeight = this.placeholder.scrollHeight - this.placeholder.offsetHeight;
			var scrollHeight = this.height - ScrollBar.MARGIN_Y*2;
			var scroll = LZ.drawRectangle(ScrollBar.THUMB_WIDTH, null, null, true);
			var bg = LZ.drawRectangle(ScrollBar.BG_WIDTH, scrollHeight, ScrollBar.BG_COLOR, true);
			var thumb = LZ.drawRectangle(ScrollBar.THUMB_WIDTH - ScrollBar.BG_WIDTH, ScrollBar.THUMB_HEIGHT, "url('" + ScrollBar.IMG_THUMB + "')", true);
			var thumbAreaHeight = scrollHeight - ScrollBar.THUMB_HEIGHT;
			
			this.container["scroll"] = scroll;
			scroll.style.marginTop = ScrollBar.MARGIN_Y + "px";
			bg.style.position = "relative";
			bg.style.left = Math.round(ScrollBar.THUMB_WIDTH/2) + "px";
			thumb.style.position = "relative";
			thumb.style.cursor = "pointer";
			thumb.style.backgroundRepeat = "no-repeat";
			thumb.style.backgroundPosition = "center";
			thumb.style.marginTop = "0px";
			
			thumb.onmousedown = function(downEvent) {
				var iniY = LZ.getMouseCoords(downEvent, scroll).y - LZ.measureToNumber(thumb.style.marginTop);
				
				document.onmousemove = function(moveEvent) {
					var y = LZ.getMouseCoords(moveEvent, scroll).y;
					var desloc = y - iniY;
					
					thumb.style.marginTop = ((desloc < thumbAreaHeight) ? ((desloc > 0) ? desloc : 0) : thumbAreaHeight) + "px";
					ref.placeholder.scrollTop = Math.round(phHeight*desloc/thumbAreaHeight);
				};
				
				document.onmouseup = function(upEvent) {
					this.onmousemove = null;
					this.onmouseup = null;
				};
			};
			
			LZ.setSelectionEnabled(false, this.container);
			
			scroll.appendChild(bg);
			scroll.appendChild(thumb);
			this.container.appendChild(scroll);
		}
	}
	else if (this.container["scroll"] != null) {
		this.container.removeChild(this.container["scroll"]);
		this.container["scroll"] = null;
	}
};

ScrollBar.prototype.getContainer = function() {
	return this.placeholder;
};

ScrollBar.prototype.update = function() {
	this.loadScroll();
};