Index: date_popup/date_popup.module
===================================================================
--- date_popup/date_popup.module	(revision 607)
+++ date_popup/date_popup.module	(working copy)
@@ -35,6 +35,41 @@
 }
 
 /**
+ * Create a unique CSS class name and output a single inline JS block
+ * for each unique combination of startup function to call and
+ * settings array to pass it.  This allows the dynamic use of any
+ * number of custom settings without requiring a duplicate copy for
+ * every element that uses them.
+ *
+ * @param $pfx
+ *   The CSS class prefix to search the DOM for.
+ * @param $func
+ *   The jQuery function to invoke on each DOM element containing the
+ * returned CSS class.
+ * @param $settings
+ *   The settings array to pass to the jQuery function.
+ * @returns
+ *   The CSS class name to assign to an element that should have
+ * $func($settings) invoked on it.
+ */
+function date_popup_js_settings_class($pfx, $func, $settings) {
+  static $cache = array();
+  static $cnt = 0;
+  
+  $serial = serialize($settings);
+  $key = $pfx .':'. $func;
+  if (! isset($cache[$key][$serial])) {
+    $class = $cache[$key][$serial] = $pfx .'-'. $cnt++;
+    drupal_add_js('// Global Killswitch
+    if (Drupal.jsEnabled) {
+      $(document).ready(function() {$(\'.'. $class .'\').'. $func .'({'. $settings. '});
+      })}', 'inline');
+  }
+  return $cache[$key][$serial];
+}
+  
+
+/**
  * Implementation of hook_menu().
  */
 function date_popup_menu($may_cache) {
@@ -235,16 +270,12 @@
     "maxDate: (input.id == 'dFrom' ? getDate($('#dTo').val()) : null) ";
   }
 
-  drupal_add_js('// Global Killswitch
-    if (Drupal.jsEnabled) {
-      $(document).ready(function() {$(\'.jquery-calendar-'. $element['#id'] .'\').calendar({'. $settings. '});
-      })}', 'inline');
-
-  // Create a unique class for each element so we can use custom settings.
+  // Create a unique class for each set of custom settings.
+  $class = date_popup_js_settings_class('jquery-calendar', 'calendar', $settings);
   $sub_element = array(
     '#type' => 'textfield',
     '#default_value' => is_object($date) ? date_format($date, $date_format) : '',
-    '#attributes' => array('class' => 'jquery-calendar-'. $element['#id']),
+    '#attributes' => array('class' => $class),
     '#size' => 20,
     '#maxlength' => 20,
     );
@@ -275,16 +306,12 @@
     "maxTime: (input.id == 'tFrom' ? getTime($('#tTo').val()) : null)} ";
   }
 
-  drupal_add_js('// Global Killswitch
-    if (Drupal.jsEnabled) {
-      $(document).ready(function() {$(\'.jquery-timeentry-'. $element['#id'] .'\').timeEntry({' .$settings. '});
-      })}', 'inline');
-
-  // Create a unique class for each element so we can use custom settings.
+  // Create a unique class for each set of custom settings.
+  $class = date_popup_js_settings_class('jquery-timeentry', 'timeEntry', $settings);
   $sub_element = array(
     '#type' => 'textfield',
     '#default_value' => is_object($date) ? date_format($date, $time_format) : '',
-    '#attributes' => array('class' => 'jquery-timeentry-'. $element['#id']),
+    '#attributes' => array('class' => $class),
     '#size' => 10,
     '#maxlength' => 10,
     );
