﻿		// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
		// 
		// 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: 09/29/02 ---------------------------------------------------------

		// Utility Functions

		var dom = document.getElementById;
		var iex = document.all;
		var ns4 = document.layers;
		
		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.getTop = function(){return parseInt(el.css.top) || 0};
			el.setTop = function(y){el.css.top=y};
			el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
			el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
			return el;
		}

		function getMouse(e)
		{
			return iex ? event.clientY : e.pageY;
		}

		function fixNetscape()
		{
			if(NS4origWidth != window.innerWidth || NS4origHeight != window.innerHeight)
			{
				window.location.reload();
			}	
		}

		if(document.layers)
		{
			NS4origWidth = window.innerWidth;
			NS4origHeight = window.innerHeight;
			window.onresize = fixNetscape;
		}

		// Scroll Functions

		function initTextScroller()
		{
			textScrollSpeed = 6; // scrolling speed
			textDragHeight = 94; // Height of scrollbar drag
			textTrackHeight = 314; // Height of scrollbar track
			textTrackObj = getElement('textScrolltrack'); // Reference to the scrollbar track div
			textUpObj = getElement('textScrollup'); // Reference to the up arrow div
			textDownObj = getElement('textScrolldown'); // Reference to the down arrow div
			textDragObj = getElement('textScrolldrag'); // Reference to the scrollbar drag div
			textContentMaskObj = getElement('textContentMask'); // Reference to the content mask div
			textContentObj = getElement('textContent','textContentMask'); // Reference to the content div
			textTrackTop = textDragObj.getTop(); // Scrollbar top contraint
			textTrackLength = textTrackHeight-textDragHeight; // Adjusted track height
			textTrackBottom = textTrackTop+textTrackLength; // Scrollbar bottom constraint
			textContentMaskHeight = textContentMaskObj.getClipHeight();// Height of the div that masks the content div
			textContentHeight = textContentObj.getHeight(); // Height of the content div
			textContentLength = textContentHeight-textContentMaskHeight; // Adjusted content height
			textScrollLength = textTrackLength/textContentLength; // Height difference between the scrollbar track and the content
			textScrollTimer = null;
			textTrackObj.onmousedown = textScrollJump;
			textUpObj.onmousedown = function(){textStartScroll(textScrollSpeed); return false};
			textDownObj.onmousedown = function(){textStartScroll(-textScrollSpeed); return false};
			textDragObj.onmousedown = textStartDrag;
			textDragObj.ondragstart = function(){return false}; // for ie4.5 compatibility
			if(ns4)
			{
				textTrackObj.captureEvents(Event.MOUSEDOWN);
				textUpObj.captureEvents(Event.MOUSEDOWN);
				textDownObj.captureEvents(Event.MOUSEDOWN);
				textDragObj.captureEvents(Event.MOUSEDOWN);
			}
		}
		
		function textStartDrag(e)
		{
			dragStartMouse = getMouse(e); // Holds the starting y mouse position
			dragStartOffset = textDragObj.getTop(); // Holds the starting top position of the scrollbar drag
			document.onmousemove = textDrag;
			document.onmouseup = textStopDrag;
			if(ns4) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
			return false;
		}
		
		function textStopDrag()
		{
			if(ns4) document.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
			document.onmousemove = null;
			document.onmouseup = null;
		}

		function textDrag(e)
		{
			// move drag
			var currentMouse = getMouse(e);
			var mouseDifference = currentMouse-dragStartMouse;
			var dragDistance = dragStartOffset+mouseDifference;
			var dragMovement = (dragDistance<textTrackTop) ? textTrackTop : (dragDistance>textTrackBottom) ? textTrackBottom : dragDistance;
			textDragObj.setTop(dragMovement);
			// move content
			var contentMovement = -(dragMovement-textTrackTop)*(1/textScrollLength);
			textContentObj.setTop(contentMovement);
			return false;
		}

		function textStartScroll(speed)
		{
			document.onmouseup = textStopScroll;
			if(ns4) document.captureEvents(Event.MOUSEUP);
			textScroll(speed);
		}

		function textScroll(speed)
		{
			// move content
			var contentMovement = textContentObj.getTop()+speed;
			if(contentMovement > 0)
			{
				contentMovement = 0;
			}
			else if(contentMovement < -textContentLength)
			{
				contentMovement = -textContentLength;
			}
			textContentObj.setTop(contentMovement);
			// move drag
			var dragMovement = textContentObj.getTop()*(textTrackLength/textContentLength);
			dragMovement = textTrackTop-Math.round(dragMovement);
			if(dragMovement < textTrackTop)
			{
				dragMovement = textTrackTop;
			}
			else if(dragMovement > textTrackBottom)
			{
				dragMovement = textTrackBottom;
			}
			textDragObj.setTop(dragMovement);
			// repeat
			textScrollTimer = window.setTimeout('textScroll('+speed+')',25);
			return false;
		}

		function textStopScroll()
		{
			if(textScrollTimer)
			{
				window.clearTimeout(textScrollTimer);
				textScrollTimer = null;
			}
			if(ns4) document.releaseEvents(Event.MOUSEUP);
			document.onmouseup = null;
		}

		function textScrollJump(e)
		{
			// move drag
			var currentMouse = getMouse(e);
			var dragDistance = currentMouse-(textDragHeight/2);
			var dragMovement = (dragDistance<textTrackTop) ? textTrackTop : (dragDistance>textTrackBottom) ? textTrackBottom : dragDistance;
			textDragObj.setTop(dragMovement);
			// move content
			var contentMovement = -(dragMovement-textTrackTop)*(1/textScrollLength);
			textContentObj.setTop(contentMovement);
			return false;
		}
		

		window.onload = initTextScroller;
