(function($) {
  $.fn.scaleImage = function() {
	var image = this		$(image).each(function(){		img = this				$.scaleImage.scale(img)	})	
  }    $.scaleImage = {	scale : function(image) {			if (image.complete) {			if ($(image).attr('scale') != null) {							var scale = $(image).attr('scale')				var image_width = $(image).width()				var image_height = $(image).height()				scale = scale.split(',')				var coefficient = scale[0] / scale[1] // współczynnik skali = szerokość / wysokość								if (coefficient > image_width / image_height) {					var new_width = scale[0]					var new_height = Math.round(image_height * (scale[0] / image_width))				} else {					var new_width = Math.round(image_width * (scale[1] / image_height))					var new_height = scale[1]				}				$(image).css({					width : new_width + 'px',					height: new_height + 'px'				})								$(image).wrap('<div style="overflow:hidden;width:' + scale[0] +'px;height:' + scale[1] + 'px"></div>')								setTimeout(function(){$(image).fadeIn(1000)}, 1000)							}		} else {			setTimeout(function(){$.scaleImage.scale(image)}, 500)		}	}  }
})(jQuery)
