(function($){  
	$.fn.centerme = function(options) {  

		// load the options
		var o = $.extend({}, $.fn.centerme.defaults, options);
		
		// set the default equal to the DOM element dimensions
		if ( !o.fullWindow ) {
			if (o.width == 0) o.width = $(this).width();
			if (o.height == 0) o.height = $(this).height();
		} else {ro
			o.width = $(window).width();
			o.height = $(window).height();
		}
		
		// set the options inside of the DOM element
		this[0][0] = o;
      
		return this.each(function() {
			// instantiate the object we'll use to pass to the private functions
			var obj = $(this);  
			
			// center DOM element(s) the first time the plugin is called
			move(obj);
			
			// center DOM element(s) when the window is resized
			$(window).resize(function() {
				move(obj);
			});
			
			// center DOM element(s) when the window is scrolled
			$(window).scroll(function() {
				move(obj)
			}); 
		});  
	};  
	
	// move the DOM element to the center of the window
	function move(obj) {
		// get the position to move to
		var css_output = getposition(obj);
		
		// reposition the DOM element(s)
		obj.css(css_output);
	};
	
	// get the position to move the DOM element to
	function getposition(obj){
		// get the options from the DOM array position 0,0
		o = obj[0][0];
		
		// set the dimensions
		var wheight = $(window).height();
		var wwidth = $(window).width();
		var wtop = $(window).scrollTop();
		var vpos = wheight/2
		
		var xoffset = -1*o.height/2;
		var yoffset = -1*o.width/2;
		
		o.height = ( o.fullWindow ) ? wheight : o.height;
		o.width = ( o.fullWindow ) ? wwidth : o.width;
		
		// define the CSS
		var css_output = {
			'top' : vpos,
			'left' : '50%',
			'margin' : xoffset + 'px 0 0 ' + yoffset + 'px',
			'height' : o.height,
			'width' : o.width
		}
		//console.log(o);
		//console.log(vpos,wtop,wheight);
		return css_output
	}
	
	// expose defaults to allow users to define them independently
	$.fn.centerme.defaults = {
		width: 0,  
		height: 0,
		fullWindow: false
	}
})(jQuery); 

