How can I insert Javascript right before the body in my custom theme?
Not sure this helps but I had a similar problem before. I solved it by using the jQuery syntax instead of the $, like so:

jQuery(window).load(function() {
    jQuery('#a a').css({'background-position','-20px 55px'});
    // and so on
});


You could load your js file by calling the drupal_add_js() in the THEME_preprocess_page() hook in your template.php file.