var ns4 = ( document.layers ) ? 1 : 0;
var ns6 = ( document.getElementById ) ? 1 : 0;
var ie4 = ( document.all ) ? 1 : 0;

var d = document;
var over = false;
var moving = false;
var mPos;

var origY = 390, y = origY;
var w = 245;
var origH = 125, h = origH;
var aH = origH;
var b = 0;
var z = 100;
var tCrop = 0;
var bCrop = 124;
var origThumbPos = 405, thumbPos = origThumbPos;
var travel = 98;
var speed = 12;
var ratio;

function initScroll( direction ) {
  document.onmouseup = function() { over = false; document.onmouseup = null; }
  var s = speed;
  if( direction == "u" && tCrop > 0 ) {
    tCrop -= s; bCrop -= s; y += s; h -= s; thumbPos -= ratio; aH = h;
  } else if( direction == "d" && bCrop < b ) {
    tCrop += s; bCrop += s; y -= s; h += s; thumbPos += ratio; aH = h + s;
  }
   if( over ) {
    startScroll();
    setTimeout( "initScroll( '" + direction + "' )", 50 );
  }
}

function startScroll() {
  setH( 'NewsContent', aH );
  setY( 'NewsContent', y );
  setC( 'NewsContent', tCrop, w, bCrop, 0 );
  setY(  'thumb', thumbPos );
}

function initThumb() {
  moving = true;
  document.onmousemove = moveThumb;
  document.onmouseup = stopThumb;
}

function moveThumb( e ) {
  if( !moving ) return false;
  mPos = getMouseY( e );
  if( mPos <= origThumbPos ) {
    mPos = origThumbPos;
  } else if( mPos >= ( origThumbPos + travel ) ) {
    mPos = origThumbPos + travel;
  }
  setY( 'thumb',  mPos );
  syncText();
  return false;
}

function stopThumb() {
  syncText();
  moving = false;
  document.onmousemove = null;
  document.onmouseup = null;
}

function syncText() {
  var sync =  Math.round( ( mPos - origThumbPos ) / ratio ) * speed;
  tCrop = sync;
  bCrop = origH + sync;
  y = origY - sync;
  h = origH + sync;
  thumbPos = mPos;
  aH = origH + ( sync + speed );
  startScroll();
}

function initScroller() {
  getB();
  ratio = Math.ceil( (b-h)/speed );
  ratio = travel/ratio;
  setH( 'NewsContent', h );
  if( ns4 ) document.captureEvents( Event.MOUSEMOVE | Event.MOUSEUP );
}

function getB() {
  var obj = getE( 'NewsContent' );
  if( ns4 ) b =  obj.document.height;
    else if( ie4 ) b =  obj.scrollHeight;
    else if( ns6 ) b =  obj.offsetHeight;
}

function getMouseY( e ) {
  if( ie4 ) return event.clientY;
    else return e.pageY;
}