/* Enhancmenets to Mootools */
Element.extend({
	inBounds : function(p,pad) {
		pad = ($chk(pad)) ? pad : 0;
		var c = this.getCoordinates();
		var st = window.getScrollTop(); c.top -= st; c.bottom -= st;
		var sl = window.getScrollLeft(); c.left -= sl; c.right -= sl;
		return  ((p.x >= c.left-pad) && (p.x <= c.right+pad) && (p.y >= c.top-pad) &&	(p.y <= c.bottom+pad));
	},
	
	shift : function(p,y) {
		var unit = ($type(this.style.top) == 'string') ? 'px' : 0;		
		if ($type(p) == 'object') {
			this.setStyles({ 'top' : p.y+unit, 'left' : p.x+unit });
		} else {
			this.setStyles({ 'top' : y+unit, 'left' : x+unit });
		}
	},
	
	getRelPosition : function() {
	    if (this.offsetParent) { return new Coord(this.offsetLeft,this.offsetTop);}
      	if (this.x) { return new Coord(this.x,this.y); }
    	return new Coord(0,0);
	}
});


/* Element Methods */
register("pedro.element");

pedro.element.util = {}

pedro.element.util.display = {
    BLOCK  : "block",
    INLINE : "inline",
    NONE   : "none"
}

pedro.element.util.visbility = {
    HIDDEN   : "hidden",
    COLLAPSE : "collapse",
    INHERIT  : "inherit",
    VISIBLE  : "visible"
}

pedro.element.util.removeAllChildren = function(el) {
  while(el.hasChildNodes())
    el.removeChild(el.firstChild);
}

var Coord = function(x,y){
    this.x = x;
    this.y = y;
}

Coord.prototype.toString = function() { return this.x + "," + this.y; }

Coord.fromMooPos = function(pos) {
	return new Coord(pos.x,pos.y);
}


var BoundingBox = function(tl,br){
    this.tl = tl;
    this.br = br;
}

BoundingBox.prototype.toString = function() { return this.tl + ":" + this.br; }


/* Coord math */

function coordSubtract(a,b){ return new Coord(a.x - b.x, a.y - b.y); }
function coordAdd(a,b){ return new Coord(a.x + b.x, a.y + b.y); }

