jQuery.fn.center = function() {
    return this.each(function() {
        $(this).css("left", (($(document).width() / 2) - ($(this).width() / 2)) + "px").css("top", (($(window).height() / 2) - ($(this).height() / 2)) + "px");
    });
}

jQuery.fn.centerOnObject = function(obj) {
    return this.each(function(i) {
        $(this).css("left", obj.position().left + (obj.width() / 2) - ($(this).outerWidth() / 2) + "px");
        $(this).css("top", obj.position().top + (obj.height() / 2) - ($(this).outerHeight() / 2) + "px");
    });
}