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
You might want to try this instead:
$(document).ready(function(){ //code here });