how to inject JQuery into a D7 page
You can add your code in a JS file say somescript.js and save it in your theme folder. In the theme.info file add the following line

scripts[] = somescript.js


This will add somescript.js to all pages by default. If you want it for a particular page add a conditional check and use drupal_add_js(PATH_TO_JS) 
For more info check out Managing JavaScript in Drupal 7