function niceScrollbar2( layerObj, backLayerObj, hookObj, min, max, height ) {
	this.layer = layerObj;
	this.backLayer = backLayerObj;
	this.hooker = hookObj;
	this.refObj = this.layer.ID + "Scroll";
	eval( this.refObj + " = this;" );
	this.min = min;
	this.max = max;
	this.pos = min;
	this.height = height;
	this.realHeight = height - 22;
	this.barLength = 0.2;
	this.step = 1;
	this.trigger = new String();
	this.startTop = 0;
	this.startPos = 0;
	this.draging = false;

	this.paint = niceScroll2Paint;
	this.move = niceScroll2Move;
	this.moveBy = niceScroll2MoveBy;
	this.start = niceScroll2Start;
	this.stop = niceScroll2Stop;
	this.jump = niceScroll2Jump;
	this.drag = niceScroll2Drag;
	this.startDrag = niceScroll2StartDrag;
	this.stopDrag = niceScroll2StopDrag;
	
	if( this.hooker.onMouseUp ) {
		this.hooker.onMouseUp += " " + this.refObj + ".stopDrag();";
		this.hooker.onMouseMove += " " + this.refObj + ".drag();";
	} else {
		this.hooker.hookEvent( EVENT_MOUSE_UP, this.refObj + ".stopDrag();" )
		this.hooker.hookEvent( EVENT_MOUSE_MOVE, this.refObj + ".drag();" )
	}

	this.moveBy( 0 );
}

function niceScroll2Paint() {
	this.realHeight = this.height - 22;
	if( this.max > 0 ) {
		alert("hej");
		theCode = "<table bgcolor=\"#eeeeee\" cellpadding=0 cellspacing=0 border=0 height=" + this.height + ">" +
			"<tr><td height=11>" +
			"<a href=\"#\" onmousedown=\"" + this.refObj + ".start( -" + this.step + " ); return false;\" " +
			"ondragstart=\"return false;\" ondrag=\"return false;\" onfocus=\"this.blur();\">" +
			"<img src=\"../images/scroll_up_grey.gif\" border=0>" +
			"</a></td></tr>" +
			"<tr><td height=11>" + 
			"<img src=\"../images/scroll_bar_space.gif\" onmousedown=\"" + this.refObj + ".jump();\" width=11 height=" + this.realHeight + " border=0>" +
			"</td></tr>" +
			"<tr><td height=11>" +
			"<a href=\"#\" onmousedown=\"" + this.refObj + ".start( " + this.step + " ); return false;\" " +
			"ondragstart=\"return false;\" ondrag=\"return false;\" onfocus=\"this.blur();\">" +
			"<img src=\"../images/scroll_down_grey.gif\" border=0>" +
			"</a></td></tr></table>&nbsp;";
		this.backLayer.write( theCode );
		this.backLayer.clip( 0, 0, 11, this.height );
		this.backLayer.show();
		
		barCode = "<table cellpadding=0 cellspacing=0 border=0><tr><td>" +
			"<a href=\"#\" onmousedown=\"" + this.refObj + ".startDrag(); return false;\" " +
			"onmouseup=\"" + this.refObj + ".stopDrag();\" ondragstart=\"return false;\" ondrag=\"return false;\" onfocus=\"this.blur();\">" +
			"<img src=\"../images/scroll_bar_end.gif\" border=0><br/>" +
			"<img src=\"../images/scroll_bar_tile_grey.gif\" width=11 height=" + ( Math.round( this.realHeight * this.barLength ) - 2 ) + " border=0><br/>" +
			"<img src=\"../images/scroll_bar_end.gif\" border=0>" +
			"</a></td></tr></table>&nbsp;";
		this.layer.write( barCode );
		this.layer.clip( 0, 0, 11, Math.round( this.realHeight * this.barLength ) );
		this.layer.show();
	} else {
		this.backLayer.hide();
		this.layer.hide();
	}
}

function niceScroll2Move( position ) {
	this.pos = position;
	if( this.pos < this.min ) this.pos = this.min;
	if( this.pos > this.max ) this.pos = this.max;
	if( this.max > 0 ) {
		newTop = this.backLayer.top + 11;
		newTop += Math.round( this.pos / this.max * ( this.realHeight - ( this.realHeight * this.barLength ) ) );
		this.layer.show();
		this.layer.move( this.layer.left, newTop );
	} else this.layer.hide();
	if( this.trigger.length ) eval( this.trigger );
}

function niceScroll2MoveBy( offset ) {
	this.pos += offset;
	if( this.pos < this.min ) this.pos = this.min;
	if( this.pos > this.max ) this.pos = this.max;
	if( this.max > 0 ) {
		newTop = this.backLayer.top + 11;
		newTop += Math.round( this.pos / this.max * ( this.realHeight - ( this.realHeight * this.barLength ) ) );
		this.layer.show();
		this.layer.move( this.layer.left, newTop );
	} else this.layer.hide();
	if( this.trigger.length ) eval( this.trigger );
}

function niceScroll2Start( offset ) {
	eval( this.refObj + ".timer = setInterval( this.refObj + \".moveBy( " + offset + " );\", 35 );" );
}

function niceScroll2Stop( offset ) {
	eval( "clearInterval( " + this.refObj + ".timer );" );
}

function niceScroll2Jump() {
	if( this.hooker.mouseY < this.layer.top )
		this.moveBy( Math.round( - ( this.max * this.barLength ) ) );
	else
		this.moveBy( Math.round( this.max * this.barLength ) );
}

function niceScroll2Drag() {
	if( this.draging && ( Math.abs( this.hooker.mouseX - this.backLayer.left ) < 50 ) ) {
		diff = this.startTop - this.hooker.mouseY;
		newPos = this.startPos;
		posDiff = diff / ( this.realHeight - ( this.realHeight * this.barLength ) ) * this.max;
		newPos -= Math.round( posDiff );
		this.move( newPos );
	} else this.draging = false;
}

function niceScroll2StartDrag() {
	this.startTop = this.hooker.mouseY;
	this.startPos = this.pos;
	this.draging = true;
}

function niceScroll2StopDrag() {
	this.stop();
	this.draging = false;
}