Fixed nested document ready calls in JS.

There was a really bad js implementation...obviously the person
who wrote the original didn't know anything about javascript.