/**
 * This function transforms coordinates from one coordinate system(CS) to other.
 * Example:
 * We got coordinates which in CS of page and the element must be shown in this point.
 * But we need position DOM-element absolutely inside positioned parent(position:relative/absolute/fixed).
 * And parent can be positioned too. So we take into consideration recursive positioning.
 *
 * @author  andrew
 * 
 */

(function($){
    $.fn.offsetToPage = function(left,top){
	left = parseInt(left);
	top = parseInt(top);
	return this.each(function(){
	    $(this).show();
	    var ofParent = $(this).offsetParent();
	    //alert(ofParent[0].tagName);
	    //if ie6,7 HTML is before BODY:)
	    while(ofParent[0].tagName!="BODY" && ofParent[0].tagName!="HTML"){
		left -= ofParent.offset().left;
		top -= ofParent.offset().top;
		ofParent = ofParent.offsetParent();
		//alert(ofParent[0].tagName+" left = "+left + " top = "+top);
	    }
	    $(this).css({left: left+'px', top: top+'px'});
	});
    }
})(jQuery);