/*
  var div_scroll1 = new TextScroll('div_scroll1', 'scroll_box1', 'scroll_up1', 'scroll_down1');
  var div_scroll2 = new TextScroll('div_scroll2', 'scroll_box2', 'scroll_up2', 'scroll_down2');

  var el1 = document.getElementById('scroll_box1');
  if(el1 != null ) el1.addEventListener('DOMMouseScroll',mousescroll1, false);
  var el2 = document.getElementById('scroll_box2');
  if(el2 != null) el2.addEventListener('DOMMouseScroll',mousescroll2, false);
*/
  function TextScroll(scrollname, div_name, up_name, down_name)
{
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 0;
    this.speed = 5;
    this.timeoutID = 0;
    this.div_obj = null;
    this.up_name = up_name;
    this.dn_name = down_name;

{
        if (document.getElementById) {
            div_obj = document.getElementById(this.div_name);
            if (div_obj) {
                this.div_obj = div_obj;
                this.div_obj.style.overflow = 'hidden';
                this.div_obj.onmousewheel = function() { eval(scrollname + ".scroll(event);") };
            }
            div_up_obj = document.getElementById(this.up_name);
            div_dn_obj = document.getElementById(this.dn_name);
            if (div_up_obj && div_dn_obj) {
                div_up_obj.onmousedown = function() { eval(scrollname + ".scrollUp();") };
                div_up_obj.onmouseup = function() { eval(scrollname + ".stopScroll();") };
                div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
                div_dn_obj.onmousedown = function() { eval(scrollname + ".scrollDown();") };
                div_dn_obj.onmouseup = function() { eval(scrollname + ".stopScroll();") };
                div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
                       
                

            }
        }
    }

this.stopScroll = function() {
        clearTimeout(this.timeoutID);
    }

this.scrollUp = function(a) {
        if (this.div_obj) {
            var spd = this.speed;
            if(a) spd *= 5;
            this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - spd;
            this.div_obj.scrollTop = this.scrollCursor;
            if(!a) this.timeoutID = setTimeout(this.name + ".scrollUp()", 10);
        }
    }
    
this.scrollDown = function(a) {
    if (this.div_obj) {
        var spd = this.speed;
        if(a) spd *= 5;
        this.scrollCursor += spd;
        this.div_obj.scrollTop = this.scrollCursor;
        if (this.div_obj.scrollTop == this.scrollCursor) {
            if(!a) this.timeoutID = setTimeout(this.name + ".scrollDown()", 10);
        } else {
            this.scrollCursor = this.div_obj.scrollTop;
        }
    }
}

this.resetScroll = function() {
        if (this.div_obj) {
            this.div_obj.scrollTop = 0;
            this.scrollCursor = 0;
        }
    }
this.scroll = function(event){
        var delta = 0;
        if (event == null) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta){
            if(delta > 0) this.scrollUp(true);
            else if(delta < 0) this.scrollDown(true);
        }

}
}

function mousescroll1(event){
    div_scroll1.scroll(event);
}
function mousescroll2(event){
    div_scroll2.scroll(event);
}

