Element.extend({
	/**
	 * get dom element X position
	 */
	getX : function(){
		var obj = this;
	    return obj.offsetLeft + (obj.offsetParent ? obj.offsetParent.getX() : obj.x ? obj.x : 0);
	},
	
	/**
	 * get dom element Y position
	 */      
	getY : function(){
		var obj = this;
	    return (obj.offsetParent ? obj.offsetTop + obj.offsetParent.getY() : obj.y ? obj.y : 0);
	},
	
	/**
	 * YUI getXY interface
	 */
	getXY : function() {
		var el = this;
		var isSafari = (document.childNodes && !document.all && !navigator.taintEnabled);
		var ROOT_TAG = /^body|html$/i;
        if (document.documentElement.getBoundingClientRect) { // IE
			var box = el.getBoundingClientRect();

			var rootNode = el.ownerDocument;
			return [box.left + this.getDocumentScrollLeft(rootNode), box.top +
					this.getDocumentScrollTop(rootNode)];
        } else {
            var pos = [el.offsetLeft, el.offsetTop];
			var parentNode = el.offsetParent;

			// safari: subtract body offsets if el is abs (or any offsetParent), unless body is offsetParent
			var accountForBody = (isSafari &&
					el.style['position'] == 'absolute' &&
					el.offsetParent == el.ownerDocument.body);

			if (parentNode != el) {
				while (parentNode) {
					pos[0] += parentNode.offsetLeft;
					pos[1] += parentNode.offsetTop;
					if (!accountForBody && isSafari && 
							parentNode.style['position'] == 'absolute' ) { 
						accountForBody = true;
					}
					parentNode = parentNode.offsetParent;
				}
			}

			if (accountForBody) { //safari doubles in this case
				pos[0] -= el.ownerDocument.body.offsetLeft;
				pos[1] -= el.ownerDocument.body.offsetTop;
			} 
			parentNode = el.parentNode;

			// account for any scrolled ancestors
			while ( parentNode.tagName && !ROOT_TAG.test(parentNode.tagName) ) 
			{
			   // work around opera inline/table scrollLeft/Top bug
			   if (parentNode.style['display'].search(/^inline|table-row.*$/i)) { 
					pos[0] -= parentNode.scrollLeft;
					pos[1] -= parentNode.scrollTop;
				}
				
				parentNode = parentNode.parentNode; 
			}

			return pos;
        }
	},
	/**
	 * Returns the left scroll value of the document 
	 * @method getDocumentScrollLeft
	 * @param {HTMLDocument} document (optional) The document to get the scroll value of
	 * @return {Int}  The amount that the document is scrolled to the left
	 */
	getDocumentScrollLeft : function(doc) {
		doc = doc || document;
		return Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);
	}, 

	/**
	 * Returns the top scroll value of the document 
	 * @method getDocumentScrollTop
	 * @param {HTMLDocument} document (optional) The document to get the scroll value of
	 * @return {Int}  The amount that the document is scrolled to the top
	 */
	getDocumentScrollTop : function(doc) {
		doc = doc || document;
		return Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
	}
});