/*
Plugin: Center element
Author: Tom van Veen
e-mail: info@tomvanveen.net
usage: $('.el').center(), $('.el').center('vertical'), $('.el').center('horizontal') 
*/

(function( $ ){

	var methods = {
		init : function( options ) {

			return this.each(function(){

				var $this = $(this);
				
				$this.center('vertical');
				$this.center('horizontal');
			
			});
		},
		
		vertical: function(options){
		
			return this.each(function(){
				var $this = $(this);
				$this.css({
					position:	'absolute', 
					top:		'50%',
					marginTop:	'-' + ($this.outerHeight() / 2) + 'px'
				});
			});
		},
		
		horizontal: function(options){
			return this.each(function(){
				var $this = $(this);
				$this.css({
					position:	'absolute', 
					left:		'50%',
					marginLeft:	'-' + ($this.outerWidth() / 2) + 'px'
				});
			});
		}
	};
	

	$.fn.center = function( method ) {

		if ( methods[method] ) {
			return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.center' );
		}
	};

})( jQuery );
