jQuery.fn.center = function() {
        // Always return each...
        return this.each(function() {
                var t = jQuery(this);

                // Set position to other than 'static' so element shrink-wraps and width/height is calculated properly
                t.css({position: 'fixed'});

                //Use this code if you care about IE<7, this requires the dimensions plug-in tho
                // Calculate left and top pos values
                var leftPos = (jQuery(window).width() - jQuery(this).outerWidth()) / 2 + jQuery(window).scrollLeft(),
                        topPos = (jQuery(window).height() - jQuery(this).outerHeight()) / 2 + jQuery(window).scrollTop();

                // Make sure element is not out of bounds
                leftPos = (leftPos < 0) ? 0 : leftPos;
                topPos = (topPos < 0) ? 0 : topPos;

                jQuery(this).css({left: leftPos +'px', top: topPos +'px', zIndex: '1000'});

        });
};

