Relevant lines are
> var icon = unescape(value.Photo);
> var img = new Image();
> img.src = icon;
> var img_ratio = parseFloat(img.height) / parseFloat(img.width);
Setting img.src to the url is instantaneous and the code moves on; but
the Image() won't have loaded that file by the time the height and
width attributes are required. They are still unset.
What you may be able to do is to use an onload handler to calculate
and use the img_ratio.
var img = new Image();
img.onload = calculateAndDisplay(img);
img.src = icon;
// move everything that needs to happen with the icon into that function
Apparently setting src before onload can be unreliable, so it needs to
be this way round.