Index: modules/system/system.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.js,v
retrieving revision 1.5
diff -u -r1.5 system.js
--- modules/system/system.js	14 May 2007 16:22:26 -0000	1.5
+++ modules/system/system.js	21 May 2007 18:26:33 -0000
@@ -60,14 +60,14 @@
 /**
  * Show/hide custom format sections on the date-time settings page.
  */
-Drupal.dateTimeAutoAttach = function() {
+Drupal.behaviors.dateTime = function(context) {
   // Show/hide custom format depending on the select's value.
-  $("select.date-format").change(function() {
+  $('select.date-format', context).change(function() {
     $(this).parents("div.date-container").children("div.custom-container")[$(this).val() == "custom" ? "show" : "hide"]();
   });
 
   // Attach keyup handler to custom format inputs.
-  $("input.custom-format").keyup(function() {
+  $('input.custom-format', context).keyup(function() {
     var input = $(this);
     var url = Drupal.settings.dateTime.lookup +(Drupal.settings.dateTime.lookup.match(/\?q=/) ? "&format=" : "?format=") + Drupal.encodeURIComponent(input.val());
     $.getJSON(url, function(data) {
@@ -76,5 +76,11 @@
   });
 
   // Trigger the event handler to show the form input if necessary.
-  $("select.date-format").trigger("change");
+  $('select.date-format', context).trigger('change');
 }
+
+if (Drupal.jsEnabled) {
+  // Clean URLs check should only be run once, so don't register it
+  // as a behavior.
+  $(document).ready(Drupal.cleanURLsSettingsCheck);
+}
\ No newline at end of file
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.479
diff -u -r1.479 system.module
--- modules/system/system.module	21 May 2007 10:56:05 -0000	1.479
+++ modules/system/system.module	21 May 2007 18:26:33 -0000
@@ -652,13 +652,6 @@
     if (strpos(request_uri(), '?q=') !== FALSE) {
       drupal_add_js(array('cleanURL' => array('success' => t('Your server has been successfully tested to support this feature.'), 'failure' => t('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.'), 'testing' => t('Testing clean URLs...'))), 'setting');
       drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module');
-      drupal_add_js('
-// Global Killswitch
-if (Drupal.jsEnabled) {
-  $(document).ready(function() {
-    Drupal.cleanURLsSettingsCheck();
-  });
-}', 'inline');
 
       $form['clean_url']['#description'] .= ' <span>'. t('Before enabling clean URLs, you must perform a test to determine if your server is properly configured. If you are able to see this page again after clicking the "Run the clean URL test" link, the test has succeeded and the radio buttons above will be available. If instead you are directed to a "Page not found" error, you will need to change the configuration of your server. The <a href="@handbook">handbook page on Clean URLs</a> has additional troubleshooting information.', array('@handbook' => 'http://drupal.org/node/15365')) .'</span>';
 
@@ -834,11 +827,7 @@
 function system_date_time_settings() {
   drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module');
   drupal_add_js(array('dateTime' => array('lookup' => url('admin/settings/date-time/lookup'))), 'setting');
-  drupal_add_js('
-// Global Killswitch
-if (Drupal.jsEnabled) {
-  $(document).ready(Drupal.dateTimeAutoAttach);
-}', 'inline');
+
   // Date settings:
   $zones = _system_zonelist();
 
Index: misc/collapse.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/collapse.js,v
retrieving revision 1.11
diff -u -r1.11 collapse.js
--- misc/collapse.js	28 Feb 2007 20:29:38 -0000	1.11
+++ misc/collapse.js	21 May 2007 18:26:32 -0000
@@ -1,5 +1,34 @@
 // $Id: collapse.js,v 1.11 2007/02/28 20:29:38 dries Exp $
 
+Drupal.behaviors.collapse = function (context) {
+  $('fieldset.collapsible > legend', context).each(function() {
+    var fieldset = $(this.parentNode);
+    // Expand if there are errors inside
+    if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
+      fieldset.removeClass('collapsed');
+    }
+
+    // Turn the legend into a clickable link and wrap the contents of the fieldset
+    // in a div for easier animation
+    var text = this.innerHTML;
+    $(this)
+      .empty()
+      .append($('<a href="#">'+ text +'</a>')
+        .click(function() {
+          var fieldset = $(this).parents('fieldset:first')[0];
+          // Don't animate multiple times
+          if (!fieldset.animating) {
+            fieldset.animating = true;
+            Drupal.toggleFieldset(fieldset);
+          }
+          return false;
+        })
+      )
+      .after($('<div class="fieldset-wrapper"></div>')
+      .append(fieldset.children(':not(legend)')));
+  });
+}
+
 /**
  * Toggle the visibility of a fieldset using smooth animations
  */
@@ -43,29 +72,3 @@
     }
   }
 }
-
-// Global Killswitch
-if (Drupal.jsEnabled) {
-  $(document).ready(function() {
-    $('fieldset.collapsible > legend').each(function() {
-      var fieldset = $(this.parentNode);
-      // Expand if there are errors inside
-      if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
-        fieldset.removeClass('collapsed');
-      }
-
-      // Turn the legend into a clickable link and wrap the contents of the fieldset
-      // in a div for easier animation
-      var text = this.innerHTML;
-      $(this).empty().append($('<a href="#">'+ text +'</a>').click(function() {
-        var fieldset = $(this).parents('fieldset:first')[0];
-        // Don't animate multiple times
-        if (!fieldset.animating) {
-          fieldset.animating = true;
-          Drupal.toggleFieldset(fieldset);
-        }
-        return false;
-      })).after($('<div class="fieldset-wrapper"></div>').append(fieldset.children(':not(legend)')));
-    });
-  });
-}
Index: misc/textarea.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/textarea.js,v
retrieving revision 1.14
diff -u -r1.14 textarea.js
--- misc/textarea.js	10 Apr 2007 11:24:16 -0000	1.14
+++ misc/textarea.js	21 May 2007 18:26:33 -0000
@@ -1,8 +1,8 @@
 // $Id: textarea.js,v 1.14 2007/04/10 11:24:16 dries Exp $
 
-Drupal.textareaAttach = function() {
-  $('textarea.resizable:not(.processed)').each(function() {
-    var textarea = $(this).addClass('processed'), staticOffset = null;
+Drupal.behaviors.textarea = function(context) {
+  $('textarea.resizable', context).each(function() {
+    var textarea = $(this), staticOffset = null;
 
     // When wrapping the text area, work around an IE margin bug.  See:
     // http://jaspan.com/ie-inherited-margin-bug-form-elements-and-haslayout
@@ -37,7 +37,3 @@
     }
   });
 }
-
-if (Drupal.jsEnabled) {
-  $(document).ready(Drupal.textareaAttach);
-}
Index: misc/drupal.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/drupal.js,v
retrieving revision 1.31
diff -u -r1.31 drupal.js
--- misc/drupal.js	4 May 2007 09:41:36 -0000	1.31
+++ misc/drupal.js	21 May 2007 18:26:32 -0000
@@ -2,6 +2,8 @@
 
 var Drupal = Drupal || {};
 
+Drupal.behaviors = Drupal.behaviors || {};
+
 /**
  * Set the variable that indicates if JavaScript behaviors should be applied
  */
@@ -220,10 +222,25 @@
   return { 'start': element.selectionStart, 'end': element.selectionEnd };
 }
 
+/**
+ * Attach registered behaviors.
+ */
+Drupal.attachBehaviors = function(context) {
+  context = context || document;
+  if (Drupal.jsEnabled && Drupal.behaviors) {
+    // Execute all of them.
+    jQuery.each(Drupal.behaviors, function() {
+      this(context);
+    });
+  }
+};
+
 // Global Killswitch on the <html> element
 if (Drupal.jsEnabled) {
   // Global Killswitch on the <html> element
   document.documentElement.className = 'js';
   // 'js enabled' cookie
   document.cookie = 'has_js=1';
+  // Attach all behaviors.
+  $(document).ready(Drupal.attachBehaviors);
 }
Index: misc/batch.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/batch.js,v
retrieving revision 1.1
diff -u -r1.1 batch.js
--- misc/batch.js	4 May 2007 09:41:36 -0000	1.1
+++ misc/batch.js	21 May 2007 18:26:32 -0000
@@ -1,31 +1,34 @@
-if (Drupal.jsEnabled) {
-  $(document).ready(function() {
-    $('#progress').each(function () {
-      var holder = this;
-      var uri = Drupal.settings.batch.uri;
-      var initMessage = Drupal.settings.batch.initMessage;
-      var errorMessage = Drupal.settings.batch.errorMessage;
+// $Id: $
 
-      // Success: redirect to the summary.
-      var updateCallback = function (progress, status, pb) {
-        if (progress == 100) {
-          pb.stopMonitoring();
-          window.location = uri+'&op=finished';
-        }
-      }
+/**
+ * Attaches the batch behaviour to progress bars.
+ */
+Drupal.behaviors.batch = function (context) {
+  $('#progress', context).each(function () {
+    var holder = this;
+    var uri = Drupal.settings.batch.uri;
+    var initMessage = Drupal.settings.batch.initMessage;
+    var errorMessage = Drupal.settings.batch.errorMessage;
 
-      var errorCallback = function (pb) {
-        var div = document.createElement('p');
-        div.className = 'error';
-        $(div).html(errorMessage);
-        $(holder).prepend(div);
-        $('#wait').hide();
+    // Success: redirect to the summary.
+    var updateCallback = function (progress, status, pb) {
+      if (progress == 100) {
+        pb.stopMonitoring();
+        window.location = uri+'&op=finished';
       }
+    }
+
+    var errorCallback = function (pb) {
+      var div = document.createElement('p');
+      div.className = 'error';
+      $(div).html(errorMessage);
+      $(holder).prepend(div);
+      $('#wait').hide();
+    }
 
-      var progress = new Drupal.progressBar('updateprogress', updateCallback, "POST", errorCallback);
-      progress.setProgress(-1, initMessage);
-      $(holder).append(progress.element);
-      progress.startMonitoring(uri+'&op=do', 10);
-    });
+    var progress = new Drupal.progressBar('updateprogress', updateCallback, "POST", errorCallback);
+    progress.setProgress(-1, initMessage);
+    $(holder).append(progress.element);
+    progress.startMonitoring(uri+'&op=do', 10);
   });
 }
Index: misc/tableselect.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/tableselect.js,v
retrieving revision 1.1
diff -u -r1.1 tableselect.js
--- misc/tableselect.js	21 Nov 2006 08:16:39 -0000	1.1
+++ misc/tableselect.js	21 May 2007 18:26:32 -0000
@@ -1,5 +1,9 @@
 // $Id: tableselect.js,v 1.1 2006/11/21 08:16:39 unconed Exp $
 
+Drupal.behaviors.tableSelect = function (context) {
+  $('form table[th.select-all]', context).each(Drupal.tableSelect);
+}
+
 Drupal.tableSelect = function() {
   // Keep track of the table, which checkbox is checked and alias the settings.
   var table = this, selectAll, checkboxes, lastChecked, settings = Drupal.settings.tableSelect;
@@ -66,10 +70,3 @@
 
   }
 }
-
-// Global Killswitch
-if (Drupal.jsEnabled) {
-  $(document).ready(function() {
-    $('form table[th.select-all]').each(Drupal.tableSelect);
-  });
-}
Index: misc/upload.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/upload.js,v
retrieving revision 1.11
diff -u -r1.11 upload.js
--- misc/upload.js	31 Aug 2006 23:31:25 -0000	1.11
+++ misc/upload.js	21 May 2007 18:26:33 -0000
@@ -3,8 +3,8 @@
 /**
  * Attaches the upload behaviour to the upload form.
  */
-Drupal.uploadAutoAttach = function() {
-  $('input.upload').each(function () {
+Drupal.behaviors.upload = function(context) {
+  $('input.upload', context).each(function () {
     var uri = this.value;
     // Extract the base name from the id (edit-attach-url -> attach).
     var base = this.id.substring(5, this.id.length - 4);
@@ -108,9 +108,3 @@
     left: '0px'
   });
 }
-
-
-// Global killswitch
-if (Drupal.jsEnabled) {
-  $(document).ready(Drupal.uploadAutoAttach);
-}
Index: misc/tableheader.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/tableheader.js,v
retrieving revision 1.2
diff -u -r1.2 tableheader.js
--- misc/tableheader.js	7 Apr 2007 03:03:40 -0000	1.2
+++ misc/tableheader.js	21 May 2007 18:26:32 -0000
@@ -1,65 +1,66 @@
 // $Id: tableheader.js,v 1.2 2007/04/07 03:03:40 unconed Exp $
 
-// Global Killswitch
-if (Drupal.jsEnabled) {
-  // Keep track of all header cells.
-  var cells = [];
+Drupal.behaviors.tableHeader = function (context) {
 
-  // Attach to all headers.
-  $(document).ready(function() {
-    var z = 0;
-    $('table thead').each(function () {
-      // Find table height.
-      var table = $(this).parent('table')[0];
-      var height = $(table).addClass('sticky-table').height();
-      var i = 0;
-
-      // Find all header cells.
-      $('th', this).each(function () {
-
-        // Ensure each cell has an element in it.
-        var html = $(this).html();
-        if (html == ' ') {
-          html = '&nbsp;';
-        }
-        if ($(this).children().size() == 0) {
-          html = '<span>'+ html +'</span>';
-        }
+  var z = 0;
+  $('table thead', context).each(function () {
+    // Find table height.
+    var table = $(this).parent('table')[0];
+    var height = $(table).addClass('sticky-table').height();
+    var i = 0;
+
+    // Find all header cells.
+    $('th', this).each(function () {
+
+      // Ensure each cell has an element in it.
+      var html = $(this).html();
+      if (html == ' ') {
+        html = '&nbsp;';
+      }
+      if ($(this).children().size() == 0) {
+        html = '<span>'+ html +'</span>';
+      }
 
-        // Clone and wrap cell contents in sticky wrapper that overlaps the cell's padding.
-        $('<div class="sticky-header" style="position: fixed; visibility: hidden; top: 0px;">'+ html +'</div>').prependTo(this);
-        var div = $('div.sticky-header', this).css({
-          'marginLeft': '-'+ $(this).css('paddingLeft'),
-          'marginRight': '-'+ $(this).css('paddingRight'),
-          'paddingLeft': $(this).css('paddingLeft'),
-          'paddingTop': $(this).css('paddingTop'),
-          'paddingBottom': $(this).css('paddingBottom'),
-          'z-index': ++z
-        })[0];
-        cells.push(div);
-
-        // Adjust width to fit cell/table.
-        var ref = this;
-        if (!i++) {
-          // The first cell is as wide as the table to prevent gaps.
-          ref = table;
-          div.wide = true;
-        }
-        $(div).css('width', parseInt($(ref).width())
-                          - parseInt($(div).css('paddingLeft')) +'px');
+      // Clone and wrap cell contents in sticky wrapper that overlaps the cell's padding.
+      $('<div class="sticky-header" style="position: fixed; visibility: hidden; top: 0px;">'+ html +'</div>').prependTo(this);
+      var div = $('div.sticky-header', this).css({
+        'marginLeft': '-'+ $(this).css('paddingLeft'),
+        'marginRight': '-'+ $(this).css('paddingRight'),
+        'paddingLeft': $(this).css('paddingLeft'),
+        'paddingTop': $(this).css('paddingTop'),
+        'paddingBottom': $(this).css('paddingBottom'),
+        'z-index': ++z
+      })[0];
+      Drupal.tableHeaderCells.push(div);
+
+      // Adjust width to fit cell/table.
+      var ref = this;
+      if (!i++) {
+        // The first cell is as wide as the table to prevent gaps.
+        ref = table;
+        div.wide = true;
+      }
+      $(div).css('width', parseInt($(ref).width())
+                        - parseInt($(div).css('paddingLeft')) +'px');
 
-        // Get position and store.
-        div.cell = this;
-        div.table = table;
-        div.stickyMax = height;
-        div.stickyPosition = Drupal.absolutePosition(this).y;
-      });
+      // Get position and store.
+      div.cell = this;
+      div.table = table;
+      div.stickyMax = height;
+      div.stickyPosition = Drupal.absolutePosition(this).y;
     });
   });
+}
+
+// Global Killswitch
+if (Drupal.jsEnabled) {
+
+  // Keep track of all header cells.
+  Drupal.tableHeaderCells = [];
 
   // Track scrolling.
   var scroll = function() {
-    $(cells).each(function () {
+    $(Drupal.tableHeaderCells).each(function () {
       // Fetch scrolling position.
       var scroll = document.documentElement.scrollTop || document.body.scrollTop;
       var offset = scroll - this.stickyPosition - 4;
@@ -88,7 +89,7 @@
         this.height = $(this).height();
       })
 
-      $(cells).each(function () {
+      $(Drupal.tableHeaderCells).each(function () {
         // Get position.
         this.stickyPosition = Drupal.absolutePosition(this.cell).y;
         this.stickyMax = this.table.height;
Index: misc/autocomplete.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/autocomplete.js,v
retrieving revision 1.17
diff -u -r1.17 autocomplete.js
--- misc/autocomplete.js	9 Jan 2007 07:31:04 -0000	1.17
+++ misc/autocomplete.js	21 May 2007 18:26:32 -0000
@@ -3,9 +3,9 @@
 /**
  * Attaches the autocomplete behaviour to all required fields
  */
-Drupal.autocompleteAutoAttach = function () {
+Drupal.behaviors.autocomplete = function (context) {
   var acdb = [];
-  $('input.autocomplete').each(function () {
+  $('input.autocomplete', context).each(function () {
     var uri = this.value;
     if (!acdb[uri]) {
       acdb[uri] = new Drupal.ACDB(uri);
@@ -296,8 +296,3 @@
   if (this.timer) clearTimeout(this.timer);
   this.searchString = '';
 }
-
-// Global Killswitch
-if (Drupal.jsEnabled) {
-  $(document).ready(Drupal.autocompleteAutoAttach);
-}
Index: misc/teaser.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/teaser.js,v
retrieving revision 1.3
diff -u -r1.3 teaser.js
--- misc/teaser.js	9 Apr 2007 13:58:02 -0000	1.3
+++ misc/teaser.js	21 May 2007 18:26:33 -0000
@@ -5,9 +5,9 @@
  *
  * Note: depends on resizable textareas.
  */
-Drupal.teaserAttach = function() {
-  $('textarea.teaser:not(.joined)').each(function() {
-    var teaser = $(this).addClass('joined');
+Drupal.behaviors.teaser = function(context) {
+  $('textarea.teaser', context).each(function() {
+    var teaser = $(this);
 
     // Move teaser textarea before body, and remove its form-item wrapper.
     var body = $('#'+ Drupal.settings.teaser[this.id]);
@@ -74,7 +74,3 @@
 
   });
 }
-
-if (Drupal.jsEnabled) {
-  $(document).ready(Drupal.teaserAttach);
-}
Index: modules/comment/comment.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.js,v
retrieving revision 1.2
diff -u -r1.2 comment.js
--- modules/comment/comment.js	20 May 2007 12:34:47 -0000	1.2
+++ modules/comment/comment.js	21 May 2007 18:26:33 -0000
@@ -1,16 +1,16 @@
 // $Id: comment.js,v 1.2 2007/05/20 12:34:47 dries Exp $
-if (Drupal.jsEnabled) {
-  $(document).ready(function() {
-    var parts = new Array("name", "homepage", "mail");
-    var cookie = '';
-    for (i=0;i<3;i++) {
-      cookie = Drupal.comment.getCookie('comment_info_' + parts[i]);
-      if (cookie != '') {
-        $("#comment-form input[@name=" + parts[i] + "]").val(cookie);
-      }
+
+Drupal.behaviors.comment = function (context) {
+  var parts = new Array("name", "homepage", "mail");
+  var cookie = '';
+  for (i=0;i<3;i++) {
+    cookie = Drupal.comment.getCookie('comment_info_' + parts[i]);
+    if (cookie != '') {
+      $("#comment-form input[@name=" + parts[i] + "]", context)
+        .val(cookie);
     }
-  });
-};
+  }
+}
 
 Drupal.comment = {};
 
Index: modules/color/color.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/color/color.js,v
retrieving revision 1.2
diff -u -r1.2 color.js
--- modules/color/color.js	13 Apr 2007 07:33:23 -0000	1.2
+++ modules/color/color.js	21 May 2007 18:26:33 -0000
@@ -1,247 +1,247 @@
 // $Id: color.js,v 1.2 2007/04/13 07:33:23 dries Exp $
 
-if (Drupal.jsEnabled) {
-  $(document).ready(function () {
-    var form = $('#color_scheme_form .color-form');
-    var inputs = [];
-    var hooks = [];
-    var locks = [];
-    var focused = null;
-
-    // Add Farbtastic
-    $(form).prepend('<div id="placeholder"></div>');
-    var farb = $.farbtastic('#placeholder');
-
-    // Decode reference colors to HSL
-    var reference = Drupal.settings.color.reference;
-    for (i in reference) {
-      reference[i] = farb.RGBToHSL(farb.unpack(reference[i]));
-    }
-
-    // Build preview
-    $('#preview').append('<div id="gradient"></div>');
-    var gradient = $('#preview #gradient');
-    var h = parseInt(gradient.css('height')) / 10;
-    for (i = 0; i < h; ++i) {
-      gradient.append('<div class="gradient-line"></div>');
-    }
-
-    // Fix preview background in IE6
-    if (navigator.appVersion.match(/MSIE [0-6]\./)) {
-      var e = $('#preview #img')[0];
-      var image = e.currentStyle.backgroundImage;
-      e.style.backgroundImage = 'none';
-      e.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image.substring(5, image.length - 2) + "')";
-    }
-
-    // Set up colorscheme selector
-    $('#edit-scheme', form).change(function () {
-      var colors = this.options[this.selectedIndex].value;
-      if (colors != '') {
-        colors = colors.split(',');
-        for (i in colors) {
-          callback(inputs[i], colors[i], false, true);
-        }
-        preview();
+Drupal.behaviors.color = function (context) {
+  var form = $('#color_scheme_form .color-form', context);
+  var inputs = [];
+  var hooks = [];
+  var locks = [];
+  var focused = null;
+
+  // Add Farbtastic
+  $(form)
+    .prepend('<div id="placeholder"></div>');
+  var farb = $.farbtastic('#placeholder');
+
+  // Decode reference colors to HSL
+  var reference = Drupal.settings.color.reference;
+  for (i in reference) {
+    reference[i] = farb.RGBToHSL(farb.unpack(reference[i]));
+  }
+
+  // Build preview
+  $('#preview', context)
+    .append('<div id="gradient"></div>');
+  var gradient = $('#preview #gradient');
+  var h = parseInt(gradient.css('height')) / 10;
+  for (i = 0; i < h; ++i) {
+    gradient.append('<div class="gradient-line"></div>');
+  }
+
+  // Fix preview background in IE6
+  if (navigator.appVersion.match(/MSIE [0-6]\./)) {
+    var e = $('#preview #img')[0];
+    var image = e.currentStyle.backgroundImage;
+    e.style.backgroundImage = 'none';
+    e.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image.substring(5, image.length - 2) + "')";
+  }
+
+  // Set up colorscheme selector
+  $('#edit-scheme', form).change(function () {
+    var colors = this.options[this.selectedIndex].value;
+    if (colors != '') {
+      colors = colors.split(',');
+      for (i in colors) {
+        callback(inputs[i], colors[i], false, true);
       }
-    });
+      preview();
+    }
+  });
 
-    /**
-     * Render the preview.
-     */
-    function preview() {
-      // Solid background
-      $('#preview', form).css('backgroundColor', inputs[0].value);
-
-      // Text preview
-      $('#text', form).css('color', inputs[4].value);
-      $('#text a, #text h2', form).css('color', inputs[1].value);
-
-      // Set up gradient
-      var top = farb.unpack(inputs[2].value);
-      var bottom = farb.unpack(inputs[3].value);
-      if (top && bottom) {
-        var delta = [];
-        for (i in top) {
-          delta[i] = (bottom[i] - top[i]) / h;
+  /**
+   * Render the preview.
+   */
+  function preview() {
+    // Solid background
+    $('#preview', form).css('backgroundColor', inputs[0].value);
+
+    // Text preview
+    $('#text', form).css('color', inputs[4].value);
+    $('#text a, #text h2', form).css('color', inputs[1].value);
+
+    // Set up gradient
+    var top = farb.unpack(inputs[2].value);
+    var bottom = farb.unpack(inputs[3].value);
+    if (top && bottom) {
+      var delta = [];
+      for (i in top) {
+        delta[i] = (bottom[i] - top[i]) / h;
+      }
+      var accum = top;
+
+      // Render gradient lines
+      $('#gradient > div', form).each(function () {
+        for (i in accum) {
+          accum[i] += delta[i];
         }
-        var accum = top;
-
-        // Render gradient lines
-        $('#gradient > div', form).each(function () {
-          for (i in accum) {
-            accum[i] += delta[i];
-          }
-          this.style.backgroundColor = farb.pack(accum);
-        });
-      }
+        this.style.backgroundColor = farb.pack(accum);
+      });
     }
+  }
 
-    /**
-     * Shift a given color, using a reference pair (ref in HSL).
-     *
-     * This algorithm ensures relative ordering on the saturation and luminance
-     * axes is preserved, and performs a simple hue shift.
-     *
-     * It is also symmetrical. If: shift_color(c, a, b) == d,
-     *                        then shift_color(d, b, a) == c.
-     */
-    function shift_color(given, ref1, ref2) {
-      // Convert to HSL
-      given = farb.RGBToHSL(farb.unpack(given));
-
-      // Hue: apply delta
-      given[0] += ref2[0] - ref1[0];
-
-      // Saturation: interpolate
-      if (ref1[1] == 0 || ref2[1] == 0) {
-        given[1] = ref2[1];
+  /**
+   * Shift a given color, using a reference pair (ref in HSL).
+   *
+   * This algorithm ensures relative ordering on the saturation and luminance
+   * axes is preserved, and performs a simple hue shift.
+   *
+   * It is also symmetrical. If: shift_color(c, a, b) == d,
+   *                        then shift_color(d, b, a) == c.
+   */
+  function shift_color(given, ref1, ref2) {
+    // Convert to HSL
+    given = farb.RGBToHSL(farb.unpack(given));
+
+    // Hue: apply delta
+    given[0] += ref2[0] - ref1[0];
+
+    // Saturation: interpolate
+    if (ref1[1] == 0 || ref2[1] == 0) {
+      given[1] = ref2[1];
+    }
+    else {
+      var d = ref1[1] / ref2[1];
+      if (d > 1) {
+        given[1] /= d;
       }
       else {
-        var d = ref1[1] / ref2[1];
-        if (d > 1) {
-          given[1] /= d;
-        }
-        else {
-          given[1] = 1 - (1 - given[1]) * d;
-        }
+        given[1] = 1 - (1 - given[1]) * d;
       }
+    }
 
-      // Luminance: interpolate
-      if (ref1[2] == 0 || ref2[2] == 0) {
-        given[2] = ref2[2];
+    // Luminance: interpolate
+    if (ref1[2] == 0 || ref2[2] == 0) {
+      given[2] = ref2[2];
+    }
+    else {
+      var d = ref1[2] / ref2[2];
+      if (d > 1) {
+        given[2] /= d;
       }
       else {
-        var d = ref1[2] / ref2[2];
-        if (d > 1) {
-          given[2] /= d;
-        }
-        else {
-          given[2] = 1 - (1 - given[2]) * d;
-        }
+        given[2] = 1 - (1 - given[2]) * d;
       }
-
-      return farb.pack(farb.HSLToRGB(given));
     }
 
-    /**
-     * Callback for Farbtastic when a new color is chosen.
-     */
-    function callback(input, color, propagate, colorscheme) {
-      // Set background/foreground color
-      $(input).css({
-        backgroundColor: color,
-        color: farb.RGBToHSL(farb.unpack(color))[2] > 0.5 ? '#000' : '#fff'
-      });
+    return farb.pack(farb.HSLToRGB(given));
+  }
 
-      // Change input value
-      if (input.value && input.value != color) {
-        input.value = color;
-
-        // Update locked values
-        if (propagate) {
-          var i = input.i;
-          for (j = i + 1; ; ++j) {
-            if (!locks[j - 1] || $(locks[j - 1]).is('.unlocked')) break;
-            var matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
-            callback(inputs[j], matched, false);
-          }
-          for (j = i - 1; ; --j) {
-            if (!locks[j] || $(locks[j]).is('.unlocked')) break;
-            var matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
-            callback(inputs[j], matched, false);
-          }
+  /**
+   * Callback for Farbtastic when a new color is chosen.
+   */
+  function callback(input, color, propagate, colorscheme) {
+    // Set background/foreground color
+    $(input).css({
+      backgroundColor: color,
+      color: farb.RGBToHSL(farb.unpack(color))[2] > 0.5 ? '#000' : '#fff'
+    });
 
-          // Update preview
-          preview();
+    // Change input value
+    if (input.value && input.value != color) {
+      input.value = color;
+
+      // Update locked values
+      if (propagate) {
+        var i = input.i;
+        for (j = i + 1; ; ++j) {
+          if (!locks[j - 1] || $(locks[j - 1]).is('.unlocked')) break;
+          var matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
+          callback(inputs[j], matched, false);
+        }
+        for (j = i - 1; ; --j) {
+          if (!locks[j] || $(locks[j]).is('.unlocked')) break;
+          var matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
+          callback(inputs[j], matched, false);
         }
 
-        // Reset colorscheme selector
-        if (!colorscheme) {
-          resetScheme();
-        }
+        // Update preview
+        preview();
       }
 
+      // Reset colorscheme selector
+      if (!colorscheme) {
+        resetScheme();
+      }
     }
 
-    /**
-     * Reset the color scheme selector.
-     */
-    function resetScheme() {
-      $('#edit-scheme', form).each(function () {
-        this.selectedIndex = this.options.length - 1;
-      });
-    }
-
-    // Focus the Farbtastic on a particular field.
-    function focus() {
-      var input = this;
-      // Remove old bindings
-      focused && $(focused).unbind('keyup', farb.updateValue)
-          .unbind('keyup', preview).unbind('keyup', resetScheme)
-          .parent().removeClass('item-selected');
-
-      // Add new bindings
-      focused = this;
-      farb.linkTo(function (color) { callback(input, color, true, false) });
-      farb.setColor(this.value);
-      $(focused).keyup(farb.updateValue).keyup(preview).keyup(resetScheme)
-        .parent().addClass('item-selected');
-    }
-
-    // Initialize color fields
-    $('#palette input.form-text', form)
-    .each(function () {
-      // Extract palette field name
-      this.key = this.id.substring(13);
-
-      // Link to color picker temporarily to initialize.
-      farb.linkTo(function () {}).setColor('#000').linkTo(this);
-
-      // Add lock
-      var i = inputs.length;
-      if (inputs.length) {
-        var lock = $('<div class="lock"></div>').toggle(
-          function () {
-            $(this).addClass('unlocked');
-            $(hooks[i - 1]).attr('class',
-              locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook up' : 'hook'
-            );
-            $(hooks[i]).attr('class',
-              locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook down' : 'hook'
-            );
-          },
-          function () {
-            $(this).removeClass('unlocked');
-            $(hooks[i - 1]).attr('class',
-              locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook both' : 'hook down'
-            );
-            $(hooks[i]).attr('class',
-              locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook both' : 'hook up'
-            );
-          }
-        );
-        $(this).after(lock);
-        locks.push(lock);
-      }
-
-      // Add hook
-      var hook = $('<div class="hook"></div>');
-      $(this).after(hook);
-      hooks.push(hook);
-
-      $(this).parent().find('.lock').click();
-      this.i = i;
-      inputs.push(this);
-    })
-    .focus(focus);
+  }
 
-    $('#palette label', form)
-
-    // Focus first color
-    focus.call(inputs[0]);
+  /**
+   * Reset the color scheme selector.
+   */
+  function resetScheme() {
+    $('#edit-scheme', form).each(function () {
+      this.selectedIndex = this.options.length - 1;
+    });
+  }
 
-    // Render preview
-    preview();
-  });
-}
\ No newline at end of file
+  // Focus the Farbtastic on a particular field.
+  function focus() {
+    var input = this;
+    // Remove old bindings
+    focused && $(focused).unbind('keyup', farb.updateValue)
+        .unbind('keyup', preview).unbind('keyup', resetScheme)
+        .parent().removeClass('item-selected');
+
+    // Add new bindings
+    focused = this;
+    farb.linkTo(function (color) { callback(input, color, true, false) });
+    farb.setColor(this.value);
+    $(focused).keyup(farb.updateValue).keyup(preview).keyup(resetScheme)
+      .parent().addClass('item-selected');
+  }
+
+  // Initialize color fields
+  $('#palette input.form-text', form)
+  .each(function () {
+    // Extract palette field name
+    this.key = this.id.substring(13);
+
+    // Link to color picker temporarily to initialize.
+    farb.linkTo(function () {}).setColor('#000').linkTo(this);
+
+    // Add lock
+    var i = inputs.length;
+    if (inputs.length) {
+      var lock = $('<div class="lock"></div>').toggle(
+        function () {
+          $(this).addClass('unlocked');
+          $(hooks[i - 1]).attr('class',
+            locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook up' : 'hook'
+          );
+          $(hooks[i]).attr('class',
+            locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook down' : 'hook'
+          );
+        },
+        function () {
+          $(this).removeClass('unlocked');
+          $(hooks[i - 1]).attr('class',
+            locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook both' : 'hook down'
+          );
+          $(hooks[i]).attr('class',
+            locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook both' : 'hook up'
+          );
+        }
+      );
+      $(this).after(lock);
+      locks.push(lock);
+    }
+
+    // Add hook
+    var hook = $('<div class="hook"></div>');
+    $(this).after(hook);
+    hooks.push(hook);
+
+    $(this).parent().find('.lock').click();
+    this.i = i;
+    inputs.push(this);
+  })
+  .focus(focus);
+
+  $('#palette label', form)
+
+  // Focus first color
+  focus.call(inputs[0]);
+
+  // Render preview
+  preview();
+}
Index: modules/user/user.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.js,v
retrieving revision 1.1
diff -u -r1.1 user.js
--- modules/user/user.js	20 May 2007 16:38:19 -0000	1.1
+++ modules/user/user.js	21 May 2007 18:26:33 -0000
@@ -5,10 +5,8 @@
  * picture-related form elements depending on the current value of the
  * "Picture support" radio buttons.
  */
-if (Drupal.jsEnabled) {
-  $(document).ready(function () {
-    $('div.user-admin-picture-radios input[@type=radio]').click(function () {
-      $('div.user-admin-picture-settings')[['hide', 'show'][this.value]]();
-    });
+Drupal.behaviors.user = function () {
+  $('div.user-admin-picture-radios input[@type=radio]').click(function () {
+    $('div.user-admin-picture-settings')[['hide', 'show'][this.value]]();
   });
 }
