// BEGIN LAYER OBJECT

function LyrObj(divId) {   // position is always pushed to the dom for these objects, but width and height can be pulled from the dom safely
	this.name = divId;
	if (objBrowser.ns4) this.ob = eval("document." +divId);
	else if (objBrowser.ie4) this.ob = document.all(divId);
	else this.ob = document.getElementById(divId);
	this.x = 0;
	this.y = 0;
	this.targetX = 0;
	this.targetY = 0;
	this.width	=	this.getWidth();
	this.height	=	this.getHeight();
}
LyrObj.prototype.px = (objBrowser.v>=5 || (objBrowser.ie5 && objBrowser.mac))?"px":"";
LyrObj.prototype.hideSyntax = (objBrowser.ns4)? "hide":"hidden";
LyrObj.prototype.showSyntax = "visible";
LyrObj.prototype.getInlineLeft = function() {
	if (objBrowser.ns4) return this.ob.pageX;
	else if ((objBrowser.ie) || (objBrowser.opera)) {
		var elem = this.ob;
		var xPos = 0;
		var yPos = 0;
		while (elem.offsetParent != null) {
			xPos += elem.offsetLeft;
			elem = elem.offsetParent;
		}
		return xPos;
	}	
	else return (this.ob.offsetLeft + document.body.offsetLeft);
}
LyrObj.prototype.getInlineTop = function() {
	if (objBrowser.ns4) return this.ob.pageY;
	else if ((objBrowser.ie) || (objBrowser.opera)) {
		var elem = this.ob;
		var yPos=0;
		while (elem.offsetParent != null) {
			yPos += elem.offsetTop;
			elem = elem.offsetParent;
		}
		return yPos;
	}
	else return (this.ob.offsetTop+ document.body.offsetTop);
}
LyrObj.prototype.getWidth = function () {	
	if (objBrowser.ns4) return this.ob.clip.width;
	else if (objBrowser.opera) return this.ob.style.pixelWidth;
	else return this.ob.offsetWidth;
}
LyrObj.prototype.getHeight = function () {
	if (objBrowser.ns4) return this.ob.clip.height;
	else if (objBrowser.opera) return this.ob.style.pixelHeight;
	else return this.ob.offsetHeight;
}
LyrObj.prototype.hide = function() {
	if (objBrowser.ns4) this.ob.visibility = this.hideSyntax;
	else this.ob.style.visibility = this.hideSyntax;
}
LyrObj.prototype.show = function() {	
	if (objBrowser.ns4) this.ob.visibility = this.showSyntax;
	else this.ob.style.visibility = this.showSyntax;
}
LyrObj.prototype.moveLayerTo = function(toX, toY) {
	this.x = toX;
	this.y = toY;
	this.targetX = toX;
	this.targetY = toY;
}
LyrObj.prototype.moveLayerBy = function(dX, dY) {
	this.x += dX;
	this.y += dY;
	this.targetX +=dX;
	this.targetY +=dY;
}
LyrObj.prototype.moveTargetTo= function(x,y) {
	this.targetX = x;
	this.targetY = y;
}
LyrObj.prototype.moveTargetBy= function(dX,dY) {
	this.targetX += dX;
	this.targetY += dY;
}
LyrObj.prototype.clipTo = function(t,r,b,l) {
	if (objBrowser.ns){
		if (objBrowser.v>=5) {
		//  clipping on NS 6 sucks compared to NS4 and IE. very slow, but at least stable.
		//  Cant NS6 use the NS4 code too? 
			this.ob.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
		}
		else {
			this.ob.clip.top = t;
			this.ob.clip.right = r;
			this.ob.clip.bottom = b;
			this.ob.clip.left = l;
		}
	}
	else {
		//IE + all other
		this.ob.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
	}
}

LyrObj.prototype.moveTowardTarget= function(denominator) {
	this.x +=   (this.targetX - this.x) / denominator;
	this.y +=   (this.targetY - this.y) / denominator;
}
LyrObj.prototype.updateLayer =  function() {
	if (objBrowser.ns4) {
		this.ob.left = Math.round(this.x) + this.px;
		this.ob.top = Math.round(this.y)+ this.px ;
	}
	else {
		this.ob.style.left = (Math.round(this.x) + "px");
		this.ob.style.top = (Math.round(this.y)  + "px");
	}
} 
// END LAYER OBJECT