var sHTML=new String('<DIV ID="scrDivs">');
    sHTML+='<IMG SRC="scrup.gif" ID="scrUp" WIDTH="15" HEIGHT="15" onmousedown="bMouseIsUp=false;scrollUp()">';
    sHTML+='<IMG SRC="scrdn.gif" ID="scrDn" WIDTH="15" HEIGHT="15" onmousedown="bMouseIsUp=false;scrollDown()">';
    sHTML+='<DIV ID="scrollBar" onmousedown="grab()"><IMG HEIGHT="1"></DIV>';
    sHTML+='<DIV ID="scrollBack" onclick="largeScroll()"></DIV></DIV>';
document.writeln(sHTML);

var iArwHeight=scrUp.offsetHeight;
var iArwWidth=scrUp.offsetWidth;
var iScrHeight=sDiv.offsetHeight;

var iSBarDist;
var iSDivDist;
var fSBarRatio;
var fScrRatio;

var iCurY=0; 
var iNewY;
var iDistY;
var iHighY=null
var iLowY=null
var oSBar=null;
var bMouseIsUp=true;

var x=0;
var y=15;
var e=sDiv;

while (e.tagName!="BODY"){
    x=x+e.offsetLeft-e.clientLeft;
    y=y+e.offsetTop-e.clientTop;
    e=e.offsetParent;
    }
    
var iPosX=x+sDiv.offsetWidth-1; 
var iPosY=y+1;

scrUp.style.pixelTop=iPosY;
scrUp.style.pixelLeft=iPosX;
scrDn.style.pixelTop=iPosY+iScrHeight-iArwHeight+1;
scrDn.style.pixelLeft=iPosX;
scrollBack.style.pixelLeft=iPosX;
scrollBack.style.pixelTop=iPosY+iArwHeight;
scrollBack.style.pixelHeight=iScrHeight-(iArwHeight*2); 
scrollBack.style.pixelWidth=iArwWidth-1;//barback width*******************

scrollBar.style.backgroundColor=sBarColor;
scrUp.style.backgroundColor=arwColor;
scrDn.style.backgroundColor=arwColor;
sDiv.style.borderColor=sDivBorder;
scrollBar.style.borderColor=sBarColdBorder;
scrollBack.style.backgroundColor=sBack;
scrollBack.style.borderColor=sBackBorder;

var ss=scrollBar.style;

function refreshScr(){
    fSBarRatio=(sDiv.offsetHeight/sDiv.scrollHeight);//barheight - to make smaller deduct 0.2 off this value********
    if (fSBarRatio>=1) scrDivs.style.display="none";
    else {
        scrDivs.style.display="";
        iScrHeight=sDiv.offsetHeight;
        scrollBar.style.pixelLeft=iPosX;//scrollbar offset**************************
        scrollBar.style.pixelTop=iPosY+iArwHeight;
        scrollBar.style.pixelHeight=scrollBack.offsetHeight*fSBarRatio;
        scrollBar.style.pixelWidth=iArwWidth-2;//scrollbar width*****************************
        iSBarDist=scrollBack.offsetHeight-scrollBar.offsetHeight;
        iSDivDist=sDiv.scrollHeight-sDiv.offsetHeight;
        fScrRatio=iSBarDist/iSDivDist;
        }
    }

function largeScroll(){
    if (event.clientY>scrollBar.style.pixelTop)
        sDiv.scrollTop+=(iScrHeight-14);
    else sDiv.scrollTop+=0-(iScrHeight-14); 
    }

function scrollDown(){
    if (bMouseIsUp) return;
    sDiv.scrollTop+=10;
    setTimeout("scrollDown()",20);
    }

function scrollUp(){
    if (bMouseIsUp) return;
    sDiv.scrollTop+=-10;
    setTimeout("scrollUp()",20);
    }

function grab(){ 
    oSBar=event.srcElement;
    iCurY=event.clientY; 
    oSBar.style.borderColor=sBarHotBorder; 
    bMouseIsUp=false;
    }

function move(){
    if (!oSBar) return; 
    if (((!iHighY)
            ||(iHighY<=event.clientY))
        &&((!iLowY)
            ||(iLowY>=event.clientY))){
        iHighY=null;
        iLowY=null;
        oSBar.style.borderColor=sBarHotBorder;
        iNewY=event.clientY;
        iDistY=iNewY-iCurY;
        iCurY=iNewY;
        if ((oSBar.offsetTop+iDistY)<iPosY+iArwHeight){
            oSBar.style.pixelTop=iPosY+iArwHeight; 
            sDiv.scrollTop=0;
            iHighY=iNewY;
            }
        else if ((oSBar.style.pixelTop+oSBar.offsetHeight+iDistY)>scrDn.offsetTop){ 
            oSBar.style.pixelTop=(scrDn.offsetTop-oSBar.offsetHeight); 
            sDiv.scrollTop=((scrollBar.style.pixelTop-(iArwHeight+iPosY))/fScrRatio);
            iLowY=iNewY;
            }
        else {
            oSBar.style.pixelTop+=iDistY;
            sDiv.scrollTop=((oSBar.offsetTop-(iArwHeight+iPosY))/fScrRatio);
            }
        }
    }

function drop(){
    scrollBar.style.borderColor=sBarColdBorder;
    oSBar=null;
    iHighY=null;
    iLowY=null;
    bMouseIsUp=true;
    }

function killEvent(){ 
    return false;
    }

function synch(){
    if (!oSBar) scrollBar.style.pixelTop=(sDiv.scrollTop*fScrRatio)+iArwHeight+iPosY;
    }

document.onmousemove=move;
document.onmouseup=drop;
sDiv.onscroll=synch;
scrollBar.onselectstart=killEvent;
refreshScr();


