 (function($) {  
   
 $.fn.centerObject = function(id) {
	
	 
	return this.each(function() {     
		
		var  $this = $(this);
		var bodyMinHeight = $('body').css('min-height');
		
		if (id==null&& $(window).height() > bodyMinHeight.substr(0,(bodyMinHeight.length-2))){		
			if (id==null) {
				var windowHeight = $(window).height();
			} else {
				var windowHeight = $('#'+id).outerHeight();
			}
			
			var elementHeight =  $this.outerHeight();
			
			//Find parents height and substract
			var parentYPos = 0;
			
			if ($this.parent()!=null){
				parentYPos = $this.parent().position().top;
			}
			
			$this.css('top',((windowHeight-elementHeight)/2)-parentYPos+'px');
		}

	});
	
 }  
 })(jQuery);
