// JavaScript Document
sniff = new Sniffer();
scrollTimer=10;

// scroller class ..
function initScroller(posId,heightID) {
this.scrollCSSObj=sniff.CSSPath(posId);
this.scrollHTMLObj=sniff.HTMLPath(posId);
this.heightHTMLObj=sniff.HTMLPath(heightID);
this.scrollDivHeight= this.scrollHTMLObj.offsetHeight;
this.centerDivHeight= this.heightHTMLObj.offsetHeight;
this.adjustment=0;
this.topLength=186;   // space + Banner;
this.centerAndTopLength = this.centerDivHeight + this.topLength;
this.bottomSpace=0;   // Leave some space below.
this.b_WindowHeight=0;
this.last_b_WindowHeight = 0;
this.scrollAreaSize;
this.amountOfScroll=0;
this.xScrollTo = xScrollTo;
this.directionDown=true;
this.invisibleTopHeight=0;
this.scrollCSSObj.marginTop = "0px";
}

function removePX (cssBit) {
return cssBit.slice(0,-2)-0;
}

function xScrollTo() {
// Current Height.
this.last_b_WindowHeight = this.b_WindowHeight;
this.b_WindowHeight = AlertSize("H");
this.lastAmountOfScroll = this.amountOfScroll;
this.amountOfScroll = getScrollXY();

  // Maybe No Change ..
	if ((this.last_b_WindowHeight==this.b_WindowHeight)&&(this.lastAmountOfScroll==this.amountOfScroll)) {return 0;}

  // No action required ..
    if (this.scrollDivHeight>=this.centerDivHeight) {return 0};

this.directionDown              = (this.lastAmountOfScroll<=this.amountOfScroll); // Default down ..
this.currentInvisibleTopHeight  = this.invisibleTopHeight;
this.visibleTopHeight           = Math.max(this.topLength-this.amountOfScroll,0);
this.invisibleTopHeight         = Math.max(this.topLength - this.visibleTopHeight,0);
this.changeToInvisibleTopHeight = this.currentInvisibleTopHeight - this.invisibleTopHeight;
this.bottomVisible              = Math.max((this.b_WindowHeight+this.amountOfScroll)-(this.centerAndTopLength),0);
this.scrollAreaSize             = this.b_WindowHeight - (this.visibleTopHeight + this.bottomVisible);
this.changeInScroll             = this.amountOfScroll-this.lastAmountOfScroll;
this.currentCSSMargin           = removePX (this.scrollCSSObj.marginTop);

  // If scrollArea >= scrolledObject position object in vertical center.
	if (this.scrollAreaSize >= this.scrollDivHeight) {

	  // MidSize < scrollAreaSize .. but only if scrollArea > scrolledObject.
		if (this.scrollAreaSize > this.centerDivHeight) {
		this.scrollCSSObj.marginTop = "0px";
		return 0;
		}

	newCSSMargin = this.amountOfScroll + ((this.scrollAreaSize-this.scrollDivHeight)/2) - this.invisibleTopHeight;

	// Start the scroller at top and migrate towards middle.
  	this.scrollCSSObj.marginTop = newCSSMargin - Math.max(0,newCSSMargin-this.amountOfScroll) + "px";
	return 0;
	}

   // Scroll Area <  Object, must allow scrolled object scroll faster .. Other wise parts of it may become invisible.
   if (this.directionDown) {
	// This keeps scroll object at the top ..+
	newCSSMargin = Math.max(this.currentCSSMargin - this.changeToInvisibleTopHeight - this.changeInScroll,0);

    // Stick scroll object onto bottom of scroll window.
    toBottomOfWindow = this.amountOfScroll + this.b_WindowHeight;
    scrollObjectAtBottom =  this.topLength + newCSSMargin + this.scrollDivHeight;
    newCSSMargin += Math.max(toBottomOfWindow-scrollObjectAtBottom,0);

    //Never let it go to far ..
    maxLength = this.centerAndTopLength + this.amountOfScroll;
    calcLength = this.amountOfScroll + this.invisibleTopHeight + newCSSMargin + this.scrollDivHeight;
    calcDiff = Math.max(0,calcLength-maxLength);
    newCSSMargin = Math.min(newCSSMargin,newCSSMargin-calcDiff);

    this.scrollCSSObj.marginTop = newCSSMargin  + "px";

    } else {
    // Going Up !

     // ** can go wrong here because changing from scroll area fits on page (above) to not fits on page here ... Caused by change in topheader on page.
     //alert("op");
    // This retains the current position relative to the page, ie. top is hidden.
    newCSSMargin = Math.max(this.currentCSSMargin + this.changeToInvisibleTopHeight + this.changeInScroll,0);
    hiddenTop = this.amountOfScroll-newCSSMargin-(this.invisibleTopHeight);

    // Adjust to (gradually) hide bottom of page whilst scrolling back to zero ..
    newCSSMargin += Math.min(hiddenTop,-1*this.changeInScroll);  // This adjustment is sometimes negative when scroll area size changes    ..

    this.scrollCSSObj.marginTop = newCSSMargin + "px";
   }

};

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}
 

function positionSideBar (posId,heightID) {
  scrollObj = new initScroller(posId,heightID);
  scrollObj.xScrollTo();
  setInterval("scrollObj.xScrollTo()",scrollTimer);
}


// *******************************************************************
// Author: ChrisColeman (on a stand alone computer)  Date: 24/10/2004 17:45:47
// Input:
// Output:
// Description: Sniffer Object & Methods.
//              Browser sniffer. Written by PerlScriptsJavaScripts.com
//              Copyright http://www.perlscriptsjavascripts.com
//              Free and commercial Perl and JavaScripts
//              Modified by HerefordComputers to include element-id methods.
// *******************************************************************
function Sniffer(){
this.nav = navigator.appName.toLowerCase();
this.version = navigator.appVersion.toLowerCase();

this.getmethod;

 if (document.images){
   if(navigator.userAgent.indexOf("Opera") != -1) {
   this.getmethod = 'unknown';
   } else {
     if (navigator.userAgent.indexOf("AOL") != -1) {
     this.getmethod = 'unknown';
     } else {
       if (document.getElementById) {this.getmethod = 'getElementById';
       } else {
         if (document.all) {this.getmethod = 'DocumentAll';
         } else {
           if (document.layers) {this.getmethod = 'DocumentLayer';
           } else {
           this.getmethod = false;
           }
         }
       }
     }
   }
 } else {
 this.getmethod = false;
 }

  if (navigator.userAgent.indexOf("Mac") != -1) {
  this.getmethod = 'unknown';
  }

this.HTMLPath = HTMLPath;
this.CSSPath = CSSPath;

}
//return the css layer object depending on which browser is looking at the page.
// Tested with ie6, Mozilla, Netscape 7.2, Firefox -- All use getelementbyid(cssid).style
function CSSPath(cssid){

var csspath;

  switch(this.getmethod) {
    case(this.getmethod = 'getElementById'):
    return document.getElementById(cssid).style;
    break;
    case(this.getmethod = 'DocumentAll'):
    return document.all[cssid].style;
    break;
    case(this.getmethod = 'DocumentLayer'):
    return document.layers[cssid];
    break;
    default:
    return false;
    break;
  };

return csspath;
}

//return the css layer object depending on which browser is looking at the page.
// Tested with ie6, Mozilla, Netscape 7.2, Firefox -- All use getelementbyid(cssid).style
function HTMLPath(htmlid){

  switch(this.getmethod) {
    case(this.getmethod = 'getElementById'):
    return document.getElementById(htmlid);
    break;
    case(this.getmethod = 'DocumentAll'):
    return document.all[htmlid];
    break;
    case(this.getmethod = 'DocumentLayer'):
    return document.layers[htmlid];
    break;
    default:
    return false;
    break;
  };

}

// *******************************************************************
// Author: ChrisColeman (on a stand alone computer)  Date: 21/10/2004 16:23:14
// Description: Return dimensions of the display area.
// *******************************************************************
function AlertSize(WorH) {

var myWidth = 0, myHeight = 0;

  if( typeof( window.innerWidth ) == 'number' ) {
  // Non-IE
  myWidth = window.innerWidth;
  myHeight = window.innerHeight;
  } else
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } else
      if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
      }

  if(WorH=='H')
  {
  return myHeight;
  } else {
  return myWidth;
  }
}
