
// Made by geeeet@ghtml.com
// Keep these two lines and you're free to use this code

// Known bugs :
// If ie4.5 mac, please press apple-t to remove sidebar, otherwise everything is pushed 20px to the right...

// Corrected bugs :
// 25.01.2001 - When the height of the span "content" was less than the height of the span "contentClip" a javascript error occured, function changed : move()
// 21.02.2001 - Scrolling text wasn't selectable in ie, function changed : move()
// 05.03.2001 - Ie x and y coordinates was wrong when page was scrolled, function changed : getMouse()

// 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}

// Touch me here :-)
var leftH = 16; // Height of left-arrow
var leftW = 16; // Width of left-arrow
var rightH = 16; // Height of right-arrow
var rightW = 16; // Width of right-arrow
var dragH = 13; // Height of scrollbar
var dragW = 80; // Width of scrollbar
var scrollW = 954; // Width of complete slider
var speed = 14; // Scroll speed

// 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 clickLeft = false; // If click on left-arrow
var clickRight = false; // If click on right-arrow
var clickDrag = false; // If click on scrollbar
var clickLeftBar = false; // If click above scrollbar
var clickRightBar = false; // If click below scrollbar

var timer = setTimeout("",500); // Repeat variable
var leftL; // left-arrow X
var leftT; // left-arrow Y
var rightL; // right-arrow X
var rightT; // right-arrow Y
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y
var contentL; // Content layer X;
var contentW; // Content Width
var contentClipW; // Content clip width
var scrollLength; // Number of pixels scrollbar should move
var startX; // Keeps track of offset between mouse and span

// Mousedown
function down(e){
	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
	getMouse(e);
	startX = (mouseX - dragL);
	
	// If click on left-arrow
	if(mouseX >= leftL && (mouseX <= (leftL + leftW)) && mouseY >= leftT && (mouseY <= (leftT + leftH))){
		clickLeft = true;
		return scrollLeft();
	}	
	// Else if click on right-arrow
	else if(mouseX >= rightL && (mouseX <= (rightL + rightW)) && mouseY >= rightT && (mouseY <= (rightT + rightH))){
		clickRight = true;
		return scrollRight();
	}
	// Else if click on scrollbar
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
		clickDrag = true;
		return false;
	}
	else if(mouseY >= dragT && (mouseY <= (dragT + dragH)) && mouseX >= rulerL && (mouseX <= (rulerL + scrollW))){
		// If click left from drag
		if(mouseX < dragL){
			clickLeftBar = true;
			clickLeft = true;
			return scrollLeft();
		}
		// else click right from drag
		else{
			clickRightBar = true;
			clickRight = true;
			return scrollRight();
		}
	}
	// If no scrolling is to take place
	else{
		return true;
	}
}

// Drag function
function move(e){
	if(clickDrag && contentW > contentClipW){
		getMouse(e);
		dragL = (mouseX - startX);
		
		if(dragL < (rulerL))
			dragL = rulerL;		
		if(dragL > (rulerL + scrollW - dragW))
			dragL = (rulerL + scrollW - dragW);
		
		contentL = ((dragL - rulerL)*(1/scrollLength));
		contentL = eval('-' + contentL);

		moveTo();
		
		// So ie-pc doesn't select gifs
		if(ie4)
			return false;
	}
}

// release mousebutton
function up(){
	clearTimeout(timer);
	// Resetting variables
	clickLeft = false;
	clickRight = false;
	clickDrag = false;
	clickLeftBar = false;
	clickRightBar = false;
	return true;
}

// Reads left content layer distance
function getL(){
	if(ie4)
		contentL = document.all.content.style.pixelLeft;
	else if(nn4)
		contentL = document.contentClip.document.content.left;
	else if(dom)
		contentL = parseInt(document.getElementById("content").style.left);
}

// Reads mouse X and Y coordinates
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;
	}
}

// Moves the layer
function moveTo(){
	if(ie4){
		document.all.content.style.left = contentL;
		document.all.ruler.style.left = dragL;
		document.all.drag.style.left = dragL;
	}
	else if(nn4){
		document.contentClip.document.content.left = contentL;
		document.ruler.left = dragL;
		document.drag.left = dragL;
	}
	else if(dom){
		document.getElementById("content").style.left = contentL + "px";
		document.getElementById("drag").style.left = dragL + "px";
		document.getElementById("ruler").style.left = dragL + "px";
	}
}

// Scrolls left
function scrollLeft(){
	getL();
	
	if(clickLeftBar){
		if(dragL <= (mouseX-(dragW/2)))
			return up();
	}
	
	if(clickLeft){
		if(contentL < 0){		
			dragL = dragL - (speed*scrollLength);
			
			if(dragL < (rulerL))
				dragL = rulerL;
				
			contentL = contentL + speed;
			if(contentL > 0)
				contentL = 0;
			
			moveTo();
			timer = setTimeout("scrollLeft()",25);
		}
	}
	return false;
}

// Scrolls right
function scrollRight(){
	getL();
	
	if(clickRightBar){
		if(dragL >= (mouseX-(dragW/2)))
			return up();
	}

	if(clickRight){
		if(contentL > -(contentW - contentClipW)){			
			dragL = dragL + (speed*scrollLength);
			if(dragL > (rulerL + scrollW - dragW))
				dragL = (rulerL + scrollW - dragW);
			
			contentL = contentL - speed;
			if(contentL < -(contentW - contentClipW))
				contentL = -(contentW - contentClipW);
			
			moveTo();
			timer = setTimeout("scrollRight()",25);
		}
	}
	return false;
}

// reloads page to position the layers again
function reloadPage(){
	location.reload();
}

// Preload
function eventLoader(){
	if(ie4){
		// left-arrow X and Y variables
		leftL = document.all.left.style.pixelLeft;
		leftT = document.all.left.style.pixelTop;		
		// right-arrow X and Y variables
		rightL = document.all.right.style.pixelLeft;
		rightT = document.all.right.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.drag.style.pixelLeft;
		dragT = document.all.drag.style.pixelTop;		
		// Ruler Y variable
		rulerL = document.all.ruler.style.pixelLeft;		
		// Width of content layer and clip layer
		contentW = parseInt(document.all.content.scrollWidth);
		contentClipW = parseInt(document.all.contentClip.style.width);
	}
	else if(nn4){
		// left-arrow X and Y variables
		leftL = document.left.left;
		leftT = document.left.top;		
		// right-arrow X and Y variables
		rightL = document.right.left;
		rightT = document.right.top;		
		// Scrollbar X and Y variables
		dragL = document.drag.left;
		dragT = document.drag.top;		
		// Ruler Y variable
		rulerL = document.ruler.left;
		// Width of content layer and clip layer
		contentW = document.contentClip.document.content.clip.right;
		contentClipW = document.contentClip.clip.right;
	}
	else if(dom){
		// left-arrow X and Y variables
		leftL = parseInt(document.getElementById("left").style.left);
		leftT = parseInt(document.getElementById("left").style.top);
		// right-arrow X and Y variables
		rightL = parseInt(document.getElementById("right").style.left);
		rightT = parseInt(document.getElementById("right").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("drag").style.left);
		dragT = parseInt(document.getElementById("drag").style.top);
		// Ruler Y variable
		rulerL = parseInt(document.getElementById("ruler").style.left);
		// Width of content layer and clip layer
		contentW = parseInt(document.getElementById("content").offsetWidth);
		contentClipW = parseInt(document.getElementById("contentClip").offsetWidth);
		document.getElementById("content").style.left = 0 + "px";
		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollW-dragW)/(contentW-contentClipW));
	// Initializes event capturing
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;
}

