/*
Copyright © Luehrix 2008, All Rights Reserved.
Site: http://www.luehrix.de
E-mail: mail@luehrix.de
Script: Div Scroller
Version: 1.0.0.1
*/

var reg = /Gecko/;
Mozilla = reg.exec(navigator.userAgent);
reg = /MSIE/;
MsIE = reg.exec(navigator.userAgent);
reg = /Opera/;
Opera= reg.exec(navigator.userAgent);


NS6 = Mozilla?Mozilla:Opera;
IE  = MsIE;
moving = null;
maxScroll = 3;
scrolling = 1;
direction = 1;
topValue  = 0;
loop      = false;
delay     = 100;
minTop    = 0;
maxLength = 0;
s         = null;
sc        = null;
bInit     = false;

function initSlider(doc, win, scroller, slInput) {
  sc = doc.getElementById(scroller);
  s = new Slider(sc, doc.getElementById(slInput), "vertical");
  
  win.onresize = function () {
	s.recalculate();
  };
}

function setSlider_onchange() {
  s.setMinimum(0);
  s.setMaximum(-1*minTop);
  s.setValue(s.getMaximum());
  s.onchange = function () {
    topValue = s.getValue();
    moveScrollbarTo(topValue+minTop);
  };
}

function initScroller() {
  if (NS6||IE) {	  
    container_=(NS6)?document.getElementById("divContainer"):document.all["divContainer"];		
    content_ =(NS6)?document.getElementById("divContent"):document.all["divContent"];
	scroller_=(NS6)?document.getElementById("divScrollbar"):document.all["divScrollbar"];
    topValue = parseInt(content_.offsetTop);
    maxLength= content_.offsetHeight;
	minTop   = Math.min(0, parseInt(container_.offsetHeight)-parseInt(content_.offsetHeight)-8);
    setSlider_onchange();
  }
}

function startDrag() {
  drag = true;
}

function moveScrollbarTo(pixels) {
  topValue = pixels;
  if (topValue<minTop) {
    topValue = minTop;
  }
  if (topValue>0) {
    topValue = 0;
  }
  content_.style.top = topValue+'px';
}

function stopDrag() {
  drag = false;
}

function scrollUp(delay_) {
  clearTimeout(moving);
  direction = 1;
  loop   = true;
  delay  = delay_;
  scrolling = 1;
  moving = setTimeout("scrollNow()", delay)
}

function scrollDown(delay_) {
    clearTimeout(moving);
    direction = -1;
    loop   = true;
    delay  = delay_;
    scrolling = 1;
    moving = setTimeout("scrollNow()", delay)
}

function scrollNow() {
  topValue = topValue + (scrolling * direction);
  if (topValue<minTop) {
    topValue = minTop;
    loop = false;
  }
  if (topValue>0) {
    topValue = 0;
    loop = false;
  }
  content_.style.top = topValue+'px';
  if (loop) {
    scrolling = Math.min(scrolling+1, maxScroll)
    moving = setTimeout("scrollNow()", delay);
  }
}

function stop() {
  loop = false;
  if (moving) clearTimeout(moving);
}

