(function($) {
	$.fn.center = function(once, only, offset) {
		var width = this.width()
			, height = this.height()
			, winWidth = $(window).width()
			, winHeight = $(window).height()
			, centerX = Math.floor((winWidth - width) / 2)
			, centerY = Math.floor((winHeight - height) / 2)
			, css = {
				'position': 'absolute',
				'left': centerX + 'px',
				'top': centerY + 'px',
				
				/* Reset */
				'right': null,
				'bottom': null,
				'margin': '0px'
			},
			self = this;
		
		this.css(css);
		
		if(typeof once == 'undefined' || once === true) {
			$(window).bind('resize', function() {
				self.center();
			});
		}
		
		if(typeof only == 'string') {
			if(only == 'x') {
				this.css('top', null);
			} else if(only == 'y') {
				this.css('left', null);
			}
		}
		
		if(typeof offset == 'object') {
			if(typeof offset.x === 'number') {
				this.css('left', centerX + offset.x + 'px');
			}
			if(typeof offset.y === 'number') {
				this.css('top', centerY + offset.y + 'px');
			}
		}
		
		return this;
	};	
})(jQuery);
