--- automodal.module	2010-06-24 17:10:04.000000000 -0700
+++ automodal.module	(working copy)
@@ -81,6 +81,17 @@ function automodal_init() {
   elseif (variable_get('automodal_autoscan', 0)) {
     automodal_add_automodal();
   }
+
+  // Adding hook_automodal
+  $automodal = automodal_get_automodal();
+
+  foreach ($automodal as $path => $automodal_config) {
+    foreach ($automodal_config as $selector => $settings) {
+      if ($path == $_GET['q'] || (strpos($path, '*') !== FALSE && drupal_match_path($_GET['q'], $path))) {
+        automodal_add_automodal($settings, $selector);
+      }
+    }
+  }
 }
 
 /**
@@ -122,6 +133,34 @@ function automodal_test() {
   return t('It works!');
 }
 
+/**
+ * Define hook_automodal()
+ * Build the list of automodal rules from all modules that implement hook_automodal.
+ *
+ * Retrieves the list of automodal rules from all modules that implement hook_automodal.
+ *
+ * @param $reset
+ * (optional) if set to TRUE, forces the automodal rule cache to reset.
+ *
+ */
+function automodal_get_automodal($reset = FALSE) {
+ static $automodal = NULL;
+  if (!isset($automodal) || $reset) {
+    // Get automodal hash out of cache.
+    if (!$reset && ($cache = cache_get('automodal:automodal')) && !empty($cache->data)) {
+      $automodal = $cache->data;
+    }
+    else { 
+      // Call all hook_automodal and cache results.
+      $automodal = module_invoke_all('automodal');
+      
+      // Save the popup registry in the cache.      
+      cache_set('automodal:automodal', $automodal);
+    }  
+  }
+  return $automodal;
+}
+
 function automodal_add_automodal($automodal_settings = array(), $automodal_selector = '') {
   static $automodal_processed;
   
