// *** Scroller script by Angus Turnbull http://www.twinhelix.com ***

var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=(navigator.appName=='Netscape'&&!isDOM)?1:0;
var isDyn=(isDOM||isIE||isNS4);

function getRef(id, par)
{
 par = (!par ? document : (par.navigator ? par.document : par));
 return (isIE ? par.all[id] :
  (isDOM ? (par.getElementById?par:par.ownerDocument).getElementById(id) :
  par.layers[id]));
}

function getSty(id, par)
{
 return (isNS4 ? getRef(id, par) : getRef(id, par).style);
}


if (!window.LayerObj) var LayerObj = new Function('id', 'par',
 'this.ref=getRef(id, par); this.sty=getSty(id, par); return this');
function getLyr(id, par) { return new LayerObj(id, par) }

function LyrFn(fn, fc)
{
 LayerObj.prototype[fn]=new Function('var a=arguments, p=a[0]; with (this) {'+fc+'}');
}

LyrFn('x','if (!isNaN(p)) sty.left=p; else return parseInt(sty.left)');
LyrFn('y','if (!isNaN(p)) sty.top=p; else return parseInt(sty.top)');
LyrFn('w','if (p) (isNS4?sty.clip:sty).width=p; ' +
 'else return (isNS4?ref.document.width:ref.offsetWidth)');
LyrFn('h','if (p) (isNS4?sty.clip:sty).height=p; ' +
 'else return (isNS4?ref.document.height:ref.offsetHeight)');
LyrFn('vis','sty.visibility=p');
LyrFn('clip','if (isNS4) with(sty.clip) { left=a[0]; top=a[1]; right=a[2]; bottom=a[3] } ' +
 'else sty.clip="rect("+a[1]+"px "+a[2]+"px "+a[3]+"px "+a[0]+"px)" ');


// *** SCROLLER SCRIPT ENGINE ***

function pscScrollTo(xPos, yPos) { with (this)
{
 if (!loaded) return;

 if (!divO)
 {
  divO = getLyr(myName + 'Outer');
  with (divO) { x(scrX); y(scrY); w(scrW); h(scrH); clip(0, 0, scrW, scrH); vis('visible') }
 } 
 if (!divI) divI = getLyr(myName + 'Inner', divO.ref);

 var divW = divI.w(), divH = divI.h();

 if (yPos + scrH > divH) yPos = divH - scrH;
 if (yPos < 0) yPos = 0;
 
 if (xPos + scrW > divW) xPos = divW - scrW;
 if (xPos < 0) xPos = 0;

 with (divI)
 {
  x(0 - parseInt(xPos));
  y(0 - parseInt(yPos));
 }

 scrLeft = xPos;
 scrTop = yPos;
}}


function pscScrollBy(xDiff, yDiff) { with (this)
{
 if (!loaded) return;
 scrollTo(scrLeft + xDiff, scrTop + yDiff);
}}


function pscSpeedCalc() { with (this)
{
 if (stepsLeft > 0)
 {
  xVel += dX;
  yVel += dY;
  stepsLeft--;
 }
 scrollBy(xVel, yVel);
}}


function pscSetScroll(newX, newY, steps) { with (this)
{
 dX = (newX - xVel) / steps;
 dY = (newY - yVel) / steps;
 stepsLeft = steps;

 if (timer) { clearInterval(timer); timer = null }
 timer = setInterval(myName + '.speedCalc()', 40);
}}


function PageScroller(myName, scrX, scrY, scrW, scrH)
{
 this.myName = myName;
 this.divO = this.divI = null;
 this.loaded = false;

 this.timer = 0;
 
 this.xVel = 0;
 this.yVel = 0;
 this.dX = 0;
 this.dY = 0;
 this.stepsLeft = 0;
 
 this.scrX = scrX;
 this.scrY = scrY;
 this.scrW = scrW;
 this.scrH = scrH;

 this.scrTop = 0;
 this.scrLeft = 0;

 this.scrollTo = pscScrollTo;
 this.scrollBy = pscScrollBy;
 this.speedCalc = pscSpeedCalc;
 this.setScroll = pscSetScroll;
}

