<!--

//ID of the scrollable area
var scrollboxID = "scrollbox";

//Speed Settings
var scrollDelaySec = 1; //Seconds between each movement
var scrollPixelsDefault = 6; //Default distance to move each interval
var scrollPixels = scrollPixelsDefault; //Current speed

var scrollSpeedAreaNumber = 3; //Number of different mouseover areas to increase speed
var scrollSpeedAreaInc = scrollPixelsDefault; //Amount to increase speed by for each mouseover area

//Misc globals for keeping track of activity
var scrollboxActive = 'off';
var scrollmouseover = 'off';
var scrollSpeedArea = 'off';
var scrolldirection = '';
var scrollolddirection = '';
var tCurrArea = '';
var tOldArea = '';

//Check to see if browser is IE
var IE = document.all?true:false

//Mouse Position Globals
var tempX = 0
var tempY = 0

function isEven(x) { return (x%2)?false:true; }
function isOdd(x) { return !isEven(x); }

function SetText(zID, zText, zAppend, zValue) {
	var zElement=document.getElementById(zID);
	if(zElement != null) {
		if (zAppend == true) { if (zValue == true) { zElement.value = zText + zElement.value; } else { zElement.innerHTML =zText + zElement.innerHTML; } }
		else { if (zValue == true) { zElement.value = zText; } else { zElement.innerHTML = zText; } }
	}
}

if (!IE) {
	HTMLElement.prototype.contains = function(node) {
		if (node == null) { return false; }
		if (node == this) { return true; }
		else { return this.contains(node.parentNode); }
	}
}

function ScrollMove(evt) {
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	} else {
		tempX = evt.pageX
		tempY = evt.pageY
	}
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}

	//document.getElementById('MouseX').value = tempX;
	//document.getElementById('MouseY').value = tempY;

	//SetText('output','X: ' + tempX + ' Y: ' + tempY + '\n',true,true);

	ScrollBoxMouseSpeed(tempX,tempY);

	return true
}
function ScrollStop(evt) {
	if (!document.getElementById(scrollboxID).contains(evt.relatedTarget || evt.toElement)) {
		//SetText('output','ScrollStop Fired\n',true,true);
		scrollSpeedArea = 'off';
		tCurrArea = '';
		scrolldirection = '';
		scroll_stop();
	}
}

function ScrollBoxMouseSpeed (MouseX,MouseY) {

	var scrollbox=document.getElementById(scrollboxID);
	if (scrollbox != null) {

		tWidth = scrollbox.offsetWidth;
		tHeight = scrollbox.offsetHeight;

		var curleft = 0;
		var curtop = 0;

		if (scrollbox.offsetParent) {
			while (scrollbox.offsetParent) {
				curleft += scrollbox.offsetLeft;
				curtop += scrollbox.offsetTop;
				scrollbox = scrollbox.offsetParent;
			} 
		}

		tBoxX1Pos = curleft;
		tBoxY1Pos = curtop;

		tBoxX2Pos = tBoxX1Pos+tWidth;
		tBoxY2Pos = tBoxY1Pos+tHeight;

		//document.getElementById('BoxX').value = tBoxX1Pos;
		//document.getElementById('BoxY').value = tBoxY1Pos;

		if ((MouseX >= tBoxX1Pos) && (MouseX <= tBoxX2Pos) && (MouseY >= tBoxY1Pos) && (MouseY <= tBoxY2Pos)) {

			tSpeedAreaSize = tWidth/scrollSpeedAreaNumber;
			tSpeedAreaSize = Math.round(tSpeedAreaSize);

			tDistancefromX1 = MouseX-tBoxX1Pos;
			tOldArea = tCurrArea;
			tCurrArea = Math.floor(tDistancefromX1/tSpeedAreaSize)+1;
			if (tCurrArea > scrollSpeedAreaNumber) { tCurrArea = scrollSpeedAreaNumber; }
			if (tCurrArea < 1) { tCurrArea = 1; }

			//SetText('output','Old: ' + scrollolddirection + ' New: ' + scrolldirection + '\n' + MouseX + ' ' + MouseY + '\n\n',false,false);

			if (tOldArea != tCurrArea) {
					if (isEven(scrollSpeedAreaNumber)) {
						tMiddleArea = scrollSpeedAreaNumber/2;
						if (tCurrArea <= tMiddleArea) {
							tSpeed = (scrollSpeedAreaInc*(tMiddleArea))-(scrollSpeedAreaInc * (tCurrArea));
							scrollSpeedArea = 'on';
							scroll_setspeed(tSpeed);
							scrollolddirection = scrolldirection;
							scrolldirection = 'left';
						} else {
							tSpeed = scrollSpeedAreaInc*((tCurrArea-tMiddleArea)-1);
							scrollSpeedArea = 'on';
							scroll_setspeed(tSpeed);
							scrollolddirection = scrolldirection;
							scrolldirection = 'right';
						}
					} else {
						tMiddleArea = ((scrollSpeedAreaNumber-1)/2)+1;
						if (tCurrArea < tMiddleArea) {
							tSpeed = (scrollSpeedAreaInc*(tMiddleArea))-(scrollSpeedAreaInc * (tCurrArea));
							scrollSpeedArea = 'on';
							scroll_setspeed(tSpeed);
							scrollolddirection = scrolldirection;
							scrolldirection = 'left';
						} else if (tCurrArea > tMiddleArea) {
							tSpeed = scrollSpeedAreaInc*((tCurrArea-(tMiddleArea-1))-1);
							scrollSpeedArea = 'on';
							scroll_setspeed(tSpeed);
							scrollolddirection = scrolldirection;
							scrolldirection = 'right';
						} else if (tCurrArea = tMiddleArea) {
							tSpeed = 0;
							scrollSpeedArea = 'on';
							scroll_setspeed(tSpeed);
							scrollolddirection = scrolldirection;
							scrolldirection = 'right';
						}
					}
					if (scrolldirection == 'left' && scrollolddirection != 'left') {
						//SetText('output','Move Left Fired\n',true,false);
						scrollmouseover = 'on';
						move_left();
					} else if (scrolldirection == 'right' && scrollolddirection != 'right') {
						//SetText('output','Move Right Fired\n',true,false);
						scrollmouseover = 'on';
						move_right();
					}
				//document.getElementById('InsideBox').value = "Area: " + tCurrArea + " - Speed: " + tSpeed;
			}
		} else {
			if (scrollSpeedArea == 'on') {
				scrollSpeedArea = 'off';
				tCurrArea = '';
				scrolldirection = '';
				scroll_stop();
			}
			//document.getElementById('InsideBox').value = "NO";
		}
	}

}

function scroll_incspeed () { scrollPixels = scrollPixelsDefault*2; }
function scroll_decspeed () { scrollPixels = scrollPixelsDefault; }
function scroll_setspeed (newspeed) { scrollPixels = newspeed; }

function scroll_up() {
	scrollPixels = scrollPixelsDefault;
	scrollmouseover = 'on';
	scrolldirection = 'up';
	move_up();
}
function move_up() {
	var scrollbox=document.getElementById(scrollboxID);
	if (scrollbox != null) {
		scroll_posTop = scrollbox.scrollTop;
		scroll_newpos = scroll_posTop-scrollPixels;
		if (scroll_newpos <= 1) { scroll_newpos = 1; }
		scrollbox.scrollTop = scroll_newpos;
		if ((scrollbox.scrollTop >= 1) && (scrollmouseover == 'on')) { 
			clearTimeout(parent.ScrollDelay);
			parent.ScrollDelay = setTimeout("move_up();", scrollDelaySec);
		}
	}
}
function scroll_down() {
	scrollPixels = scrollPixelsDefault;
	scrollmouseover = 'on';
	scrolldirection = 'down';
	move_down();
}
function move_down() {
	var scrollbox=document.getElementById(scrollboxID);
	if (scrollbox != null) {
		viewHeight = scrollbox.offsetHeight;
		scrollboxHeight = scrollbox.scrollHeight - viewHeight;
		scroll_posTop = scrollbox.scrollTop;
		scroll_newpos = scroll_posTop+scrollPixels;
		if (scroll_newpos >= scrollboxHeight) { scroll_newpos = scrollboxHeight; }
		scrollbox.scrollTop = scroll_newpos;
		if ((scrollbox.scrollTop <= scrollboxHeight) && (scrollmouseover == 'on')) { 
			clearTimeout(parent.ScrollDelay);
			parent.ScrollDelay = setTimeout("move_down();", scrollDelaySec);
		}
	}
}
function scroll_left() {
	scrollPixels = scrollPixelsDefault;
	scrollmouseover = 'on';
	scrolldirection = 'left';
	move_left();
}
function move_left() {
	var scrollbox=document.getElementById(scrollboxID);
	if (scrollbox != null) {
		scroll_posLeft = scrollbox.scrollLeft;
		scroll_newpos = scroll_posLeft-scrollPixels;
		if (scroll_newpos <= 1) { scroll_newpos = 1; }
		scrollbox.scrollLeft = scroll_newpos;
		if ((scrollbox.scrollLeft >= 1) && (scrollmouseover == 'on')) {
			clearTimeout(parent.ScrollDelay);
			parent.ScrollDelay = setTimeout("move_left();", scrollDelaySec);
		}
	}
}
function scroll_right() {
	scrollPixels = scrollPixelsDefault;
	scrollmouseover = 'on';
	scrolldirection = 'right';
	move_right();
}
function move_right() {
	var scrollbox=document.getElementById(scrollboxID);
	if (scrollbox != null) {
		viewWidth = scrollbox.offsetWidth;
		scrollboxWidth = scrollbox.scrollWidth - viewWidth;
		scroll_posLeft = scrollbox.scrollLeft;
		scroll_newpos = scroll_posLeft+scrollPixels;
		if (scroll_newpos >= scrollboxWidth) { scroll_newpos = scrollboxWidth }
		scrollbox.scrollLeft = scroll_newpos;
		if ((scrollbox.scrollLeft <= scrollboxWidth) && (scrollmouseover == 'on')) {
			clearTimeout(parent.ScrollDelay);
			parent.ScrollDelay = setTimeout("move_right();", scrollDelaySec);
		}
	}
}
function scroll_autolr() {
	scrollPixels = scrollPixelsDefault;
	scrollmouseover = 'on';
	if(scrolldirection != 'left') {
		scrolldirection = 'right';
	}
	move_autolr();
}
function move_autolr() {
	var scrollbox=document.getElementById(scrollboxID);
	if (scrollbox != null) {
		viewWidth = scrollbox.offsetWidth;
		scrollboxWidth = scrollbox.scrollWidth - viewWidth;
		scroll_posLeft = scrollbox.scrollLeft;
		if (scrolldirection == 'left') {
			scroll_newpos = scroll_posLeft-scrollPixels;
			if (scroll_newpos <= 1) { scroll_newpos = 1; scrollolddirection = scrolldirection; scrolldirection = 'right'; }
			scrollbox.scrollLeft = scroll_newpos;
		}
		if (scrolldirection == 'right') {
			scroll_newpos = scroll_posLeft+scrollPixels;
			if (scroll_newpos >= scrollboxWidth) { scroll_newpos = scrollboxWidth; scrollolddirection = scrolldirection; scrolldirection = 'left'; }
			scrollbox.scrollLeft = scroll_newpos;
		}
		if (((scrollbox.scrollLeft >= 1) && (scrollbox.scrollLeft <= scrollboxWidth)) && (scrollmouseover == 'on')) {
			clearTimeout(parent.ScrollDelay);
			parent.ScrollDelay = setTimeout("move_autolr();", scrollDelaySec);
		}
	}
}
function scroll_autoud() {
	scrollPixels = scrollPixelsDefault;
	scrollmouseover = 'on';
	if(scrolldirection != 'up') {
		scrolldirection = 'down';
	}
	move_autoud();
}
function move_autoud() {
	var scrollbox=document.getElementById(scrollboxID);
	if (scrollbox != null) {
		viewHeight = scrollbox.offsetHeight;
		scrollboxHeight = scrollbox.scrollHeight - viewHeight;
		scroll_posTop = scrollbox.scrollTop;
		if (scrolldirection == 'up') {
			scroll_newpos = scroll_posTop-scrollPixels;
			if (scroll_newpos <= 1) { scroll_newpos = 1; scrollolddirection = scrolldirection; scrolldirection = 'down'; }
			scrollbox.scrollTop = scroll_newpos;
		}
		if (scrolldirection == 'down') {
			scroll_newpos = scroll_posTop+scrollPixels;
			if (scroll_newpos >= scrollboxHeight) { scroll_newpos = scrollboxHeight; scrollolddirection = scrolldirection; scrolldirection = 'up'; }
			scrollbox.scrollTop = scroll_newpos;
		}
		if (((scrollbox.scrollTop >= 1) && (scrollbox.scrollTop <= scrollboxHeight)) && (scrollmouseover == 'on')) {
			clearTimeout(parent.ScrollDelay);
			parent.ScrollDelay = setTimeout("move_autoud();", scrollDelaySec);
		}
	}
}
function scroll_stop() {
	scrollPixels = scrollPixelsDefault;
	scrollmouseover = 'off';
	tCurrArea = '';
	scrolldirection = '';
	clearTimeout(parent.ScrollDelay);
}
function ScrollToElement (ElementID) {
	var tElement=document.getElementById(ElementID);
	if (tElement != null) {
		tPosX = tElement.offsetLeft;
		tPosY = tElement.offsetTop;
		tWidth = tElement.offsetWidth;
		tHeight = tElement.offsetHeight;

		var scrollbox=document.getElementById(scrollboxID);
		if (scrollbox != null) {
			viewWidth = scrollbox.offsetWidth;
			scrollboxWidth = scrollbox.scrollWidth - viewWidth;
			viewHeight = scrollbox.offsetHeight;
			scrollboxHeight = scrollbox.scrollHeight - viewHeight;
			tScrollPosX = tPosX-((viewWidth/2)-(tWidth/2));
			tScrollPosY = tPosY-((viewHeight/2)-(tHeight/2));
			scrollbox.scrollLeft = tScrollPosX;
			scrollbox.scrollTop = tScrollPosY;
		}
	}
}
// -->

