var moz=document.getElementById&&!document.all
var moving = false;
var tempX = 0
var tempY = 0
var dex=""
var BarTop1 = 0
var BarTop2 = 306

if( navigator.userAgent.indexOf("MSIE") != -1 ) {
	var BarTop1 = 0
	var BarTop2 = 296
}

if( navigator.userAgent.indexOf("Gecko") != -1 ) {
	var BarTop1 = 0
	var BarTop2 = 305
}

function init_ScrollBar() {
	scrollTop = document.getElementById("ContentArea").scrollTop
	diff = getDiff()
	scrollTop = scrollTop / diff
	document.getElementById("dragBar").style.top = scrollTop + 'px'
	elm_id = document.getElementById( 'dragBar' )
}

function getDiff() {
	scrollHeight = document.getElementById("ContentArea").scrollHeight
	scrollbarHeight = document.getElementById("scrollbar").style.height
	scrollbarHeight = parseInt( scrollbarHeight )
	diff = scrollHeight / scrollbarHeight
	return diff
}

function check_height( top_offset ){
	if( navigator.userAgent.indexOf("Netscape") != -1 )
		document.getElementById("ContentArea").style.overflow="auto"
	diff = getDiff() 
	top_offset = parseInt( top_offset )
	top_offset = top_offset * (diff - 1.14)
	document.getElementById("ContentArea").scrollTop = top_offset
}

function drag() {
	el = document.getElementById( 'scrollbar' )
	if(dex!="") {
		dex.style.zIndex = ""
	}
	moving=true
	posY = tempY - elm_id.offsetTop
	BarY = posY
	elm_id.style.zIndex = 1
	dex=elm_id
}

function moveTo(e) {
	tempY = (!moz ? event.clientY : e.clientY)
	if( moving == true ) {
		BarTop = tempY - posY
		if( BarTop >= BarTop1 && BarTop <= BarTop2 ) {
			elm_id.style.top = BarTop + "px"
			check_height( elm_id.style.top )
			if( document.selection )
				document.selection.empty()
		}
	}
}

function mouseScroll( delta , step ) {
	tempY = parseInt( document.getElementById("dragBar").style.top )
	d=5
	if( tempY < d )
		d=2
	if (delta < 0)
			BarTop = ( tempY ) + d
	else
			BarTop = ( tempY ) - d
	if( BarTop >= BarTop1 && BarTop <= BarTop2 ) {
		elm_id.style.top = BarTop + "px"
		check_height( elm_id.style.top );
	}
}


function mouseWheel(event) {
	var delta = 0
	if ( !event ) event = window.event
	if ( event.wheelDelta ) {
		delta = event.wheelDelta / 120
		if ( window.opera ) delta = -delta
	} else if ( event.detail ) {
		delta = -event.detail / 3
	}
	if (delta) {
		mouseScroll( delta , 150 )
		if ( event.preventDefault ) event.preventDefault()
		event.returnValue = false
	}
}

if ( window.addEventListener ) {
	window.addEventListener( 'DOMMouseScroll' , mouseWheel , false );
}
window.onmousewheel = document.onmousewheel = mouseWheel;
document.onmousemove = moveTo
document.onmouseup = new Function("moving=false")

