It didn't work beforehand, because you most likely had a jQuery <> Prototype conflict. The wrapping you did shields the dollar variable for jQuery. You could also use:
var $j = jQuery.noConflict();
at the beginning of your script and then use $j instead of $ for all jQuery related stuff.