Your script looks as if it needs the entire page be loaded before it runs. Are you sure you're running the script after everything is loaded?
<head><script>function init() { //run your script ...}</script></head> <body onload="init();"> ...