$.fn.center = function(args) {
    
    var args = $.extend({
        // defaults
        top: null  // center horizontally, manually specify top
    }, args || {})
    
    this.each(function() {
		var self = $(this);
        coords = $.get_center(self.outerWidth(), self.outerHeight())
        var left = coords[0], top = coords[1]
		
		if(args.top !== null) {
		    top = args.top
		}
		
    	self.css({top: top, left: left});
   });
};

$.get_center = function(width, height) {        
    var winHeight = $(window).height()
    var winWidth = $(window).width()		
    var top = ((winHeight - height) / 2) + $(window).scrollTop()
    var left = ((winWidth - width) / 2) + $(window).scrollLeft()
    return [left, top]
}