// MODIFIED AND UPDATED BY MERLE EHM (C) 2006

// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
//
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 01/17/03 ---------------------------------------------------------
// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Cross-Browser Functions
var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;

function addEvent(event,method){
	this[event] = method;
	if(ns4) this.captureEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function removeEvent(event){
	this[event] = null;
	if(ns4) this.releaseEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function getElement(name,nest){
	nest = nest ? "document."+nest+"." : "";
	var el = dom ? document.getElementById(name) : iex ? document.all[name] : ns4 ? eval(nest+"document."+name) : false;
	el.css = ns4 ? el : el.style;
	el.hideVis = function(){el.css.visibility="hidden"};
	el.showVis = function(){el.css.visibility="visible"};
	el.getTop = function(){return parseInt(el.css.top) || 0};
	el.setTop = function(y){el.css.top = ns4 ? y: y+"%"};
	el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
	el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
	el.addEvent = addEvent;
	el.removeEvent = removeEvent;
	return el;
}
function getMouse(e){
	return iex ? event.clientY : e.pageY;
}

document.addEvent = addEvent;
document.removeEvent = removeEvent;

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Scroll Functions

var currentContent = null;
var docLoaded = false;
var browserHeight = null;

function initScroller(){ 
	if(window.innerHeight) {
		browserHeight = window.innerHeight;
	} else if(document.documentElement && document.documentElement.clientHeight) {
		browserHeight = document.documentElement.clientHeight;
	} else if(document.body && document.body.offsetHeight) {
		browserHeight = document.body.offsetHeight;
	} else {
		browserHeight = 0;
	} 
	dragHeight = 80; // Height of scrollbar drag
	trackHeight = 243; // Height of scrollbar track
	trackObj = getElement("track"); // Reference to the scrollbar track div
	dragObj = getElement("drag"); // Reference to the scrollbar drag div
	contentMaskObj = getElement("contentMask"); // Reference to the content mask div
	trackTop = 3; //dragObj.getTop(); // Scrollbar top contraint
	trackLength = trackHeight-dragHeight; // Adjusted track height
	trackBottom = trackTop+((trackLength*100)/browserHeight); // Scrollbar bottom contraint
	contentMaskHeight = contentMaskObj.getClipHeight();// Height of the div that masks the content div
	dragObj.addEvent("onmousedown", startDrag);
	if(iex) dragObj.addEvent("ondragstart", function(){return false});
	docLoaded = true;
	loadContent(currentContent);
}
function loadContent(name){
	if(!docLoaded) return;
	currentContent = name;
	contentObj = getElement(currentContent,"contentMask");
	contentHeight = contentObj.getHeight(); // Height of the content div
	contentLength = contentHeight-contentMaskHeight; // Adjusted content height
	scrollLength = trackLength/contentLength; // Height difference between the scrollbar track and the content
	contentObj.showVis();
	dragObj.setTop(trackTop);
	if(contentHeight<=contentMaskHeight){
		trackObj.hideVis();
		dragObj.hideVis();
	}else{
		trackObj.showVis();
		dragObj.showVis();
	}
}
function startDrag(e){
	dragStartMouse = getMouse(e); // Holds the starting y mouse position
	dragStartOffset = dragObj.getTop(); // Holds the starting top position of the scrollbar drag
	document.addEvent("onmousemove", drag);
	document.addEvent("onmouseup", stopDrag);
	return false;
}
function stopDrag(){
	document.removeEvent("onmousemove");
	document.removeEvent("onmouseup");
}
function drag(e){
	var currentMouse = getMouse(e);
	var mouseDifference = currentMouse-dragStartMouse;
	var dragDistance = dragStartOffset+(mouseDifference*100)/browserHeight;
	var dragMovement = (dragDistance<trackTop) ? trackTop : (dragDistance>trackBottom) ? trackBottom : dragDistance;
	dragObj.setTop(dragMovement);
	var contentMovement = -(dragMovement-trackTop)*(1/scrollLength);
	contentObj.setTop(contentMovement);
	return false;
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Utility Functions

function hideScrollbars(){
	if(document.getElementsByTagName){
		document.getElementsByTagName("body")[0].style.overflow = "hidden";
	}
}
function fixNetscape4(){
	if(ns4origWidth != window.innerWidth || ns4origHeight != window.innerHeight){
		window.location.reload();
	}	
}
if(document.layers){
	ns4origWidth = window.innerWidth;
	ns4origHeight = window.innerHeight;
	window.onresize = fixNetscape4;
}

// |||||||||||||||||||||||||||||||||||||||||||||||||
