//copied from http://pastelhorn.com/project/js/scrollspy/scrollspy-093.js.txtvar agt = navigator.userAgent.toLowerCase();var isOpera = ( (agt.indexOf("opera") != -1)                 && document.getElementById   ) ? 1 : 0;                 var isNav4 = (document.layers && !isOpera) ? 1 : 0;var isIE4  = (document.all && !isOpera) ? 1 : 0;var isMoz  = ( document.getElementById && !(isNav4 || isIE4 | isOpera) ) ? 1 : 0;if (isNav4) {  widthCheck = window.innerWidth;  heightCheck = window.innerHeight;  window.onResize = resizeFix;}function resizeFix() {  if ( widthCheck != window.innerWidth || heightCheck != window.innerHeight )    document.location.href = document.location.href;} function getTop() {layer = getDiv(scrollDiv);  if (isNav4)    return layer.top;  else    if (isIE4)      return layer.style.pixelTop;    else	  if (isMoz) {		return layer.style.top;	  }	  else	    if (isOpera)          		  return layer.style.top;}function setTop(layer, t) {  if (isNav4)    layer.top = t;  else    if (isIE4)      layer.style.pixelTop = t;    else	  if (isMoz) {	    var p = '' + t + 'px';		layer.style.top = p;	  }	  else	    if (isOpera)          		  layer.style.top = t;}var divObject;function getDiv(divname) {	// given name 'divname', return div object	// if div is within otherdiv, use 'otherdivname.divname' format as parameter	divs = divname.split('.'); 	if (isNav4) {		s = ''		for (i = 0; i < divs.length; i++) {			s += 'document.layers.' + divs[i];			if (i < divs.length - 1) 				s += '.';		}			divObject = eval(s);			return  divObject;	}	if (isIE4)		divObject = eval( 'document.all.' + divs[ divs.length-1 ] );		return divObject;	if (isMoz || isOpera)		divObject = document.getElementById(divs[ divs.length-1 ] );		return divObject;}function update(scrollPos) {  thediv = getDiv(scrollDiv);  setTop(thediv, scrollPos+ origTop);}var S;var scrollDiv;var origTop;  function initSpy(tempScrollDiv) {    scrollDiv=tempScrollDiv;   origTop = getTop(scrollDiv);  S = new scrollSpy(update, tempScrollDiv);  S.start();}function initSpyMult(tempScrollDiv, multName) {    scrollDiv=tempScrollDiv;   origTop = getTop(scrollDiv);  eval(multName + '= new scrollSpy(update, tempScrollDiv);');  eval(multName + '.start()');}function scrollSpy(theFunction) {//// First, set window.RANDOMNAME to this Spy object, so the outside world// can refer to it.//// Although ugly, it's needed, if we want "setInterval()" to apply a method// on our object:  when using "setInterval("this...", ..)", the// "this" will refer to the window, because that's the object running// the function "setInterval".//// Another solution would be, passing the object's name as parameter to// the constructor:////   S = new scrollSpy('S', func)//// and use the first parameter to build the "setInterval()" command line.//  var NameOfThisSpy = generateSpyInternalName();    eval('window.' + NameOfThisSpy + ' = this;'); // window.RANDOMNAME = <this_spy>  eval('this.name = "' + NameOfThisSpy + '";'); // <this_spy>.name = "RANDOMNAME"  this.changeFunction = theFunction;  this.intervalTime = 200;   // by default 200 milliseconds  this.enabled = 0;  this.monitor = monitorScrolling;  this.getWindowYOffset = getWindowYOffsetSpy;  this.prevWindowYOffset = 0; /// public interface:    this.start = startSpy;  this.stop = stopSpy;  this.isRunning = isRunningSpy;    this.getIntervalTime = getIntervalTimeSpy;  this.setIntervalTime = setIntervalTimeSpy; /////}function startSpy() {  if (!this.enabled) { // not already running?    var cmdstring = 'window.' + this.name + '.monitor()';        if (!isOpera)      this.interval = window.setInterval( cmdstring, this.intervalTime );    else // work around bug      this.interval = window.setTimeout( cmdstring, this.intervalTime );    this.enabled = 1;  }}function stopSpy() {  if (this.enabled) { // really running?    window.clearInterval(this.interval);    this.enabled = 0;  }}function isRunningSpy() {  return this.enabled;}    function getIntervalTimeSpy() {  return this.intervalTime;}function setIntervalTimeSpy(newValue) {  var wasRunning = (this.enabled) ? 1 : 0;  this.stop();  this.intervalTime = newValue;  if (wasRunning)    this.start();}function getWindowYOffsetSpy() {  if ( window.pageYOffset || window.pageYOffset == 0 )    return window.pageYOffset;  if ( document.body ) {    if ( document.body.scrollTop || document.body.scrollTop == 0 ) {      if ( document.documentElement ) {        if ( document.documentElement.scrollTop || document.documentElement.scrollTop == 0 ) {          // IE 6 uses document.documentElement.scrollTop instead of          // document.body.scrollTop. Has to do with viewpoints -          // see some w3 spec ;-)          return document.body.scrollTop + document.documentElement.scrollTop; // +50;        }      } else {        return document.body.scrollTop; // + 100;      }    }  }}  function monitorScrolling() {  var newWinYOffset = getWindowYOffsetSpy();  var Scrolled = (newWinYOffset != this.prevWindowYOffset);//if (jdebug) alert(Scrolled);  this.prevWindowYOffset = newWinYOffset;  if (Scrolled) {       eval( 'this.changeFunction(' + newWinYOffset + ')' );    //if (jdebug) alert(newWinYOffset);}  if (isOpera) {  // work around bug    var cmdstring = 'window.' + this.name + '.monitor()';    this.interval = window.setTimeout( cmdstring, this.intervalTime);  }    }function generateSpyInternalName() {  var now = new Date();  var rand = Math.floor(  1000000 * Math.random(now.getTime())  );  return ('spy' + rand + 's');}
