/*******************************
*
* elcLayer.js
* 
* generic layer class
*
* Author: DoublePrime
* References: ELCI Clinique layer.js created by Razorfish
* Version: 0.1
*
* Comments
*
*******************************/
DEBUG = (window.location.search.indexOf('debug=1') > -1) ? true : false;

function elcLayer(id) {
	if (document.getElementById(id)) {
		this.obj = (document.getElementById(id));
		this.style = this.obj.style;
		this.x = (this.obj.offsetLeft) ? this.obj.offsetLeft : null;
		this.y = (this.obj.offsetTop) ? this.obj.offsetTop : null;
		this.h = (this.obj.offsetHeight) ? this.obj.offsetHeight : null;
		this.w = (this.obj.offsetWidth) ? this.obj.offsetWidth : null;
		
		if (DEBUG) {
			var str = this.statistics();
			alert( 'New Layer instantiated: ' + id + '\n' + str );
		}
		return this;
	} else {
		return null;
	}
}

elcLayer.prototype.moveTo = function(x,y) {
	this.x=x;
	this.y=y;
	this.style.left=this.x;
	this.style.top=this.y;
}
	
elcLayer.prototype.moveBy = function(x,y){
	this.x+=x;
	this.y+=y;
	this.style.left=this.x;
	this.style.top=this.y;
}

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

elcLayer.prototype.clipValues = function(which){
	var clipv = this.style.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.style.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.style.visibility = 'hidden';
}

elcLayer.prototype.show = function(){
	this.style.visibility = 'visible';
}

elcLayer.prototype.vis = function(){
	if (this.style.visibility=="visible") {
		return true;
	}
}

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

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

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;
}
