var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;

function addEvent (event,method) {
  this[event] = method;
  if (ns4) this.captureEvents (Event[event.substr (2,event.length).toUpperCase ()]);
}

function removeEvent (event) {
  this[event] = null;
  if(ns4) this.releaseEvents (Event[event.substr (2,event.length).toUpperCase ()]);
}

function getElement (name, nest) {
  nest = nest ? 'document.'+nest+'.' : '';
  var el = dom ? document.getElementById (name) : iex ? document.all[name] : ns4 ? eval (nest+'document.'+name) : false;
  el.css = ns4 ? el : el.style;
  el.getTop = function () {return parseInt (el.css.top) || 0};
  el.setTop = function (y) {el.css.top = y};
  el.getHeight = function () {return ns4 ? el.document.height : el.offsetHeight};
  el.getClipHeight = function () {return ns4 ? el.clip.height : el.offsetHeight};
  el.addEvent = addEvent;
  el.removeEvent = removeEvent;
  return el;
}

function getMouse (e) {
  return iex ? event.clientY : e.pageY;
}

document.addEvent = addEvent;
document.removeEvent = removeEvent;

function fixNetscapeCSS () {
  if (ns4origWidth != window.innerWidth || ns4origHeight != window.innerHeight) window.location.reload ();
}
if (document.layers) {
  ns4origWidth = window.innerWidth;
  ns4origHeight = window.innerHeight;
  window.onresize = fixNetscapeCSS;
}

function initScroller () {
	scrollSpeed = 6; // scrolling speed
	dragHeight = 20; // Height of scrollbar drag
	trackHeight = 78; // Height of scrollbar track
	upObj = getElement ('up'); // Reference to the up arrow div
	downObj = getElement ('down'); // Reference to the down arrow div
	contentMaskObj = getElement ('contentMask'); // Reference to the content mask div
	contentObj = getElement ('content','contentMask'); // Reference to the content div
	trackLength = trackHeight - dragHeight; // Adjusted track height
	contentMaskHeight = contentMaskObj.getClipHeight ();// Height of the div that masks the content div
	contentHeight = contentObj.getHeight (); // Height of the content div
	contentLength = contentHeight - contentMaskHeight; // Adjusted content height
	scrollLength = trackLength / contentLength ; // Height difference between the scrollbar track and the content
	scrollTimer = null;
	
	if(contentLength -10 <= 0){
		upObj.style.display = 'none';
		downObj.style.display = 'none';
	}
	
	
	upObj.addEvent ('onmousedown', function () {scroll (scrollSpeed); return false});
	upObj.addEvent ('onmouseup', stopScroll);
	upObj.addEvent ('onmouseout', stopScroll);
	
	downObj.addEvent ('onmousedown', function () {scroll (-scrollSpeed); return false });
	downObj.addEvent ('onmouseup', stopScroll);
	downObj.addEvent ('onmouseout', stopScroll);
}
function scroll(speed) {
  var contentMovement = contentObj.getTop() + speed;
  if (contentMovement > 0) {
    contentMovement = 0;
  } else if (contentMovement < -contentLength) {
    contentMovement = -contentLength;
  }
  contentObj.setTop (contentMovement);
  scrollTimer = window.setTimeout ('scroll ('+speed+')',25);
}
function stopScroll () {
  if (scrollTimer) {
    window.clearTimeout (scrollTimer);
    scrollTimer = null;
  }
}
