Replacing the auto-size code to use jQuery.

The reason for this is that we should use the size of the nearest
ancestor element of the IMG tag, and use its width as a reference for
the image size.