$j(function()
{
	$j('.mod-images').each(function()
	{
		var that = $j(this);
		
		var maxWidth = that.parent().width();
		
		var handleImage = function()
		{
			var that = $j(this);
			
			var i = 0;
			
			var setMaxWidth = function()
			{
				var width = that.width();
				
				if (width == 0 && i++ !== 10)
				{
					setTimeout(setMaxWidth, 50);
				}
				else if (width > maxWidth)
				{
					that.width(maxWidth);
				}
			};
		};
		
		that.find('img').each(function()
		{
			if (this.complete)
			{
				handleImage();
			}
			else
			{
				this.onload = this.onerror = this.onabort = handleImage;
			}
		});
	});
});
