Drupal javascript file loading and jQuery
By the docs You should wrap your code that way:

(function ($) {

  Drupal.behaviors.exampleModule = {
    attach: function (context, settings) {
      $('.example', context).click(function () {
        $(this).next('ul').toggle('show');
      });
    }
  };

})(jQuery);


What's wrong with other methods? Nothing fundamental, only Drupal's own scripts are not tested to work with them, and redefining $ globally may interfere with non-jQuery libraries some modules use, rendering either their or yours code not working.

For "jQuery is not defined", there are couple of possible problems. My surest bet was to skip drupal_add_js() altogether. Unconditional module (or theme) scripts can be added in info files:

scripts[] = somescript.js


and form related ones can be added directly to a form:

$form['#attached']['js'] = array(
  drupal_get_path('module', 'mymodule') . '/js/a.js',
  drupal_get_path('module', 'mymodule') . '/js/b.js',
);


I prefer to leave conditions in javascript itself, it means I only need one aggregated file for all pages on my site (plus one per form), so this is a performance boost in addition to problem prevention.