jQuery(document).ready(function() {
     jQuery.fn.extend({
          center: function (options) {
               var options =  jQuery.extend({ // Default values
                    inside:window, // element, center into window
                    transition: 0, // millisecond, transition time
                    minX:0, // pixel, minimum left element value
                    minY:0, // pixel, minimum top element value
                    withScrolling:true, // booleen, take care of the scrollbar (scrollTop)
                    vertical:true, // booleen, center vertical
                    horizontal:true // booleen, center horizontal
               }, options);
               return this.each(function() {
                    var props = {position:'absolute'};
                    if (options.vertical) {
                         var top = (jQuery(options.inside).height() - jQuery(this).outerHeight()) / 2;
                         if (options.withScrolling) top += jQuery(options.inside).scrollTop() || 0;
                         top = (top > options.minY ? top : options.minY);
                         jQuery.extend(props, {top: top+'px'});
                    }
                    if (options.horizontal) {
                          var left = (jQuery(options.inside).width() - jQuery(this).outerWidth()) / 2;
                          if (options.withScrolling) left += jQuery(options.inside).scrollLeft() || 0;
                          left = (left > options.minX ? left : options.minX);
                          jQuery.extend(props, {left: left+'px'});
                    }
                    if (options.transition > 0) jQuery(this).animate(props, options.transition);
                    else jQuery(this).css(props);
                    return jQuery(this);
               });
          }
     });
});
