(function($) {
	$.fn.centerImage = function(options) {
		var centerImage = function(img) {
			var imgHeight = img.height();
			if (imgHeight == 0)
				return;
			var containerHeight = img.parent().height();
			var diff = (containerHeight - imgHeight)/2;
			if (diff > 0)
				img.css("paddingTop", diff);
		};

		return this.each(function() {
			var $this = $(this);
			if (this.complete) {
				centerImage($this);
			} else {
				$this.load(function() {
					centerImage($this);
				})
			}
		});
	};
})(jQuery);
