function Scroller(){}
SC=Scroller.prototype
SC.init=function(id,id2){
        this.s=document.getElementById(id);
        this.cc=document.getElementById(id2);
        this.dr=document.getElementById('dragBar');
        this.dr.onmousedown=this.pd
        this.tr=document.getElementById('track');
        var dbarSize=this.s.offsetHeight/this.cc.offsetHeight*this.tr.offsetHeight
        this.dr.style.height=dbarSize>this.tr.offsetHeight-2?this.tr.offsetHeight-2:dbarSize
        this.barY=0
        this.y=0
        this.t=50
        this.accel=0
        this.maxY=this.cc.offsetHeight-this.s.offsetHeight
        this.koef=(this.tr.offsetHeight-2-parseInt(this.dr.style.height))/this.maxY
}
SC.shiftTo=function(){this.cc.style.top=this.y+"px"}
SC.run=function(dir){
        if(this.running)return
        this.d=dir
        this.running=1
        SC.scroll()
}
SC.scroll=function() {
        var ny=this.y+this.d
        if(this.maxY+ny<=0)ny=-this.maxY
        if(ny>0)ny=0
        if(!this.running)return
        this.y=ny
        this.shiftTo()
        this.timId=setTimeout("SC.scroll()",this.t)
        if(this.t>10&&this.accel==1)this.t-=500
        if(this.t<50&&this.accel==-1)this.t+=500
        this.updSrollBar()
}

SC.stop=function() {
        this.running=0
        clearInterval(this.timId)
        this.timId=0
        this.t=10
        this.accel=0
}

SC.updSrollBar=function(){
        this.barY=this.dr.style.top=-this.koef*this.y
}
SC.pd=function(e){
        //dw_event.add(document,"mousemove",SC.dragBar,true)
        dw_event.add(document,"mouseup",SC.pu,true)
        e=e?e:event
//window.event.cancelBubble = true;
    SC.BstartY = parseInt(e.clientY)-SC.barY
}
SC.pu=function(){
        //dw_event.remove(document,"mousemove",SC.dragBar,true)
    dw_event.remove(document,"mouseup",SC.pu,true)
}
SC.dragBar=function(e){
        e=e?e:event
        if(document.selection)document.selection.empty()
        //var r=document.body.createTextRange()
        //r.execCommand("Unselect",false)
        var ny=-Math.round((e.clientY-SC.BstartY)/SC.koef)
        if(SC.maxY+ny<=0)ny=-SC.maxY
        if(ny>0)ny=0
        SC.y=ny
        SC.updSrollBar()
        SC.shiftTo()
//window.status=SC.y+' '+SC.koef+' '+SC.maxY
}
var dw_event={
        add:function(obj,etype,fp,cap){
                cap=cap||false
                if(obj.addEventListener)obj.addEventListener(etype,fp,cap)
                else if(obj.attachEvent)obj.attachEvent("on"+etype,fp)
        },
        remove:function(obj,etype,fp,cap){
                cap=cap||false
                if(obj.removeEventListener)obj.removeEventListener(etype,fp,cap)
                else if(obj.detachEvent)obj.detachEvent("on"+etype,fp)
        }
}