SOLVED: Dynamic height / width SOMETIMES broken on page load

SOLVED: Dynamic height / width SOMETIMES broken on page load

I hope someone might have some insight into a funny issue I'm having. I've written a small plugin to serve as a feature rotator and am having one strange problem.

You can see some demos of the plugin and documentation here:

http://pbskids.org/pbskidswidgets/carousel.html

The plugin does a number of things that involve reading the width and height of DOM elements and using them to set the width and height of other elements. The problem is that sometimes in Firefox and Safari, when the page loads, the widths and heights of panels in the carousel are fracked.

Image

Reload the page and the problem's fixed. In Safari, I can't get it to happen again on many reloads. In Firefox, though, if I reload repeatedly, I can get the problem to happen again: maybe once every seven or eight times.

It looks like something's happening with page loading, but I'm at a loss to diagnose it further: is the script firing before the elements have fully loaded sometimes, and then works on subsequent tries because those elements are in the cache? Also: I've never seen this error in any of the IE versions.

Thanks in advance for any help anyone can provide on this. I'm happy to answer any questions to clarify what I'm talking about.