/* Prototype JavaScript framework, version 1.5.1_rc2 required
 * @author lei.wang@nunet.de
 * @since 10.04.2007
 * @release 0.0.1
 */

var Scrollbar = Class.create();
Scrollbar.prototype = {
	initialize: function (dragButton,contentScreen,scrolledContent,scrollHeight){
		this.dragButton=$(dragButton);	
		this.scrolledContent=$(scrolledContent);
		this.contentScreen=$(contentScreen);
		this.dragT=this.dragButton.offsetTop;		
		this.dragH=this.dragButton.getHeight();
		this.scrollH=scrollHeight;
		this.contentH=this.scrolledContent.getHeight()+40;
		this.contentClipH=this.contentScreen.getHeight();
		this.scrollLength = (this.contentH-this.contentClipH)/this.scrollH;		
		if(this.contentH > this.contentClipH){
			this.scrolledObj=new Draggable(dragButton,{constraint:'vertical',snap: this.move.bind(this)});
		}else{
			this.dragButton.style.display="none";
		}				
		
	},
	
	move: function (x,y,draggable){		
		
		if(y<=this.dragT){
			this.moveTo(this.dragT);
			return[x,this.dragT];
		}else if(y>=this.scrollH){
			this.moveTo(this.scrollH);
			return[x,this.scrollH];
		}
		this.moveTo(y);		
		return [x,y];
		
	},
	
	moveTo:function(y){		
		contentT =(this.dragT-y)*this.scrollLength;
		this.scrolledContent.style.top=contentT +"px";			
		
		
	}
	
	
	
}


function windowLoader(){
		
	var sc=new Scrollbar('dragmitte','mitte','contentMitte',340);
	var sc1=new Scrollbar('draglinks','links','contentLinks',340);
	var sc2=new Scrollbar('dragrechts','rechts','contentRechts',340);
		
}
