Where to initialize module specific variables
hook_init() is always invoked for not cached pages, even for AJAX request. You can verify the page request is made because an AJAX request, though. 

There are two conditions that should be common on any AJAX request:


The menu path is system/ajax
The delivery callback is ajax_deliver()


While the first condition is only true when the form element doesn't set #ajax['path'],  the second condition should always be true.

Code similar to the following one should detect when a menu callback is called because an AJAX request.

if ($router_item = menu_get_item()) {
  if (isset($route_item['delivery_callback']) &amp;&amp; $route_item['delivery_callback'] == 'ajax_deliver') {
    // It is an AJAX call.
  }
}


In Drupal 6, the menu callback for AJAX/AHAH requests changes, and each menu has its own callback. You can notice the path for those menu callbacks follows a specific pattern: It usually ends with /js, but that is not necessarily true. This means a menu callback could be associated with a path ending with /js, but that menu callback is not for a AJAX/AHAH request.