var ie = document.all ? true : false;
var ns = document.layers ? true : false;
var ns6 = !ie && document.getElementById ? true : false;

// Problem: After starting Netscape 4.x, the first
// call to the constructor fails, throwing an error.
// This is a fix that simply causes a reload of the
// page in case the test layer couldn't be accessed.
// To apply, make sure the page contains the line
// <div id="fixnetscape" style="position:absolute;visibility:hidden"></div>
// and call this function in your onLoad-handler.
function fixNetscape() {
	if (!LyrObjGetRef("fixnetscape")) document.location.reload();
}

function LyrObjGetRef(layerName) {
	if (ns) return eval("document." + layerName);
	if (ie) return eval("document.all." + layerName);
	if (ns6) return document.getElementById(layerName);
}

function LyrObjGetPos(which) {
	if (ns) {
		return this.ref[which];
	}
	if (ie || ns6){
		return this.ref[which].split("px")[0];
	}
}	

function LyrObjSetPos(which, pos) {
	this.ref[which] = pos;
}

function LyrObjGetClip(which) {
	if (ns) { return this.ref.clip[which]; }
	
	if (ie || ns6){
		var clipPos = this.ref.clip.split("rect(")[1].split(")")[0].split("px");
		switch (which) {
			case "top" : return Number(clipPos[0]);
			case "right" : return Number(clipPos[1]);
			case "bottom" : return Number(clipPos[2]);
			case "left" : return Number(clipPos[3]);
		}
	}
}

function LyrObjSetClip(left, top, right, bottom){
	if (ns){
		this.ref.clip.top = top;
		this.ref.clip.right = right;
		this.ref.clip.bottom = bottom;
		this.ref.clip.left = left;
	}
	if (ie || ns6)
		this.ref.clip = "rect(" + top +"px " + right +"px " + bottom +"px " + left +"px)";
}

function LyrObjGetVisibility() {
	v = this.ref.visibility;
	return v.indexOf("hid") == -1;
}

function LyrObjSetVisibility(visible){

	if (ns)
		this.ref.visibility = visible ? "show" : "hide";

	if (ie || ns6)
		this.ref.visibility = visible ? "visible" : "hidden";
}

function LyrObjShow() {
	this.setVisibility(true);
}

function LyrObjHide() {
	this.setVisibility(false);
}

function LyrObjGetzIndex() {
	return this.ref.zIndex;
}

function LyrObjSetzIndex(zIndex){
	this.ref.zIndex = zIndex;
}

/** Steiler Contructor
	*
	*/
function LyrObj(lyrName) {

  this.lyrname = lyrName;

	this.ref = ns ? LyrObjGetRef(lyrName) : LyrObjGetRef(lyrName).style;
	//if (!this.ref) alert("Error: Couldn't access " + this.lyrname);
	
  
  
	this.getPos = LyrObjGetPos;
	this.setPos = LyrObjSetPos;
	
	this.getClip = LyrObjGetClip;
	this.setClip = LyrObjSetClip;
	
	this.getVisibility = LyrObjGetVisibility;
	this.setVisibility = LyrObjSetVisibility;
	this.show = LyrObjShow;
	this.hide = LyrObjHide;
	
	this.getzIndex = LyrObjGetzIndex;
	this.setzIndex = LyrObjSetzIndex;
	return this;
}
