function initScroller() {
	document.getElementById('scroller').style.visibility = "visible";
	contentdiv = document.getElementById('contentdiv');
	content = document.getElementById('content');
	dummy = document.getElementById('dummy');
	scroller = document.getElementById('scrollera');

	contentdiv.style.overflow = "hidden";
	scroller.style.position="relative";	
	maxheight = document.getElementById('scrollertd').offsetHeight;
	scroller.onmousedown = mousedown;
	maxtop = ((document.body.offsetHeight - 600) / 2) + 132;
	scroller.style.height = "18px";
	scroller.style.top = "0";
	
	if(dummy.offsetHeight > contentdiv.offsetHeight) {
		allowscroll=1;
		if(IE) {
			contentdiv.onscroll = autoControl;
		}
		else {
			autotimer = window.setInterval("autoControl()",500);
		}
	}
	else {
		allowscroll=0;
		scroller.style.top = (maxheight / 2) - 25;
		contentdiv.scrollTop = 0;
	}
	
	if((parseInt(scroller.style.top) * 1) + (parseInt(scroller.style.height) * 1) > maxheight) {
		scroller.style.top = maxheight - parseInt(scroller.style.height);
	}
	
	if (!IE) {
		document.captureEvents(Event.MOUSEMOVE)
		window.addEventListener('DOMMouseScroll', getmousewheel, false);
	}

	document.onmousemove = getMouseXY;
	document.onmouseup = mouseup;
	document.onmousewheel = getmousewheel;
}

function scrolldown(i) {
	if(dummy.offsetHeight > contentdiv.offsetHeight) {
		contentdiv.scrollTop += i;
		scroller.style.position="relative";
		scroller.style.top = (((contentdiv.scrollTop * 100) / (dummy.offsetHeight - contentdiv.offsetHeight)) * (maxheight - parseInt(scroller.style.height))) / 100;
		if(parseInt(scroller.style.top) > maxheight - parseInt(scroller.style.height)) {
			scroller.style.top = maxheight - parseInt(scroller.style.height);
		}
	}
}

function scrollup(i) {
	if(dummy.offsetHeight > contentdiv.offsetHeight) {
		contentdiv.scrollTop -= i;
		scroller.style.position="relative";
		scroller.style.top = (((parseInt(contentdiv.scrollTop) * 100) / (parseInt(dummy.offsetHeight) - parseInt(contentdiv.offsetHeight))) * (maxheight - parseInt(scroller.style.height))) / 100;
	}
}

function startScrollDown() {
	aktiv = window.setInterval("scrolldown(10)",50);
}

function stopScrollDown() {
	window.clearInterval(aktiv);
}

function startScrollUp() {
	aktiv = window.setInterval("scrollup(10)",50);
}

function stopScrollUp() {
	window.clearInterval(aktiv);
}

function mousedown(e) {
	if(allowscroll == 1) {
		setscroller=1;
	}
	if(IE) {
		startpos = event.offsetY;
	}
	else {
		temp = parseInt(scroller.style.top);
		startpos = e.pageY - maxtop - temp;
	}
	return false;
}

function mouseup() {
	setscroller=0;
	return false;
}

function getMouseXY(e) {
	if(setscroller == 1) {
		if (IE) {
			tempY = event.clientY;
		}
		else {
			tempY = e.pageY;
		}  
		if (tempY < 0){tempY = 0;}
		if( ((tempY - maxtop) - startpos) >= 0 && ((tempY - maxtop) - startpos) < (maxheight - parseInt(scroller.style.height))) {
			scroller.style.top = (tempY - maxtop) - startpos;
			contentdiv.scrollTop = ((((parseInt(scroller.style.top)) * 100) / (maxheight - parseInt(scroller.style.height))) * (dummy.offsetHeight - contentdiv.offsetHeight)) / 100;
		}
		else if(((tempY - maxtop) - startpos) < 0) {
			scroller.style.top = 0;
			contentdiv.scrollTop = 0;
		}
		else {
			scroller.style.top = maxheight - parseInt(scroller.style.height);
			contentdiv.scrollTop = dummy.offsetHeight - contentdiv.offsetHeight;			
		}
	}
	return false;
}

function getmousewheel(e) {
	if(IE) {
		if(event.wheelDelta >= 120) {
			scrollup(30);
		}
		if(event.wheelDelta <= -120) {
			scrolldown(30);
		}
	}
	else {
		if(e.detail <= -3) {
			scrollup(30);
		}
		if(e.detail >= 3) {
			scrolldown(30);
		}
	}
}

function autoControl() {
	if(allowscroll == 1) {
		scroller.style.position="relative";
		scroller.style.top = (((contentdiv.scrollTop * 100) / (dummy.offsetHeight - contentdiv.offsetHeight)) * (maxheight - scroller.style.height.replace(/px/,""))) / 100;
	}
}

var IE = document.all?true:false;
var aktiv;
var contentdiv;
var content;
var dummy;
var setscroller=0;
var tempY = 0;
var maxtop = "115";
var maxheight;
var scrollerheight;
var scroller;
var startpos;
var contentOffsetHeight;
var allowscroll;
var autotimer;
var scroller;
