With the help of a friend of mine, it turned out what was the problem with the above code.
When document.ready is executed, jquery is not on the page (there are two onReady elements) ... and since the addToHead version does not block, the rest of javascript is executed in parallel and not executed.
I added this immediately after running the body tag, and it works great:
<script type="text/javascript"> if (typeof jQuery == 'undefined') { document.write('<scr'+'ipt type="text/javascript" src="http://ajax.googleapis.com /ajax/libs/jquery/1.7.1/jquery.min.js">'+'</scr'+'ipt>'); } </script>
source share