Q:

window.onload sometimes fires before images have their sizes set

I'm using some jQuery to reposition images and text to the center of the window in a trivial little slideshow. Naturally, I have to wait until the images have been loaded before doing this, otherwise their size is 0 and the image is placed with the top-left at the middle of the page instead of being offset correctly.
To make sure the images are loaded, I attach the javascript function to $(window).load, like this:
$(window).load = start_slideshow()
function center() {
    e = $(this)
    e.css("position","absolute");
    e.css("top", (($(window).height() - e.outerHeight()) / 2) + $(window).scrollTop() + "px");
    e.css("left", (($(window).width() - e.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

function start_slideshow() {
    $(".text").each(center);
    $(".image").each(center);
    $(".slide").each(function() { $(this).hide() } );
    next_slide()
}

This works, most of the time. Yet sometimes when refreshing an image will be off-center with its top-left coordinates at the middle, as if it hadn't been loaded by the time the javascrpt was called. I see this maybe one time in five on mobile Safari.
I'm not doing anything special with the images:
<div class="image">
    <img src="http://4.bp.blogspot.com/_OxhGU7eVQls/TQ_8RSFptmI/AAAAAAAAAF0/2pKKeDQEK1A/s1600/rainPA_468x409.jpg" />
</div>

window.onload is supposed to be after all resources are downloaded, so why would the javascript sometimes be executed before an image has its size set correctly? What's the right way to ensure all images are loaded, if window.onload doesn't do this reliably?

A:

It should be:
$(window).load(start_slideshow)

start_slideshow() will execute the function immediately and assigns the return-value of the function to a property "load" of $(window)

