jQuery.fn.imgSize = function(deep,callback){
	callback = callback || deep;
	var $images = this.filter("IMG[src]");
	if(deep) $images.add( this.find("IMG[src]") );
	
	$images.each(function(){
		var origImg = this;
		var url = $(origImg).attr("src");
		
		$("<img>").load(function(){
			var $dummy = $(this), size = { width:$dummy.width(), height:$dummy.height(), fileSize:0 };
			try{ size.fileSize = parseInt($dummy.attr("fileSize")) || 0 }catch(e){};
			jQuery.isFunction(callback) && callback.apply( origImg, [size,this] );
			$dummy.remove();
		})
		// To be on the safe side, apply inline styles to prevent any css styles affecting our measurements:
		// (We use a try-catch workaround for IE7 because it raises errors when we try to set maxWidth/maxHeight)
		.css({ display:"none", width:"auto", height:"auto", minWidth:"auto", minHeight:"auto" })
		.each(function(){ try{ $(this).css({ maxWidth:"auto", maxHeight:"auto" }) }catch(e){}; })
		.addClass("imgSize-temp-img")
		.appendTo(document.body)    // The width/height would be zero if img is not added to DOM.
		.attr({ src:url });
	
	});
	return this;
}

