//================//
// Layer Handler v1.2
//----------------
// Provides a generic API for handling layers/divs.
//----------------
// Requires: None
//----------------
// Modifications: 	06 Apr 2000 - Added support for Netscape 6. Added show and hide methods.
//							09 Oct 2000 - Added setClip and setContent methods.
//							07 Mar 2001 - Fixed problem with getHeight and getWidth methods in IE.
//							13 Mar 2001 - Fixed problem with NS6 returning nothing for the width and height of a layer if they
//								  				 had not been previously designated.
//================//

var ref_Collection = "";
var ref_CollectionEnd = "";
var ref_Style = "";

// DOM mapping for IE.
if (document.all) {
	ref_Collection = "all.";
	ref_Style = ".style";
}

// Netscape 6 detection and DOM mapping.
if (document.getElementById && !document.all) {
	isNetscape6 = true;
	ref_Collection = "getElementById('";
	ref_CollectionEnd = "')";
	ref_Style = ".style";
} else {
	isNetscape6 = false;
}

// layerHandler object constructor.
function layerHandler (objectName) {
	
	var ref_ObjectString = "document." + ref_Collection + objectName + ref_CollectionEnd;
	var ref_Object = eval (ref_ObjectString);

	// Check that the referenced object actually exists.
	if (ref_Object) {
		this.obj = eval ("ref_Object" + ref_Style);
		this.content = ref_Object;
	} else {
		alert ("Reference object not available.");
	}

	// PROPERTIES
	this.name = objectName;

	// METHODS
	this.setTop = layerHandler_setTop;
	this.setLeft = layerHandler_setLeft;
	this.setPosition = layerHandler_setPosition;
	this.setWidth = layerHandler_setWidth;
	this.setHeight = layerHandler_setHeight;
	this.setSize = layerHandler_setSize;
	
	this.top = layerHandler_getTop;
	this.left = layerHandler_getLeft;
	this.width = layerHandler_getWidth;
	this.height = layerHandler_getHeight;
	
	this.show = layerHandler_show;
	this.hide = layerHandler_hide;
	
	this.setClip = layerHandler_setClip;
	
	this.setContent = layerHandler_setContent;
}

// setTop
function layerHandler_setTop(y) {
	if (this.obj) {
		if (document.all) {
			this.obj.pixelTop = y;
		} else {
			this.obj.top = y;
		}
	}
}

// setLeft
function layerHandler_setLeft(x) {
	if (this.obj) {
		if (document.all) {
			this.obj.pixelLeft = x;
		} else {
			this.obj.left = x;
		}
	}
}

// setPosition
function layerHandler_setPosition(x,y) {
	this.setLeft(x);
	this.setTop(y);
}

// getTop
function layerHandler_getTop() {
	if (this.obj) {
		if (document.all) {
			return this.obj.pixelTop;
		} else {
			return parseInt(this.obj.top);
		}
	}
}

// getLeft
function layerHandler_getLeft() {
	if (this.obj) {
		if (document.all) {
			return this.obj.pixelLeft;
		} else {
			return parseInt(this.obj.left);
		}
	}
}

// setWidth
function layerHandler_setWidth(w) {
	if (this.obj) {
		if (isNetscape6) {
			this.obj.width = w;
		} else {
			if (document.all) {
				this.obj.width = w;
			} else {
				this.obj.clip.width = w;
			}
		}
	}
}

// setHeight
function layerHandler_setHeight(h) {
	if (this.obj) {
		if (isNetscape6) {
			this.obj.height = h;
		} else {
			if (document.all) {
				this.obj.height = h;
			} else {
				this.obj.clip.height = h;
			}
		}
	}
}

// setSize
function layerHandler_setSize(w,h) {
	this.setWidth(w);
	this.setHeight(h);
}

// getWidth
function layerHandler_getWidth() {
	if (this.obj) {
		if (isNetscape6) {
			return this.content.offsetWidth;
		} else {
			if (document.all) {
				return this.content.clientWidth;
			} else {
				return this.obj.clip.width;
			}
		}
	}
}

// getHeight
function layerHandler_getHeight() {
	if (this.obj) {
		if (isNetscape6) {
			return this.content.offsetHeight;
		} else {
			if (document.all) {
				return this.content.clientHeight;
			} else {
				return this.obj.clip.height;
			}
		}
	}
}

// show
function layerHandler_show() {
	if (this.obj) {
		this.obj.visibility = "visible";
	}
}

// hide
function layerHandler_hide() {
	if (this.obj) {
		this.obj.visibility = "hidden";
	}
}

// setClip
function layerHandler_setClip(clipTop, clipLeft, clipWidth, clipHeight) {
	if (this.obj) {
		if (document.all || isNetscape6) {
			clipRight = clipLeft + clipWidth;
			clipBottom = clipTop + clipHeight;
			this.obj.clip = "rect( " + clipTop + " " + clipRight + " " + clipBottom + " " + clipLeft + " )";
		} else {
			this.obj.clip.top = clipTop;
			this.obj.clip.left = clipLeft;
			this.obj.clip.right = clipLeft + clipWidth;
			this.obj.clip.bottom = clipTop + clipHeight;
		}
	}
}

// setContent
function layerHandler_setContent( theContent ) {
	
	// Netscape 6
	if (isNetscape6) {
			
		var docRange;
		var contentFragment;
		
		docRange = document.createRange();
		docRange.setStartBefore(this.content);
		contentFragment = docRange.createContextualFragment(theContent);
		
		while (this.content.hasChildNodes()) {
			this.content.removeChild(this.content.lastChild);
		}
		
		this.content.appendChild(contentFragment);
		
	// IE4.x, IE5.x
	} else if (document.all) {
		
		this.content.innerHTML = theContent;
		
	// Netscape 4.x
	} else {
		
		this.content.document.open();
		this.content.document.write(theContent);
		this.content.document.close();
		
	}
	
}