// Made by geeeet@ghtml.com
// Keep these two lines and you're free to use this code

// 19.04.2001 - Finally able to remove browser-scrollbar if content is longer than the browser is high:
// Just put this in the style-tag right before the end head-tag:
// body {margin-left:0; margin-right:0; margin-top:0; margin-bottom:0; width:100%;height:100%;overflow:hidden}

// And now... go to the bottom of the page...

// Browser detection
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick

var clickUp = false; // If click on up-arrow
var clickDown = false; // If click on down-arrow
var clickDrag = false; // If click on scrollbar
var clickAbove = false; // If click above scrollbar
var clickBelow = false; // If click below scrollbar

var timer = setTimeout("",500); // Repeat variable
var upL; // Up-arrow X
var upT; // Up-arrow Y
var downL; // Down-arrow X
var downT; // Down-arrow Y
var dragL=0; // Scrollbar X
var dragT=0; // Scrollbar Y
var dragW=0;
var dragH=0;
var rulerL=0; // Ruler X
var rulerT=0; // Ruler Y
var contentT; // Content layer Y;
var contentH; // Content height
var contentClipH; // Content clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span
var timer, dir=0;

// Mousedown
function down(e){
	//if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
	getMouse(e);
	startY = mouseY;

	// If click on up-arrow
	if((mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH)))){
		if (dir==1) { return true; }
		dir=1;
		return scrollUp();
	}	
	// Else if click on down-arrow
	else if((mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH)))){
		if (dir==2) { return true; }
		dir=2;
		return scrollDown();
	}
	// If no scrolling is to take place
	else{
		up();
		return true;
	}
}

function up(){
	clearTimeout(timer);
	dir=0;
	// Resetting variables
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}


function getT(){
	if(ie4)
		contentT = document.all.content.style.pixelTop;
	else if(nn4)
		contentT = document.contentClip.document.content.top;
	else if(dom)
		contentT = parseInt(document.getElementById("content").style.top);
}


function getMouse(e){
	if(ie4){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
	mouseX-=offX;
	mouseY-=offY;
}


function moveTo(){
	if(ie4){
		document.all.content.style.top = contentT;
	}
	else if(nn4){
		document.contentClip.document.content.top = contentT;
	}
	else if(dom){
		document.getElementById("content").style.top = contentT + "px";
	}
}


function scrollUp(){
	getT();
	var mult=1;
	if (mouseY <= (upT + upH/2)) mult=3;
	
	if(contentT < 0){		
		contentT = contentT + speed*mult;
		if(contentT > 0)
			contentT = 0;
			
		moveTo();
		clearTimeout(timer);
		timer = setTimeout("scrollUp()",25);
	}
	return false;
}


function scrollDown(){
	getT();
	var mult=1;
	if (mouseY >= (downT + downH/2)) mult=3;
	
	if(contentT > -(contentH - contentClipH)){			
		contentT = contentT - speed*mult;
		if(contentT < -(contentH - contentClipH))
			contentT = -(contentH - contentClipH);
			
		moveTo();
		clearTimeout(timer);
		timer = setTimeout("scrollDown()",25);
	}
	return false;
}

// reloads page to position the layers again
function reloadPage(){
	location.reload();
}

// Preload
function loadScroller(){
	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.up.style.pixelLeft;
		upT = document.all.up.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.down.style.pixelLeft;
		downT = document.all.down.style.pixelTop;
		// Height of content layer and clip layer
		contentH = parseInt(document.all.content.scrollHeight);
		contentClipH = parseInt(document.all.contentClip.style.height);
		var oup=document.all.up;
		var odown=document.all.down;
	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.up.left;
		upT = document.up.top;		
		// Down-arrow X and Y variables
		downL = document.down.left;
		downT = document.down.top;		
		// Height of content layer and clip layer
		contentH = document.contentClip.document.content.clip.bottom;
		contentClipH = document.contentClip.clip.bottom;
		var oup=document.up;
		var odown=document.down;
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("up").style.left);
		upT = parseInt(document.getElementById("up").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("down").style.left);
		downT = parseInt(document.getElementById("down").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("content").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
		document.getElementById("content").style.top = 0 + "px";
		var oup=document.getElementById("up");
		var odown=document.getElementById("down");
	}
	// Number of pixels scrollbar should move
	if (contentH > contentClipH) { oup.style.display='inline';
									odown.style.display='inline';
									}
	
	// Initializes event capturing
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousemove = down;
}

