//  this little object is used in many places to provide information about the browser and platform. 
function Browser() {
	var b=navigator.appName;
	if (b=="Netscape") this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	//this.ns6=(this.b=="ns" && this.v==5);
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.ie6up = ((navigator.appVersion.indexOf("MSIE 6")!=-1)||(navigator.appVersion.indexOf("MSIE 7")!=-1));
	this.opera=(this.b=="opera");
	var ua=navigator.userAgent.toLowerCase();
	this.mac = (ua.indexOf("mac")!=-1);
	this.win = (ua.indexOf("windows")!=-1);
	this.safari = (ua.indexOf("safari")!=-1);

	

}
var is = new Browser();

// 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 (is.ns4) this.ob = eval("document." +divId);
	else if (is.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 = (is.version>=5)?"px":"";
LyrObj.prototype.hideSyntax = (is.ns4)? "hide":"hidden";
LyrObj.prototype.showSyntax = "visible";
LyrObj.prototype.getInlineLeft = function() {
	if (is.ns4) return this.ob.pageX;
	else if ((is.ie) || (is.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 (is.ns4) return this.ob.pageY;
	else if ((is.ie) || (is.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 (is.ns4) return this.ob.clip.width;
	else if (is.opera) return this.ob.style.pixelWidth;
	else return this.ob.offsetWidth;
}
LyrObj.prototype.getHeight = function () {
	if (is.ns4) return this.ob.clip.height;
	else if (is.opera) return this.ob.style.pixelHeight;
	else return this.ob.offsetHeight;
}
LyrObj.prototype.hide = function() {
	if (is.ns4) this.ob.visibility = this.hideSyntax;
	else this.ob.style.visibility = this.hideSyntax;
}
LyrObj.prototype.show = function() {	
	if (is.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 (is.ns){
		if (is.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 (is.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) + this.px;
		this.ob.style.top = Math.round(this.y)  + this.px;
	}
} 
// END LAYER OBJECT