function ObjStage (pintX,pintY,pintWidth,pintHeight,pstrObjRef) {

	//attributen
	this.Ref = pstrObjRef;
	this.X = pintX;
	this.Y = pintY;
	this.Width = pintWidth;
	this.Height = pintHeight;
	
	this.Layers = new Array(); //all the layers that will appear on the stage
	this.arrVisibleLayers = new Array; //the current visible layers on the stage
	this.objScroller
	
	this.strScrollableLayer = "" //the layer that is controlled by the visible scroller controllers
	this.strScrollDir = ""; //direction in which the layer is being is scrolled
	
	this.scrollTime	= 40;
	this.scrollJump	= 5;
	this.scrollJumpBar	= 40;

	//methods
	this.addLayer = function(Layer,Nest,strAlign,strValign){
		var newLayer = new ObjLayer("",Layer,Nest);
		this.Layers[Layer] = newLayer;
		this.Layers[Layer].strAlign = strAlign
		this.Layers[Layer].strValign = strValign
		}

	this.addScroller = function (strScrollThumb,strScrollBar,strScrollUpArrow,strScrollDownArrow){
		this.objScroller = new ObjScroller(strScrollThumb,strScrollBar,strScrollUpArrow,strScrollDownArrow);
	}

	this.show = function(){
		//input: meerdere lagen, de laatste laag die scrollable is krijgt scrollers de andere niet
		this.hideall();
		for (var i=0;i < arguments.length; i++){
	        	var Layer = arguments[i];
				if (this.Layers[Layer]){
					this.align(Layer,this.Layers[Layer].strAlign);
					this.valign(Layer,this.Layers[Layer].strValign);
					t = Math.max(0,this.Y-this.Layers[Layer].getY())
					l = Math.max(0,this.X-this.Layers[Layer].getX());
					r = l + Math.min(this.Layers[Layer].getWidth(),this.Width);
					b = t + Math.min(this.Layers[Layer].getHeight(),this.Height)
					this.Layers[Layer].setClipArea(t,r,b,l);
					this.Layers[Layer].show();
					this.arrVisibleLayers[this.arrVisibleLayers.length] = Layer;
					//showen scrollers
					if (this.Layers[Layer].getHeight() > this.Height && this.objScroller){
						this.strScrollableLayer = Layer;
						this.objScroller.show(this.Layers[this.strScrollableLayer], this.Height);
						}
					}
			}
	} 

	this.hideall = function(){
		//hide layers
		if (this.arrVisibleLayers.length) {
			for (var i in this.arrVisibleLayers) {this.Layers[this.arrVisibleLayers[i]].hide();}
			this.arrVisibleLayers.length = 0;
			}
		//hide scrollers
		if (this.objScroller) {
			this.objScroller.hide()
			}		
		}

	this.valign = function(Layer,strVert){
		switch(strVert){
		case "center" : this.Layers[Layer].setY(this.Y+Math.max(0,0.5*(this.Height-this.Layers[Layer].getHeight())));break;
		case "bottom" : this.Layers[Layer].setY(this.Y+Math.max(0,this.Height-this.Layers[Layer].getHeight()));break;
		case "top" :	this.Layers[Layer].setY(this.Y);break;
		case "" :		break;
		default : alert("fout bij uitlijnen layer in stage")
		}
	}

	this.align = function(Layer,strHorz){
//		alert(strHorz+" x"+this.X+" w"+this.Width+" gw"+this.Layers[Layer].getWidth()+" layer:"+Layer)
		switch(strHorz){
		case "center" : this.Layers[Layer].setX(this.X+0.5*(this.Width-this.Layers[Layer].getWidth()));break;
		case "right" :  this.Layers[Layer].setX(this.X+this.Width-this.Layers[Layer].getWidth());break
		case "left" : this.Layers[Layer].setX(this.X);break;
		case "" : break;
		default : alert("fout bij uitlijnen layer in stage")
		}
	}


	this.startScroll = function(strDir){
		this.strScrollDir=strDir;
		this.Scroll();
		}

	this.stopScroll = function(){
			this.strScrollDir="";
	}

	this.Scroll = function(){
		if (this.strScrollDir!=""){
			if (this.strScrollDir=="down"){this.Layers[this.strScrollableLayer].scrollDown(this.scrollJump);}
			if (this.strScrollDir=="up"){this.Layers[this.strScrollableLayer].scrollUp(this.scrollJump);}
			if (this.objScroller) {this.objScroller.positionThumb(this.Layers[this.strScrollableLayer],this.Height)}
			if(this.strScrollDir!=""){setTimeout(this.Ref+".Scroll();",this.scrollTime)}//the line between quotes operates on a global level
			}
	}

	this.barScroll = function(objEvent){
		var Ymouse;
		if (bw.ns4) {Ymouse = objEvent.pageY}
		else {Ymouse = objEvent.clientY}
		if (Ymouse<this.objScroller.lThumb.getY()) {this.Layers[this.strScrollableLayer].scrollUp(this.scrollJumpBar);}
		if (Ymouse>(this.objScroller.lThumb.getY()+this.objScroller.lThumb.getHeight())) {this.Layers[this.strScrollableLayer].scrollDown(this.scrollJumpBar);}
		this.objScroller.positionThumb(this.Layers[this.strScrollableLayer],this.Height)
		}

	this.thumbScroll = function(){
		yThumb = this.objScroller.lThumb.getY();
		hThumb = this.objScroller.lThumb.getHeight();
		yBar = this.objScroller.lBar.getY();
		hBar = this.objScroller.lBar.getHeight();
		this.Layers[this.strScrollableLayer].scrollVerticalByPercentage((yThumb-yBar)/(hBar-hThumb))
	}
	
	this.showArea = function(strLayer){
	//deze functie is voor ontwerp doeleinden
		var debugLayer = new ObjLayer(strLayer);
		debugLayer.setX(this.X);
		debugLayer.setY(this.Y);
		debugLayer.setWidth(this.Width);
		debugLayer.setHeight(this.Height);
		debugLayer.setClipArea(0,4000,4000,0)
		debugLayer.show();
	}
}

