//tested on PC win2000:
//IE 5.0,IE 5.5 and IE 6.0
//NN 7.1
//MOZ 1.7.3
//FIREFOX 1.0 preview
//OPERA 7.54
//on MAC OS X 10.3:
//Safari 1.1 

function ObjLayer(poRef,pobj,pnest){
    pnest=(!pnest) ? '':'document.'+pnest+'.' 

	//attributes
	this.ref = poRef;
	this.name = pobj;
	this.nest = pnest;
	this.move = false;
	this.dragX = 0; //the horizontal distance between the mousepointer ande the top right corner of the object that is being draged
	this.dragY = 0; //the vertical distance between the mousepointer ande the top right corner of the object that is being draged

	this.el=bw.dom?document.getElementById(this.name):bw.ie4?document.all[this.name]:bw.ns4?eval(this.nest+'document.'+this.name):0; 
    this.css=bw.dom?document.getElementById(this.name).style:bw.ie4?document.all[this.name].style:bw.ns4?eval(this.nest+'document.'+this.name):0; 

//methods

//visibility
	this.show=function(){this.css.visibility="visible"};
	this.hide=function(){this.css.visibility="hidden"};

//display
	this.display=function(){this.css.display="block"};
	this.nodisplay=function(){this.css.display="none"};
	
//dimensions
	this.getHeight=function(){return bw.ns4?this.css.document.height:this.el.offsetHeight;};
	this.getWidth=function(){return bw.ns4?this.css.document.width:this.el.offsetWidth;};
	this.setWidth=function(pInt){this.css.width = pInt;};
	this.setHeight=function(pInt){this.css.height = pInt;};

//positioning
	this.setX=function(pInt){this.css.left = pInt;};	
	this.setY=function(pInt){this.css.top = pInt;};
	this.setZ=function(pInt){this.css.zIndex = pInt;};	
	this.getX=function(){return bw.ns4?this.css.left:this.el.offsetLeft;};
	this.getY=function(){return bw.ns4?this.css.top:this.el.offsetTop;};
	this.getZ=function(){return this.css.zIndex;};
	
//moving
	this.up = function(pInt){this.setY(this.getY()-pInt);};
	this.down = function(pInt){this.setY(this.getY()+pInt);};
	this.right = function(pInt){this.setX(this.getX()+pInt);};
	this.left = function(pInt){this.setX(this.getX()-pInt);};

	this.moveTo = function(e){
		if (arguments.length==1){	
			if (!e) {e = window.event};		
			x = getEventX(e);
			y = getEventY(e);
		}
		else {
			if (arguments.length==2 && typeof(arguments[0])=="number" && typeof(arguments[1])=="number"){
				x = arguments[0];
				y = arguments[1];
			}
			else {return false}
		}
		this.setX(x);
		this.setY(y);
	}
	
	this.moveUp = function(pInt,strCaller){
		if(strCaller!="self"){this.move=true}
		if(this.move){
			this.up(pInt);
			setTimeout(this.ref+".moveUp("+pInt+",'self')",50);
			}
		}

	this.moveDown = function(pInt,strCaller){
		if(strCaller!="self"){this.move=true}
		if(this.move){
			this.down(pInt);
			setTimeout(this.ref+".moveDown("+pInt+",'self')",50);
			}
		}

	this.moveLeft = function(pInt,strCaller){
		if(strCaller!="self"){this.move=true}
		if(this.move){
			this.left(pInt);
			setTimeout(this.ref+".moveLeft("+pInt+",'self')",50);
			}
	
		}
	this.moveRight = function(pInt,strCaller){
			if(strCaller!="self"){this.move=true}
			if(this.move){
				this.right(pInt);
				setTimeout(this.ref+".moveRight("+pInt+",'self')",50);
				}
		}

	this.stopMove = function(){
		this.move=false
	}
	
//cliping
	this.setClipArea = function(t,r,b,l){
		if (arguments.length==1){intT=t[0];r=t[1];b=t[2];l=t[3];}
		else {intT=t}
		if (bw.ns4){this.css.clip.top=intT;this.css.clip.right=r;this.css.clip.bottom=b;this.css.clip.left=l}
		else{this.css.clip="rect("+intT+"px "+r+"px "+b+"px "+l+"px)";}
		}

	this.getClipArea = function(){
		var clipval=new Array()
		if(bw.dom || bw.ie4) {
			clipval=this.css.clip
			clipval=clipval.slice(5,clipval.length-1);
			clipval=clipval.split(' ')
			for(var i=0;i<4;i++){clipval[i]=parseInt(clipval[i])}
		}else{
			clipval[0]=this.css.clip.top
	    	clipval[1]=this.css.clip.right
		    clipval[2]=this.css.clip.bottom
		    clipval[3]=this.css.clip.left
		}
		return clipval;
		}

//scrolling
	this.scrollDown = function(pInt){
		var arrClip = this.getClipArea();
		var jump = Math.min(this.getHeight()-arrClip[2],pInt);
		arrClip[2]+=jump;
		arrClip[0]+=jump;
		this.setClipArea(arrClip);
		this.up(jump);
		}

	this.scrollUp = function(pInt){
		var arrClip = this.getClipArea();
		var jump = Math.min(arrClip[0],pInt);
		arrClip[0]-=jump;
		arrClip[2]-=jump;
		this.setClipArea(arrClip);
		this.down(jump);
		}

	this.scrollLeft = function(pInt){
		arrClip = this.getClipArea();
		var jump = Math.min(arrClip[3],pInt);
		arrClip[1]-=jump;
		arrClip[3]-=jump;
		this.setClipArea(arrClip);
		this.right(jump);
		}

	this.scrollRight = function(pInt){
		arrClip = this.getClipArea();
		var jump = Math.min(this.getWidth()-arrClip[1],pInt);
		arrClip[1]+=jump;
		arrClip[3]+=jump;
		this.setClipArea(arrClip);
		this.left(jump);
		}

	this.scrollVerticalByPercentage = function(intPerc){
		// 0% means to the top, 50% halfway, 100% to the bottom etc.
		currClip = this.getClipArea()
		hClip = currClip[2]-currClip[0];
		hLayer = this.getHeight();
		yVisibleWindow = this.getY() + currClip[0]

		cliptop = Math.round(intPerc*(hLayer-hClip));
		clipbottom = cliptop + hClip;

		this.setClipArea(cliptop,currClip[1],clipbottom,currClip[3]);
		this.setY(yVisibleWindow-cliptop)
	}


//draging
	
	this.startDrag = function(e){
		if (!e) {e = window.event};
		this.dragX = this.getX() - getEventX(e) ;
		this.dragY = this.getY() - getEventY(e) ;
		if (document.body.addEventListener){
			eval("window.document.dragfunc =  function(e){window."+this.ref+".Drag(e)}")
			eval("window.document.stopdragfunc =  function(){window."+this.ref+".stopDrag()}")
			document.body.addEventListener("mousemove",window.document.dragfunc,false)
			document.body.addEventListener("mouseup",window.document.stopdragfunc,false)
			}
		else{
			eval("document.body.onmousemove = function(){"+this.ref+".Drag(event)}")
			eval("document.body.onmouseup = function(){"+this.ref+".stopDrag()}")
			}
		}

	this.Drag = function(e){
		if (!e) {e = window.event};
		this.moveTo(getEventX(e)+this.dragX,getEventY(e)+this.dragY);
		}


	this.stopDrag = function(){
		if (document.body.addEventListener){
			document.body.removeEventListener("mousemove",window.document.dragfunc,false)
			document.body.removeEventListener("mouseup",window.document.stopdragfunc,false)
			}
		else {
			document.body.onmousemove = null;
			document.body.onmouseup = null;
		}
		this.dragX = 0; 
		this.DragY = 0;
		}

	this.initDrag = function() {
		//hack for IE bug where you can see selectboxes through layers does not work in IE5 or lower
		this.el.innerHTML = '<span style="position:relative;top:0;left:0;z-index:'+this.getZ()+';display:block;">'+this.el.innerHTML + '</span><iframe style="position:absolute;top:0;left:0;z-index:'+(this.getZ()-1)+';display:block;" height="'+(this.getHeight()-2)+'" width="'+(this.getWidth()-2)+'" frameborder="0"></iframe>'
	}

		
//center in screen
	this.centerInScreenHorz = function(){
		var intInnerWidth;
		if (window.innerWidth){intInnerWidth = window.innerWidth;}
		else if (document.body.offsetWidth){intInnerWidth = document.body.offsetWidth;}
		else {alert("unexpected error!! please report at support@tpm-webapplicaties.nl, thank you")};
		this.setX((intInnerWidth-this.getWidth())/2);
	};

	this.centerInScreenVert = function(){
		var intInnerHeight;
		var intPosVertScreen;
		if (window.innerHeight){intInnerHeight = window.innerHeight;}
		else if (document.body.offsetHeight){intInnerHeight = document.body.offsetHeight;}
		else {alert("unexpected error!! please report at support@tpm-webapplicaties.nl, thank you")};
		intPosVertScreen = document.body.scrollTop;
		this.setY(intPosVertScreen + ((intInnerHeight-this.getHeight())/2));
	};

	this.centerInScreen = function(){
		this.centerInScreenHorz();
		this.centerInScreenVert();
	};

//initialize	
}





