DEBUG = (window.location.search.indexOf('debug=1') > -1) ? true : false;
function elcLayer(id) {
	if (bw.ns4) { return null };
	this.obj=bw.dom?document.getElementById(id):bw.ie4?document.all[id]:0;
	if (this.obj == null || !this.obj) { return null };
	this.css=bw.dom?document.getElementById(id).style:bw.ie4?document.all[id].style:0;
	if (bw.ie4) {this.x=this.css.pixelLeft;this.y=this.css.pixelTop;this.h=this.css.clientHeight;this.w=this.css.clientWidth;}
	if (bw.ie5 || bw.ns6) {
 		this.x=findAbsoluteOffset(this.obj, cFindOffsetFromLeft);
		this.y=findAbsoluteOffset(this.obj, cFindOffsetFromTop);
		this.h=this.obj.offsetHeight;
		this.w=this.obj.offsetWidth;
	}
	if (DEBUG) {
		var str = this.statistics();
		alert( 'New Layer instantiated: ' + id + '\n' + str );
	}
}

elcLayer.prototype.moveTo = function(x,y) {
//alert( this.obj.style.top );
    this.x = x;
    this.y = y;
    this.css.left = this.x;
    this.css.top = this.y
    if (bw.dom && (this.obj != null)) {
        this.obj.style.left = x + 'px';
        this.obj.style.top = y + 'px';
//alert( this.obj.style.top );
    }
}

elcLayer.prototype.moveBy = function(x,y){
	this.x+=x;
	this.y+=y;
	this.css.left+=x;
	this.css.top+=y;
        if (bw.dom && (this.obj != null)) {
            this.obj.style.left = this.x + 'px';
            this.obj.style.top = this.y + 'px';
        }
}

elcLayer.prototype.setZIndex = function(z){
	this.z=z;
	this.css.zIndex=z;
}

elcLayer.prototype.clipValues = function(which){
	var clipv = this.css.clip.split("rect(")[1].split(")")[0].split("px");
	if(which=="t") return Number(clipv[0]);
	if(which=="r") return Number(clipv[1]);
	if(which=="b") return Number(clipv[2]);
	if(which=="l") return Number(clipv[3]);
}

elcLayer.prototype.clipTo = function(t,r,b,l){
	this.css.clip="rect("+t+","+r+","+b+","+l+")";
}

elcLayer.prototype.clipBy = function(t,r,b,l){
	this.clipTo(this.clipValues('t')+t,this.clipValues('r')+r,this.clipValues('b')+b,this.clipValues('l')+l);
}

elcLayer.prototype.hide = function(){
        this.css.visibility = 'hidden';
	this.display('none');
}

elcLayer.prototype.show = function(){
        this.css.visibility = 'visible';
	this.display('block');

}

elcLayer.prototype.vis = function(){
	if(this.css.visibility=="hidden" || this.css.visibility=="hide") return true;
}

elcLayer.prototype.writeThis = function(txt){
	this.obj.innerHTML = txt;
}

elcLayer.prototype.replaceImage = function(imgName,imgSrc) {
	document[imgName].src = imgSrc;
}

elcLayer.prototype.display = function( displayState ) {
	this.css.display = displayState;
}

elcLayer.prototype.statistics = function() {
	var vitals = 'Layer stats\n' + 'x : ' + this.x + '\n' + 'y : ' + this.y + '\n' + 'w : ' + this.w + '\n' + 'h : ' + this.h + '\n' + 'z : ' + this.z + '\n';
	return vitals;
}

// contributed by WebCollage
function findAbsoluteOffset (node, leftTopOrRight) {
	var offset = 0;
	var currObject = node;

	while (currObject) {
		if (leftTopOrRight == cFindOffsetFromLeft || leftTopOrRight == cFindOffsetFromRight)
			offset += currObject.offsetLeft;
		else if (leftTopOrRight == cFindOffsetFromTop)
			offset += currObject.offsetTop;
		currObject = currObject.offsetParent;
	}

	if (leftTopOrRight == cFindOffsetFromRight)
		return offset + node.offsetWidth;
	else
		return offset;
}

var cFindOffsetFromLeft = 1;
var cFindOffsetFromTop = 2;
var cFindOffsetFromRight = 3;
