jQuery.fn.elementLocation = function() {
    var curleft = 0;
    var curtop = 0;
    var obj = this;
    do {
        curleft += obj.attr('offsetLeft');
        curtop += obj.attr('offsetTop');
        obj = obj.offsetParent();
    } while ( obj.attr('tagName') != 'BODY' && obj.css('position') != 'relative' && obj.css('position') != 'absolute');
    return ( {x:curleft, y:curtop} );
};
jQuery.fn.elementAbsoluteLocation = function() {
    var curleft = 0;
    var curtop = 0;
    var obj = this;
    do {
        curleft += obj.attr('offsetLeft');
        curtop += obj.attr('offsetTop');
        obj = obj.offsetParent();
    } while ( obj.attr('tagName') != 'BODY');
    return ( {x:curleft, y:curtop} );
};
jQuery.fn.center = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position:    absolute ? 'absolute' : 'fixed', 
            left:        '50%', 
            top:        '50%', 
            zIndex:        '99999'
        }).css({
            marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
            marginTop:    '-' + (t.outerHeight() / 2) + 'px'
        });

        if (absolute) {
            t.css({
                marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};
