﻿(function ($) {
  $.fn.centerImage = function (maxWidth, maxHeight) {
    var marginLeft = 0;
	  var marginTop = 0;

		if ($(this).attr('complete') && $(this).attr('width') !== 0 && $(this).attr('height') !== 0) {
			if ($(this).attr('width') < maxWidth) {
			    marginLeft = (maxWidth - $(this).attr('width')).toFixed(0) / 2;
			}

			if ($(this).attr('height') < maxHeight) {
			    marginTop = (maxHeight - $(this).attr('height')).toFixed(0) / 2;
			}

			$(this).css('margin', marginTop.toFixed(0) + "px " + marginLeft.toFixed(0) + "px");
		}
  };
})(jQuery);
 

