/*
		dw_clip.js
		clip methods for use with dw_core.js
		
		This code is from Dynamic Web Coding 
    www.dyn-web.com 
    Permission granted to use this code 
    as long as this entire notice is included.
*/



// ideas from dynduo, brainjar and bratta
dynObj.prototype.getClipValues = function() {
	var clipVal = new Array();
  if (typeof this.css.clip != "undefined" && typeof this.css.clip.top == "undefined") {
		clipVal = this.css.clip.substring(5,this.css.clip.length-1).split(' ');
			for (var i=0; i<4; i++) {
				clipVal[i] = parseInt(clipVal[i]);
			}
  } else if (typeof this.css.clip.top != "undefined") {
		clipVal[0] = this.css.clip.top;
		clipVal[1] = this.css.clip.right;
		clipVal[2] = this.css.clip.bottom;
		clipVal[3] = this.css.clip.left;
	}
	return clipVal;
}

dynObj.prototype.clipBy = function(top,rt,btm,lft) {
	if (typeof this.css.clip != "undefined" && typeof this.css.clip.top == "undefined") {
		var clipVal = this.getClipValues();
  	this.css.clip = "rect(" + Number(clipVal[0]+top) + "px, " + Number(clipVal[1]+rt)  + "px, " + Number(clipVal[2]+btm) + "px, " + Number(clipVal[3]+lft) + "px)"
  } else if (typeof this.css.clip.top != "undefined") {
  	this.css.clip.top += top;
		this.css.clip.right += rt;
		this.css.clip.bottom += btm;
		this.css.clip.left += lft;
  }
}

dynObj.prototype.clipTo = function(top,rt,btm,lft) {
	 if (typeof this.css.clip != "undefined" && typeof this.css.clip.top == "undefined") {
  	this.css.clip = "rect("+top+"px, "+rt+"px, "+btm+"px, "+lft+"px)";
  } else if (typeof this.css.clip.top != "undefined") {
  	this.css.clip.top = top;
		this.css.clip.right = rt;
		this.css.clip.bottom = btm;
		this.css.clip.left = lft;
  }
}
