var scroll_time = 1;
var scroll_step = 5;
var scrollInterval;

function initScroller(scr_id, up_id, down_id)
{
    scr_w = document.getElementById(scr_id);
    scr_b = document.getElementById(up_id).parentNode;
    scr_b2 = document.getElementById(down_id).parentNode;
    document.getElementById(up_id).onmousedown =  function() { 
                              document.getElementById(up_id).className += ' active_up';
                              startScroll(scr_id, "up"); 
                          }
    document.getElementById(up_id).onmouseup =  function() { 
                            document.getElementById(up_id).className = document.getElementById(up_id).className.replace(new RegExp(' active_up'), ''); 
                            endScroll(); 
                        };
    document.getElementById(up_id).onmouseout = function() { 
                            document.getElementById(up_id).className = document.getElementById(up_id).className.replace(new RegExp(' active_up'), ''); 
                            endScroll(); 
                        };
    document.getElementById(up_id).onclick = function() { return false; };
    document.getElementById(down_id).onmousedown =  function() { 
                                document.getElementById(down_id).className += ' active_down';
                                startScroll(scr_id, "down"); 
                            }
    document.getElementById(down_id).onmouseup =  function() { 
                              document.getElementById(down_id).className = document.getElementById(down_id).className.replace(new RegExp(' active_down'), ''); 
                              endScroll(); 
                          };
    document.getElementById(down_id).onmouseout = function() { 
                              document.getElementById(down_id).className = document.getElementById(down_id).className.replace(new RegExp(' active_down'), ''); 
                              endScroll(); 
                          };
    document.getElementById(down_id).onclick = function() { return false; };
    if (scr_w.scrollHeight <= scr_w.clientHeight) {
        scr_b.style.display = 'none';
        scr_b2.style.display = 'none';
        scr_w.scrollTop = 0;
    } else {
        scr_b.style.display = '';
        scr_b2.style.display = '';
    }
    
}

function startScroll(id, dir) {
    scrollInterval = setInterval('scroll("' + id + '", "' + dir + '")', scroll_time);
}
function endScroll() {
    try {
        clearInterval(scrollInterval);
    } catch(e) {}
}
function scroll(id, dir)
{
    D = document.getElementById(id);
    dir_num = (dir == 'up' ? -1 : (dir == 'down' ? 1 : 0)) * scroll_step;
    D.scrollTop += dir_num;
    if (D.scrollTop <= 0 || D.scrollTop + D.height >= D.scrollHeight) {
        clearInterval(scrollInterval);
    }
}

