/*

  INLINE HV SCROLLBOX v1.1 RC (c) 2001-2004 Angus Turnbull, http://www.twinhelix.com
  This notice may not be altered or removed. See my site for licensing and more scripts!

*/



// This is the full, commented script file, to use for reference purposes or if you feel
// like tweaking anything. I used the "CodeTrimmer" utility availble from my site
// (under 'Miscellaneous' scripts) to trim the comments out of this JS file.



// *** COMMON CROSS-BROWSER COMPATIBILITY CODE ***


// This is taken from the "Modular Layer API" available on my site.
// See that for the readme if you are extending this part of the script.

var isDOM=document.getElementById?1:0,
 isIE=document.all?1:0,
 isNS4=navigator.appName=='Netscape'&&!isDOM?1:0,
 isIE4=isIE&&!isDOM?1:0,
 isOp=self.opera?1:0,
 isDyn=isDOM||isIE||isNS4;

function getRef(i, p)
{
 p=!p?document:p.navigator?p.document:p;
 return isIE ? p.all[i] :
  isDOM ? (p.getElementById?p:p.ownerDocument).getElementById(i) :
  isNS4 ? p.layers[i] : null;
};

function getSty(i, p)
{
 var r=getRef(i, p);
 return r?isNS4?r:r.style:null;
};

if (!self.LayerObj) var LayerObj = new Function('i', 'p',
 'this.ref=getRef(i, p); this.sty=getSty(i, p); return this');
function getLyr(i, p) { return new LayerObj(i, p) };

function LyrFn(n, f)
{
 LayerObj.prototype[n] = new Function('var a=arguments,p=a[0],px=isNS4||isOp?0:"px"; ' +
  'with (this) { '+f+' }');
};
LyrFn('x','if (!isNaN(p)) sty.left=p+px; else return parseInt(sty.left)');
LyrFn('y','if (!isNaN(p)) sty.top=p+px; else return parseInt(sty.top)');
LyrFn('w','if (p) (isNS4?sty.clip:sty).width=p+px; ' +
 'else return (isNS4?ref.document.width:ref.offsetWidth)');
LyrFn('h','if (p) (isNS4?sty.clip:sty).height=p+px; ' +
 'else return (isNS4?ref.document.height:ref.offsetHeight)');
LyrFn('vis','sty.visibility=p');




// *** SCROLLER OBJECT SETUP ***

function InlineScrollbox(myName, pageName)
{
 // These are the properties and function bindings used.
 this.myName = myName;
 this.pageName = pageName;
 this.div = null;
 this.divCont = null;

 this.scrW = this.scrH = this.scrTop = this.scrLeft = 0;
 this.xSpeed = this.ySpeed = this.stepsLeft = 0;

 this.timer = 0;

 // Record this scroller in the list for this page.
 InlineScrollbox.list[myName] = this;
};

InlineScrollbox.list = {};

// A quick reference to its prototype, to reduce script size.
var IsPt = InlineScrollbox.prototype;



// *** MAIN SCROLLER FUNCTIONS ***

IsPt.load = function(pageToLoad) { with (this)
{
 if (!isDyn) return;

 // Pre-existing page? Hide it, and reset the div object to null.
 if (div)
 {
  (isNS4?div:divCont).vis('hidden');
  div = null;
 }

 // Record this as the active page, scroll back to 0 position.
 pageName = pageToLoad;
 scrollTo(0, 0);
 return;
}};

IsPt.scrollTo = function(xPos, yPos) { with (this)
{
 if (!pageName || !isDyn) return;

 // Get references and set up divs....
 if (!div)
 {
  // Get reference/dimensions to outer ILAYER (NS4), or this page container (others).
  divCont = getLyr(myName + '-Container' + (isNS4?'':'-'+pageName));
  if (!divCont.ref) return;
  if (isNS4) with (divCont.sty.clip) { scrW = width; scrH = height }

  // Reference & show the inner page div that is moved within its container(s).
  // We show the inner page divs themselves in NS4, or their containers in others.
  div = getLyr(myName + (isNS4?'-':'-Page-') + pageName, isNS4?divCont.ref:null);
  if (!div.ref) return;
  (isNS4?div:divCont).vis('visible');

  // Add mousewheel support in IE6+, you may wish to alter the scrolling amount or direction.
  if (isIE) div.ref.onmousewheel = new Function(myName +
   '.scrollBy(0,event.wheelDelta/-3); return false');
 }

 // Find the dimensions of the scrolling page. Opera 5 doesn't want to return width of
 // in-scroller page content (Opera 6 is fine)...
 // If you have many vocal Opera 5 users, perhaps hardcode page widths in somewhere.
 var pagW = div.w(), pagH = (isOp&&!document.documentElement)?div.sty.pixelHeight:div.h();

 // STUPID MOZILLA PATCH: In some ways, Mozilla 1.x proves the million-monkeys theory. For
 // no apparent reason, when you have a sized div with "overflow: hidden", the offsetWidth
 // property of anything within that div is reported as the size of the outside div, even if
 // it renders as much wider and it gets the offsetHeight right. Argh!
 if (navigator.userAgent.indexOf('rv:1.') > 0) with (div.ref)
  for (var i = 0; i < childNodes.length; i++)
   pagW = Math.max(pagW, (childNodes[i].offsetWidth ? childNodes[i].offsetWidth : 0));

 // Check the scroll position for content edges & scroll!
 scrLeft = Math.max(0, Math.min(xPos, pagW-scrW));
 div.x(0 - parseInt(scrLeft));
 scrTop = Math.max(0, Math.min(yPos, pagH-scrH));
 div.y(0 - parseInt(scrTop));
 return;
}};


IsPt.scrollBy = function(xDiff, yDiff) { with (this)
{
 // Scrolls the div by a certain amount of pixels.
 if (!pageName) return;
 scrollTo(scrLeft + xDiff, scrTop + yDiff);
 return;
}};


IsPt.setScroll = function(newX, newY, steps) { with (this)
{
 if (!pageName || !isDyn) return;

 // Alter scroller velocity in steps to the new speed, set timer interval.
 stepsLeft = steps;

 if (timer) { clearInterval(timer); timer = null }
 timer = setInterval('with (' + myName + ') { if (stepsLeft > 0) { xSpeed += ' +
  ((newX-xSpeed)/steps) + '; ySpeed += ' + ((newY-ySpeed)/steps) + '; stepsLeft-- } ' +
  'scrollBy(xSpeed, ySpeed) }', 5);
 return;
}};



// *** IE/NS6/OPERA DIV CONSTRUCTION FUNCTIONS ***

IsPt.startArea = function(w, h) { with (this)
{
 // Record dimensions of scrolling area, and write out container div.
 scrW = w;
 scrH = h;
 document.write('<div style="position: relative; width: '+w+'px; height: '+h+'px; overflow: hidden">');
}};

// Page name is passed to this - write out container and scr-PageName divs.
IsPt.startPage = function(pN) { with (this)
{
 document.write('<div id="' + myName + '-Container-' + pN + '" style="position: absolute; ' +
  'width: '+scrW+'px; height: '+scrH+'px; clip:rect(0px '+scrW+'px '+scrH+'px 0px); ' +
  'overflow: hidden; visibility: hidden"><div id="' + myName + '-Page-' + pN +
  '" style="position: ' + (isIE?'absolute':'relative') + '">');
}};

IsPt.endPage = function() { document.write('</div></div>') };

IsPt.endArea = function() { document.write('</div>') };







// *** PAGE EVENTS ***

// Backup pre-existing ones, and run all scroller load commands on page load.

var ilsOL=window.onload, ilsOR=window.onresize, nsWinW=window.innerWidth, nsWinH=window.innerHeight;

window.onload = function()
{
 if (ilsOL) ilsOL();
 with (InlineScrollbox) for (var s in list) list[s].load(list[s].pageName);
};

function resizeBugCheck(){ if (nsWinW!=innerWidth || nsWinH!=innerHeight) location.reload() };
if (isOp&&!document.documentElement&&!self.opFix) self.opFix=setInterval('resizeBugCheck()',507);
window.onresize = function()
{
 if (ilsOR) ilsOR();
 if (isNS4) resizeBugCheck();
};