
Element.implement({
	getCharacterSize: function() {
		var element = this.clone(), size, style;
		style = new Hash(this.getStyles('font-size', 'font-weight')).extend({
			position: 'absolute',
			visibility: 'hidden',
			display: 'block',
			top: 0
		});

		element.setStyles(style).inject(document.body);
		size = element.getSize();
		element.destroy();
		return size;
	},
	getEdges: function(style, offset) {
		var edges = this.getStyle(style).split(' '), n;
		
		//
		if ($type(offset) == false) {
			return edges.map(function(item, index) {
				return item.toInt();
			});
		//
		} else {
			n = (offset == 'height') ? 0 : 1;
			return edges[n].toInt() + edges[n + 2].toInt();
		}
	},
	// Calculate the size of an element add or subtract the margin
	getSizeWithMargin: function() {
		var margin = this.getStyle('margin').split(' '), size = this.getSize();
		
		size.x += margin[1].toInt() + margin[3].toInt();
		size.y += margin[0].toInt() + margin[2].toInt();
		
		return size;
	},
	getElementsWithAssociate: function(filter) {
		var reg = new RegExp("[.]|#", "g"), a = filter.split(',').map(function(item) {
    		return item.trim().replace(reg, '');
		});
		return this.getElements(filter).associate(a);
	},
	diselected: function() {
		with (this) {
			onselectstart = function() { return false; };
			['MozUser', 'KhtmlUser', 'User'].each(function(p) {
				setStyle(p + 'Select', 'none');
			});
		}		
		return this;
	},
	/*
	 * BUG: if not is dom tree, with IE before 
	 *		center element use injectInside, example:
	 *		img.injectInside(container).center(container);
	 */
	center: function(container) {
		var eoo = this.getCoordinates(), coo = container.getCoordinates(), h, w;

		// For image
		h = (eoo && eoo.height) ? eoo.height : this.height;
		w = (eoo && eoo.width) ? eoo.width : this.width;

		this.setStyles({
			'top': -(h / 2) + (coo.height / 2),
			'left': -(w / 2) + (coo.width / 2),
			'height': h,
			'width': w
		});
		return this;
	},	
	setHref: function(h) {
		h = h || 'javascript:void(0);';
		if (this.get('tag') != 'a')
			return this;
		
		return this.set('href', h);
	},
	setBlock: function() {
		return this.setStyle('display', 'block');
	},
	setNone: function() {
		return this.setStyle('display', 'none');
	}
});
