﻿function TextScroll(scrollname, div_name, up_name, down_name) {
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursorOver = 0;
    this.mouseover_speed = 20;
    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';
            }
            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_MouseOver();") };
                div_up_obj.onmouseup = function() { eval(scrollname + ".stopScroll();") };
                //div_up_obj.onmousemove = function() { eval(scrollname + ".stopScroll();") };
                div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };

                div_dn_obj.onmousedown = function() { eval(scrollname + ".scrollDown_MouseOver();") };
                div_dn_obj.onmouseup = function() { eval(scrollname + ".stopScroll();") };
                //div_dn_obj.onmousemove = function() { eval(scrollname + ".stopScroll();") };
                div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
            }
        }
    }

    this.stopScroll = function() {
        //alert('stopScroll');
        clearTimeout(this.timeoutID);
    }

    this.scrollUp_MouseOver = function() {
        if (this.div_obj) {
            this.scrollCursorOver = (this.scrollCursorOver - this.mouseover_speed) < 0 ? 0 : this.scrollCursorOver - this.mouseover_speed;
            this.div_obj.scrollTop = this.scrollCursorOver;
            this.timeoutID = setTimeout(this.name + ".scrollUp_MouseOver()", 60);
        }
    }

    this.scrollDown_MouseOver = function() {
        if (this.div_obj) {
            this.scrollCursorOver += this.mouseover_speed;
            this.div_obj.scrollTop = this.scrollCursorOver;
            this.timeoutID = setTimeout(this.name + ".scrollDown_MouseOver()", 60);
        }
    }

    //this.resetScroll = function() {
    //    alert('reset');
    //    if (this.div_obj) {
    //        this.div_obj.scrollTop = 0;
    //        this.scrollCursorOver = 0;
    //    }
    //}
}