
/*

function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.' 
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 

*/

var speed=50 
 
var loop, timer 

function MoveArea(x,y){ 
    this.x=x;this.y=y 
    this.css.left=this.x 
    this.css.top=this.y 
    
    var newtop;
    var deltax;
    
    newtop = objThumb.maxy - ((objThumb.sizedoc  + this.y)  / objThumb.sizedoc )* objThumb.sizebar;
    objThumb.css.top= newtop;

    deltax = -0.001151052 * newtop * newtop + 0.361742128 * newtop + 5.181321941;
    
    newtop = newtop - objThumb.miny - (objThumb.maxy -objThumb.miny)/2 ;
    
    objThumb.css.left= deltax;
    
} 
 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 
 
function PerformScroll(speed){ 
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 
 
function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 

function CaptureScroll(e){

	dragActive = true

	if (!e) e = window.event
	
	objThumb.deltay= e.y - parseFloat(objThumb.css.top);
	
	//if (ns4) window.document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP)
	window.document.onmousemove = dragMove
	window.document.onmouseup = dragUp

}

function ReleaseScroll(){

	dragActive = false
	//if (ns4) window.document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP)
	
	window.document.onmousemove = null
	window.document.onmouseup = null

}

function dragMove(e){

if (!e) e = window.event

if (dragActive){
	var y;
    var newtop;
    var deltax;
	
	y = e.y - objThumb.deltay;
	
	if (y<objThumb.miny) y=objThumb.miny;
	if (y>objThumb.maxy) y=objThumb.maxy;

	objThumb.css.top=y;
	
	newtop = y;
    newtop = newtop - objThumb.miny - (objThumb.maxy -objThumb.miny)/2 ;
    deltax = -0.001151052 * y * y + 0.361742128 * y + 5.181321941;
    objThumb.css.left= deltax;

	y = - ((y - objThumb.maxy) / objThumb.sizebar) * objThumb.sizedoc - objThumb.sizedoc ; 
	
    objScroller.y=y; 
    objScroller.css.top=y;
    
    
	}

}

function dragUp(){
	ReleaseScroll();
}

var initialised; 
function InitialiseScrollableArea(){ 

    objUp = new ConstructObject('divUpControl')
    objDown = new ConstructObject('divDownControl')
    objThumb=new ConstructObject('divThumb')

    objContainer=new ConstructObject('divContainer') 
    objScroller=new ConstructObject('divContent','divContainer') 
    
    objScroller.up=MoveAreaUp; objScroller.down=MoveAreaDown; 
    objScroller.MoveArea=MoveArea; objScroller.x; objScroller.y; 

    objThumb.miny= parseFloat(objUp.css.top) + 14;
    objThumb.maxy= parseFloat(objDown.css.top) - 10;
    
    objThumb.upx = parseFloat(objUp.css.left);
    objThumb.downx = parseFloat(objDown.css.left);

    objThumb.sizedoc = objScroller.scrollHeight - objContainer.clipHeight;
    objThumb.sizebar = objThumb.maxy - objThumb.miny;

    if (objScroller.clipHeight- 50 > objThumb.sizebar)
    {
        objThumb.css.display='';
        objUp.css.display='';
        objDown.css.display='';
    };
    
    objThumb.clickactive = false;
    
    objScroller.MoveArea(0,0);
    objContainer.css.visibility='visible';
    initialised=true; 
} 
