The following is a combination of several posts on Dean Edwards’ blog as well as an onload handler for those browsers that don’t support this kind of solution that I found elsewhere. This may not work in Opera, I am not sure. According to the second post Opera supports DOMContentLoaded but I don’t know if this code will catch Opera properly.
UPDATE: fixed the code above. WordPress was screwing up the last bit due to its insistence on changing the preformatted HTML in the code.