// Requires: xelement.js
if(typeof(xElement) == "undefined") alert("xElement Required");

// ||||||||||||||||||||||||||||||||||||||||||||||||||

xElementObject = function(name){
	this.el = xElement.getObject(name);
	this.css = xElement.getStyle(name);
	this.obj = "xElementObject"+name;
	eval(this.obj+"=this");
	return this;
};
xElementObject.prototype.getLeft = function(){
	return parseInt(this.css.left) || 0;
};
xElementObject.prototype.getTop = function(){
	return parseInt(this.css.top) || 0;
};
xElementObject.prototype.setLeft = function(x){
	this.css.left = document.layers ? x : x+"px";
};
xElementObject.prototype.setTop = function(y){
	this.css.top = document.layers ? y : y+"px";
};
xElementObject.prototype.moveTo = function(x,y){
	this.setLeft(x);
	this.setTop(y);
};
xElementObject.prototype.moveBy = function(x,y){
	this.setLeft(this.getLeft()+x);
	this.setTop(this.getTop()+y);
};
xElementObject.prototype.getWidth = function(){
	return document.layers ? this.el.document.width : this.el.offsetWidth;
};
xElementObject.prototype.getHeight = function(){
	return document.layers ? this.el.document.height : this.el.offsetHeight;
};
xElementObject.prototype.setWidth = function(w){
	this.css.width = w+"px";
};
xElementObject.prototype.setHeight = function(h){
	this.css.height = h+"px";
};
xElementObject.prototype.getClipWidth = function(){
	// if(document.layers) return this.el.clip.width || 0;
	var clip = this.getClipObject();
	return clip.right - clip.left || this.getWidth();
};
xElementObject.prototype.getClipHeight = function(){
	// if(document.layers) return this.el.clip.height || 0;
	var clip = this.getClipObject();
	return clip.bottom - clip.top || this.getHeight();
};
xElementObject.prototype.clipTo = function(t,r,b,l){
	if(document.layers){
		this.el.clip.top = t; this.el.clip.right = r; this.el.clip.bottom = b; this.el.clip.left = l;
	}else{
		this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
	}
};
xElementObject.prototype.clipBy = function(t,r,b,l){
	var clip = this.getClipObject();
	this.clipTo(clip.top+t, clip.right+r, clip.bottom+b, clip.left+l);
};
xElementObject.prototype.getClipObject = function(){
	if(document.layers){
		return {top:this.el.clip.top, right:this.el.clip.right, bottom:this.el.clip.bottom, left:this.el.clip.left};
	}else{
		var c = this.css.clip;
		c = c.slice(5, c.length-1);
		c = c.split(" ");
		for(var i=0; i<4; i++){
			c[i] = parseInt(c[i]);
		}
		return {top:c[0],right:c[1],bottom:c[2],left:c[3]};
	}
};
xElementObject.prototype.hideVis = function(){
	this.css.visibility = "hidden";
};
xElementObject.prototype.showVis = function(){
	this.css.visibility = "visible";
};
xElementObject.prototype.setBgColor = function(color){
	if(document.layers){
		this.el.bgColor = color;
	}else{
		this.css.backgroundColor = color;
	}
};
xElementObject.prototype.setBgImage = function(img){
	if(document.layers){
		this.el.background.src = img;
	}else{
		this.css.backgroundImage = "url("+img+")";
	}
};
xElementObject.prototype.setHTML = function(html){
	if(document.layers){
		this.el.document.open("text/html");
		this.el.document.write(html);
		this.el.document.close();
	}else{
		this.el.innerHTML = html;
	}
};
xElementObject.prototype.addEvent = function(event,method){
	xElement.addEvent(this.el,event,method);
};
xElementObject.prototype.removeEvent = function(event){
	xElement.removeEvent(this.el,event);
};
