I have some code that when the page loads gets the height of an image and then resizes its container div accordingly. This works fine unless its the first time the page has
Try calling your code in $(window).load. This will run after all images have loaded.
$(window).load
$(window).load(function () { // run code });
Or you could try the imgload plugin.