Improved Javascript to decide next/prev image sizes.