/*********************************************************************
Multi-page scroller with auto scrollbars
A script by
Dave Cage - Dec 2000 (nikzhowz@mailandNOPORKnews.com)
Michael van Ouwerkerk (Laz) Dec 2000 (mvouwerkerk@hotNOSPAMmail.com)
Tested in IE5 && 5.5, NN4, and NN6 on a Win98 system
NN6 is squirrelly as ever -- it works, but not without hiccups.
Free for personal use as long as this message is intact, blah de blah...
**********************************************************************/
/********************************************************************************************************
UPDATE LOG... line numbers are approximate...
Feb 2 2001, fixes for explorer 5.5:
    line 173: if(document.all)document.onselectstart= function(){ if(main.active)return false };
    lines 181, 182, 189: boolean checks for main.active before changing any values onmouseover/onmouseout
********************************************************************************************************/

numOfPages= 1;		// Like it says, the number of scrolling pages
railColor= '000000';	// The default color of the rail the scroll button is set in
railHilite= '081D21';	// The highlight color when scrolling with a mousedown in the rail
viewPortTop= 215;	// Top position of the view window
viewPortLeft= 350;	// Left position of viewport
railTop= 215;		// Top position of the rail
railLeft= 725;		// Left position of rail
buttonColor= '000000'
scrollTm= 80		// The loop delay in milliseconds that's incrementally reduced as you hold down the
				// mouse button in the rail area. Allows you to click and scroll a single step without
				// overshooting the target text.
var pageStep = 12;	//Controls the speed of pagescrolling when you click in the rail, in pixels.

				// Set the sizes of the rail, button, and view window in the style section above
				// Scrolling text styles are applied through the "txt" class
				// The change-page links are not handled by the script. Set all values above

function sniffIt(){
	this.opera= (navigator.userAgent.indexOf('Opera')>-1);
	this.nn4= (document.layers);
	this.ie4= (document.all && !document.getElementById);
	this.ie5= (document.getElementById && document.all && !this.opera);
	this.nn6= (document.getElementById && !document.all && !this.opera);
	this.mac= (navigator.userAgent.indexOf('Mac')>-1 && this.ie4); // For excluding IE4 macs only
	this.ok= (this.nn4 || this.ie4 || this.ie5 || this.nn6 && !this.mac && !this.opera);
}
who= new sniffIt();

px= (who.nn6)?'px':0;

if(who.nn4){
	document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP);
	scrX= innerWidth;	scrY= innerHeight;
	window.onresize= function(){if(scrX!= innerWidth || scrY!= innerHeight){history.go(0)}}
}
function makeObj(obj,nest){
	nest= (!nest)?'':'document.'+nest+'.';
	this.sty= (who.nn4)?eval(nest+'document.'+obj):(who.ie4)?document.all[obj].style:document.getElementById(obj).style;
	this.el= (who.nn4)?this.sty:(who.ie4)?document.all[obj]:document.getElementById(obj);
	this.moveIt= moveIt;
	this.showIt= showIt;
	this.hideIt= hideIt;
	this.chgCol= chgCol;
	this.ht= (who.nn4)?this.sty.clip.height:this.el.offsetHeight;
}

function moveIt(x,y){this.x=x; this.y=y; this.sty.left=x+px; this.sty.top=y+px;}
function showIt(){this.sty.visibility= 'visible';}
function hideIt(){this.sty.visibility= 'hidden';}
function chgCol(col){if(who.nn4)this.sty.bgColor= col; else this.sty.backgroundColor= col;}

function trackIt(e){
	if(main.active){
		var tmp= pg[main.page];
		if(main.over==1){
			var y= ((who.nn4 || who.nn6)?e.pageY:event.y-2)-yLoc;
			y= (y<=0)?0:(y>=button.limit)?button.limit:y;
			button.moveIt(0,y);
			tmp.moveIt(0,y*tmp.inc);
			return false;
		}
	}
}
function dragIt(e){
	if(window.event && event.button==1 || window.Event && e.which==1){
	    yLoc= (who.nn4 || who.nn6)?e.pageY:event.y-2;
	    if(main.over==1){
		    yLoc-= button.y
		    main.active= 1;
      return false
	    }
	    else if(main.over==2){
		    yLoc= yLoc-rail.y;
		    rail.chgCol(railHilite);
		    scrollIt();		
	    }
	}
	else if (who.nn4) {main.over=0; main.nn=0;}
}

function scrollIt(){
		var tmp= pg[main.page];
		main.speed= (main.speed>20)?main.speed-=20:20;
		if(yLoc-button.half>button.y && button.y<button.limit){
			if(button.y >= button.limit-tmp.step){
			   button.moveIt(0,button.limit);
			   tmp.moveIt(0,-tmp.ht+view.ht);
			}
			else{
			   button.moveIt(0,button.y+tmp.step);
			   tmp.moveIt(0,tmp.y+(tmp.inc*tmp.step))
			}
			main.timerID= setTimeout('scrollIt()',main.speed);
		}

		else if(yLoc<button.y){
			if(button.y <= 0+tmp.step){
			   button.moveIt(0,0);
			   tmp.moveIt(0,0);
			}
			else{
			   button.moveIt(0,button.y-tmp.step);
			   tmp.moveIt(0,tmp.y-(tmp.inc*tmp.step));
			}
			main.timerID= setTimeout('scrollIt()',main.speed);
		}
		else return false;
}

function dragEnd(){
	main.active= 0;
	main.speed= 70;
	clearTimeout(main.timerID);
	rail.chgCol(railColor);
	return true;
}
function chgPage(num){
	pg[main.page].yPos= button.y;
	pg[main.page].hideIt();
	main.page= num;
	if(pg[num].inc==0)rail.hideIt();
	else rail.showIt();
	button.moveIt(0,pg[num].yPos)
	pg[num].moveIt(0,pg[num].inc*button.y);
	pg[num].showIt();
}
function setUp(){
	main= {}
	main.over= 0;
	main.active= 0;
	main.page= 0;
	main.nn= 0;
	main.speed= scrollTm;
	main.timerID= null;
	document.onmousemove= trackIt;
	document.onmousedown= dragIt;
	document.onmouseup= dragEnd;
	if(document.all)document.onselectstart= function(){ if(main.active)return false };
	view= new makeObj('viewPort');
	view.moveIt(viewPortLeft,viewPortTop);
	rail= new makeObj('sRail');
	rail.chgCol(railColor);
	rail.moveIt(railLeft,railTop);
	rail.el.onmouseover= function(){if(!main.active)main.over= 2;main.nn=1}
	rail.el.onmouseout= function(){if(!main.active)main.over= 0;main.nn=0}
	button= new makeObj('sButton','sRail');
	button.chgCol(buttonColor);
	button.moveIt(0,0);
	button.limit= rail.ht-button.ht;
	button.half= Math.floor(button.ht/2);
	button.el.onmouseover= function(e){main.over= 1;if(who.ie4 || who.ie5)event.cancelBubble= 'true';if(who.nn6)e.cancelBubble= 'true'};
	button.el.onmouseout= function(e){ if(who.nn4){if(main.nn){main.over=2}else{main.over=0}} else if(!main.active) main.over=0; }
	pg= new Array()
	for(var i=0;i<numOfPages;i++){
		pg[i]= new makeObj('page'+i,'viewPort');
		pg[i].moveIt(0,0);
		pg[i].ht= (who.nn4)?pg[i].sty.clip.height:pg[i].el.offsetHeight;
		pg[i].inc= (pg[i].ht<view.ht)?0:-((pg[i].ht-view.ht)/(rail.ht-button.ht));
		pg[i].step= pg[i].inc!=0?pageStep/-pg[i].inc:0;
		pg[i].yPos= 0;
	}
	pg[0].showIt();
	view.showIt();
	if(pg[0].inc<0)rail.showIt();
}
if(who.ok) onload= setUp;