{
	p = wrapLayer.prototype
	p.createScroll = createScroll
	p.startContinousScroll = startContinousScroll
	p.buttonScroll = buttonScroll
	p.scrollButton = scrollButton
	p.calibrate = calibrate
	p.scroll = scroll
	p.bar_mouseDown_all = bar_mouseDown_all
	p.reset = reset
	p.scrollVis = scrollVis
	p.scrollToClick = scrollToClick
	p.mouseMoveScroll		= mouseMoveScroll
	p.stopContinousScroll	= stopContinousScroll
	p.scrollOnClick = true
	p.autoVis	= true
	p.scrollSpeed	= 3
}

function createScroll(bRelative,oNest,bPosition,bCompMode) {
	if (bCompMode && (oClient.opera || (oClient.ie4 && oClient.mac))){
		alert("browser cannot run in backwards compability mode")
		return false
	}
	if (oClient.ns6up){	this.layer.style.position = "absolute" }
	this.eventID = this.id
	this.compMode = bCompMode
	this.clipper = (bRelative)?new wrapLayer(this.id+"Clip",this.obj+".clipper",this):this;
	this.content = (!bCompMode)?new wrapLayer(this.id+"Content",this.obj+".content",this.clipper):this;
	this.barNest = (!bCompMode)?this.clipper:oNest;
	this.clipHeight = this.clipper.getClip("height")
	this.scrollBar 	= new wrapLayer(this.id+"Bar",this.obj+".scrollBar",this.barNest)
	this.scrollArr  = new wrapLayer(this.id+"Arrow",this.obj+".scrollArrow",this.barNest)
	this.up 		= new wrapLayer(this.id+"Up",this.obj+".up",this.barNest)
	this.down 		= new wrapLayer(this.id+"Down",this.obj+".down",this.barNest)
	this.bg		 	= new wrapLayer(this.id+"Bg",this.obj+".bg",this.barNest)
	if (bPosition){
		var setX = this.content.xpos+this.content.getClip("width")
		this.up.setLayerPixel(setX,this.content.ypos)
		this.bg.setLayerPixel(setX,this.up.ypos+this.up.h)
		this.scrollBar.setLayerPixel(setX,this.up.ypos+this.up.h)
		this.scrollBar.setLayerPixel(setX,this.up.ypos+this.up.h)	
		this.scrollArr.setLayerPixel(setX,this.up.ypos+this.up.h)
		this.scrollArr.setLayerPixel(setX,this.up.ypos+this.up.h)	
		this.down.setLayerPixel(setX,this.bg.ypos+this.bg.h)	
	}
	this.ORIGypos = this.ypos 
	this.scrollBar.ORIGypos = this.scrollBar.ypos
	this.scrollArr.ORIGypos = this.scrollArr.ypos	
	this.up.scrollButton(this,0)
	this.down.scrollButton(this,1)
	if (oClient.ns4) this.scrollBar.addCover()
	fn = new Function("e","e = e || event;"+this.obj+".bar_mouseDown_all(e,\"v\");return false;")
	fn2 = new Function("e","e = e || event;"+this.obj+".mouseMoveScroll(e,\"v\");return false;")
	fn3 = new Function("e","e = e || event;"+this.obj+".stopContinousScroll(e,\"v\");return false;")
	this.scrollBar.addEvent("onmousedown",fn)
	if (!oClient.ie4up && !oClient.ns6up && !oClient.op5up) this.scrollBar.addEvent("onmousemove",fn2)			
	if (!oClient.ie4up && !oClient.ns6up && !oClient.op5) this.scrollBar.addEvent("onmouseup",fn3)	 // not for ie6	
	if (oClient.ie4up || oClient.ns6up || oClient.op5up || oClient.ns4) GlobalEvent(this.eventID+"mouseMoveScroll",0,"onmousemove",fn2)	
	if (oClient.ie4up || oClient.ns6up || oClient.op5up || oClient.ns4) GlobalEvent(this.eventID+"mouseUp",0,"onmouseup",fn3)
	if (oClient.ie5 && oClient.win) GlobalEvent(this.eventID+"moveAutoFalse",0,"onmousemove",new Function("return false"))	 // neeeded for ie5
	if (oClient.op5up) GlobalEvent(this.eventID+"moveAutoFalse",1,"onmousemove",new Function("event.preventDefault();event.stopPropagation();return false"))	 // neeeded for op?
	if (oClient.op5up) GlobalEvent(this.eventID+"moveDownFalse",1,"onmousedown",new Function("self.focus();event.preventDefault();event.stopPropagation();return false"))	 // neeeded for op?		
	if (this.scrollOnClick){
		if (oClient.ns4) this.bg.addCover()
		fn2 = new Function("e","e = e || event;"+this.obj+".scrollToClick(e);")
		this.bg.addEvent("onclick",fn2)
	}
	this.calibrate()
}

function scrollButton(scrollTarget,direction) {
	this.eventID = scrollTarget.id
	this.scrollTarget = scrollTarget
	this.scrollBar = scrollTarget.scrollBar
	this.direction = direction
	if (oClient.ns4) this.addCover()
	var fn = new Function("e","e = e || event;"+this.obj+".startContinousScroll(e);return false")
	var fn3 = new Function("e","e = e || event;"+scrollTarget.obj+".stopContinousScroll(e);return false;")	
	this.addEvent("onmousedown",fn)
	if (!oClient.ie4up && !oClient.ns6up && !oClient.op5) this.addEvent("onmouseup",fn3) //ie uses global
	if (oClient.ie4up) this.addEvent("onmousemove",new Function("return false"))//for all ie		
}

function startContinousScroll(e){
	GlobalEvent(this.eventID+"abortSelect",1)
	GlobalEvent(this.eventID+"moveAutoFalse",1)
	GlobalEvent(this.eventID+"mouseUp",1)
	clipModScrollBar = this.scrollTarget.scrollSpeed/this.scrollTarget.scrollRatio
	clipModScrollBar = (this.direction==1)?clipModScrollBar:0-clipModScrollBar;
	if (!oClient.op5) this.scrollTarget.rupert = setInterval(this.scrollTarget.obj+".buttonScroll("+clipModScrollBar+","+this.direction+")",10)
	else if (oClient.op5) this.scrollTarget.rupert = setTimeout(this.scrollTarget.obj+".buttonScroll("+clipModScrollBar+","+this.direction+")",10) //opera 5 has issues with setinterval...	
	if (oClient.ns5up) e.preventDefault()
	return false
}

function stopContinousScroll(){
	GlobalEvent(this.eventID+"mouseMoveScroll",0)
	GlobalEvent(this.eventID+"mouseUp",0)
	GlobalEvent(this.eventID+"moveAutoFalse",0)
	GlobalEvent(this.eventID+"abortSelect",0) 
	if (this.rupert){ 
		clearInterval(this.rupert)
		this.rupert=null
	}
	this.scrolling = false
	return false
}

function bar_mouseDown_all(e,strScrollDirection) {
		GlobalEvent(this.eventID+"mouseUp",1)
		GlobalEvent(this.eventID+"mouseMoveScroll",1)
		GlobalEvent(this.eventID+"abortSelect",1) 
		GlobalEvent(this.eventID+"moveAutoFalse",1)
		mouseX = (oClient.ns4up)?e.pageX:event.clientX;
   		mouseY = (oClient.ns4up)?e.pageY:event.clientY;
		this.scrollTarget = this
		this.scrollDirection = strScrollDirection
		if (strScrollDirection == "v") {
			this.mouseInLayerX = mouseX-this.scrollBar.xpos
			this.mouseInLayerY = mouseY-this.scrollBar.ypos
		}
		this.scrolling = true
		if (oClient.ns5up) e.preventDefault()
		return false
}

function scrollToClick(e){
	if (oClient.ns4){ clickY = e.y } else if (oClient.ns5up){ clickY = e.layerY	} else if (oClient.ie4up || oClient.opera){ clickY = e.offsetY } else { clickY = e.offsetY }	
	clickY -= (this.scrollBar.h*.5)-this.bg.getOffsetTop()
	moveY = clickY-this.scrollBar.ypos
	if (moveY<1) moveY= moveY.inverse()
	clipModScrollBar = this.scrollSpeed/this.scrollRatio
	times = Math.round(moveY/clipModScrollBar)
	clipModScrollBar = (clickY>this.scrollBar.ypos)?clipModScrollBar:0-clipModScrollBar;
	for (a=1;a<times+1;a++){
		dTime = 10*a
		setTimeout(this.obj+".buttonScroll("+clipModScrollBar+")",dTime)
	}
}

function buttonScroll(mod,direction){
		send_pTop = this.scrollBar.ypos + mod
		this.scroll(null,send_pTop)
		if (oClient.op5 && this.rupert!=null) this.rupert = setTimeout(this.obj+".buttonScroll("+mod+","+direction+")",10)	//opera 5 has issues with setinterval
}

function scroll(pLeft,pTop){
	if (this.scrollRatio>0){
		setT = clipTop = clipBottom = null	
		if (pTop){
			//Hier wird die Höhe des Scroller-Up Buttons eingegeben für ns6.x
			if (this.scrollMin > 0) {
				myScrollMin = this.scrollMin
			} else {
				myScrollMin = 10
			}

			if (Math.floor(pTop)>=this.scrollMax) pTop = this.scrollMax
			else if (Math.ceil(pTop)<=myScrollMin || !pTop) 	pTop = myScrollMin
			clipMod = Math.round((pTop-this.scrollBar.ORIGypos)*this.scrollRatio)
			if (this.compMode){
				clipTop 	= clipMod
				clipBottom 	= clipMod + this.clipHeight
			}
			setT = this.ORIGypos-clipMod
			this.scrollAtTop = pTop
		}
		if (this.compMode) this.setClip(clipTop,null,clipBottom,0)
		this.content.setLayerPixel(null,setT)
		if (pTop){
			mySliderHeight = 75 //Höhe des Slider Buttons
			myArrowHeight = 9 //Höhe des Arrow Buttons
			mySpace = 10 //Höhe bei der der Slider und der Arrow im css platziert sind
			this.scrollBar.setLayerPixel(null,pTop)
			this.scrollArr.setLayerPixel(null,pTop+(((mySliderHeight/(this.scrollMax-mySpace)) * (pTop-mySpace)) - (myArrowHeight/(this.scrollMax-mySpace) * (pTop-mySpace))))
			//Dies ist die Formel für den Scroll des Arrows
}	}	}

function mouseMoveScroll(e,mx,my) {
	if (this.scrolling && this.scrollDirection=="v"){
		if (!mx || !my){
			e = e || event
			my = (oClient.ns4up)?e.pageY:e.clientY;
		}
		pTop = my - this.mouseInLayerY
		this.scroll(null,pTop)
		return false
	}
	return false
}

function calibrate(force){
	this.totalHeight 	= force || this.content.getDim(1)-this.getClip("height")
	this.scrollMin 		= this.up.ypos+this.up.h

	//Hier wird die Höhe des Scroller-Up Buttons eingegeben für ns6.x
	if (this.scrollMin > 0) {
		myScrollMin = this.scrollMin
	} else {
		myScrollMin = 10
	}
	
	//Hier wird die Höhe des Slider Buttons eingegeben für ns6.x
	if (this.scrollBar.h > 0) {
		myScrollBar = this.scrollBar.h;
	} else {
		myScrollBar = 75
	}

	this.scrollMax 		= this.down.ypos-myScrollBar
	this.scrollSpan 	= this.scrollMax-myScrollMin
	this.scrollRatio	= this.totalHeight/this.scrollSpan

	if (this.autoVis){
		if (this.scrollRatio>0) this.scrollVis(true)
		else {
			this.scrollVis(false)
		}
	}
}

function scrollVis(show){
	this.bg.layerVis(show)
	this.scrollBar.layerVis(show)
	this.scrollArr.layerVis(show)	
	this.bg.layerVis(show)
	this.up.layerVis(show)
	this.down.layerVis(show)
}

function reset(){ 
	if (this.scrollBar){ 

		//Hier wird die Höhe des Scroller-Up Buttons eingegeben für ns6.x
		if (this.scrollMin > 0) {
			myScrollMin = this.scrollMin
		} else {
			myScrollMin = 10
		}

		this.scroll(null,myScrollMin)
	} 
}

