//version 0.0, am scrollboxheight061219


var clipTop = 0;
var clipWidth = 540;
var clipBottom = 255;
var distfromtop = 20;     //distfromtop = -clipTop;

var contentheight = 0;
var time,stepsize,theTime,theHeight,DHTML,wkfrac,wkfrac2;

var scrolllength = clipBottom - 40;
var scrollboxheight = 20;

function initcliparea(){
        DHTML = (document.getElementById || document.all || document.layers);
        if (!DHTML) return;
        var objcliparea = new getObj('cliparea');
        var objscrollbox = new getObj('scrollbox');
        if (document.getElementById || document.all)        {
                contentheight = objcliparea.obj.offsetHeight;
                objcliparea.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
                wkfrac = (clipBottom)  / (contentheight)
                if (wkfrac * clipBottom < clipBottom){
                        objscrollbox.style.height = wkfrac * (clipBottom - scrollboxheight);
                        wkfrac = wkfrac * scrolllength/clipbottom;
                } else {
                 objscrollbox.style.height = clipBottom - scrollboxheight;
                      //objscrollbox.obj.offsetHeight = clipBottom - 28;   auskommentiert am scrollboxheight061219, verursacht Error: setting a propterty tha has only a getter
                }
        }
        //alert (wkfrac);
}
function scrollayer(layername,amt,tim){
        if (!DHTML) return;
        thelayer = new getObj(layername); //thelayer = cliparea
        if (!thelayer) return;
        stepsize = amt;
        theTime = tim;
        realscroll();
}
function realscroll(){
        if (!DHTML) return;
        var wkoffset;
        corrflag = false;
        wkmodlayerstepsize = parseInt(thelayer.obj.offsetHeight);
        wkmodlayerstepsize = wkmodlayerstepsize%stepsize;
        window.status = wkmodlayerstepsize;
        wkoffset = clipTop%stepsize;
        if (wkoffset!=0){
                if (stepsize>0){
                        realamount = stepsize - wkoffset;
                } else {
                        realamount = - wkoffset;
                }
        } else {
                realamount = stepsize;
        }
        if(clipBottom + wkmodlayerstepsize + 10 > contentheight && stepsize>0){
                realamount = wkmodlayerstepsize;
                corrflag = true;
        }
        clipTop += realamount;
        clipBottom += realamount;
        distfromtop -= realamount;
        if (clipTop < 0 || clipBottom > contentheight)        {
                clipTop -= realamount;
                clipBottom -= realamount;
                distfromtop += realamount;
        }
        var objscrollbox = new getObj('scrollbox');
        if (document.getElementById || document.all)        {
                clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
                thelayer.style.clip = clipstring;
                thelayer.style.top = distfromtop + 'px';
                if (corrflag!=true){
                        objscrollbox.style.top = Math.round(scrollboxheight - wkfrac  * distfromtop) +'px';
                } else {
                        objscrollbox.style.top = scrollength - objscrollbox.obj.offsetHeight +'px';
                }
        }
        time = setTimeout('realscroll()',theTime);
}


function stopscroll(){
        if (time) clearTimeout(time);
}

//drag scrollbar----------------------------------------------

var ddEnabled=false;
var objekt;

function startdrag(e) {
        if(!document.all) {
                objekt=e.target.id;
        } else {
                objekt=event.srcElement.id;
        }
        if(objekt) {
                if(!document.all) {
                        event=e;
                }
                startY=event.clientY;
                YpositionAlt=document.getElementById(objekt).style.top;
                ddEnabled=true;
                document.onmousemove=realdrag;
        }
}

function realdrag(e) {
        if (ddEnabled){
                if(objekt="scrollbox") {
                        if(!document.all) {
                                event=e;
                        }
                        Ywert=event.clientY-startY;
                        if (Ywert > 0){
                                        document.getElementById(objekt).style.top = parseInt(YpositionAlt)+Ywert;
                                        if (parseInt(document.getElementById(objekt).style.top)+ parseInt(document.getElementById(objekt).style.height)>280){
                                                document.getElementById(objekt).style.top =scrolllength - parseInt(document.getElementById(objekt).style.height) ;
                                        }
                        } else {
                                        document.getElementById(objekt).style.top = parseInt(YpositionAlt)+Ywert;
                                        if (parseInt(document.getElementById(objekt).style.top)<scrollboxheight){
                                                document.getElementById(objekt).style.top = scrollboxheight;
                                        }
                        }
                        wkstepsize = (scrollboxheight - parseInt(document.getElementById(objekt).style.top))/wkfrac;
                        window.status = wkstepsize;
                        realdragdriven('cliparea',wkstepsize);
                }
        }
        return false;
}
function realdragdriven(layername,amt){
        if (!DHTML) return;
        thelayer = new getObj(layername); //thelayer = cliparea
        if (!thelayer) return;
        stepsize = amt;
        clipTop = -stepsize;
        clipBottom = clipTop+clipBottom;
        distfromtop = stepsize;
        if (document.getElementById || document.all)        {
                clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
                thelayer.style.clip = clipstring;
                thelayer.style.top = distfromtop + 'px';
        }
}
function stopdrag(){
        ddEnabled=false;
}
//bibliothek----------------------------------------------------
function getObj(name)
{
  if (document.getElementById)
  {
    this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
    this.obj = document.all[name];
        this.style = document.all[name].style;
  }
  else if (document.layers)
  {
           this.obj = document.layers[name];
           this.style = document.layers[name];
  }
}
document.onmousedown=startdrag;
document.onmouseover=startdrag;
document.onmouseup=stopdrag;
document.onmouseout=stopdrag

function showpopup(){
        document.all.popup1.style.visibility="visible";
}
function hidepopup(){
        document.all.popup1.style.visibility="hidden";
}
