Index: vertical_tabs.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vertical_tabs/vertical_tabs.module,v
retrieving revision 1.1.2.12
diff -u -r1.1.2.12 vertical_tabs.module
--- vertical_tabs.module	5 Jan 2009 23:37:01 -0000	1.1.2.12
+++ vertical_tabs.module	5 Jan 2009 23:47:04 -0000
@@ -37,14 +37,17 @@
     // The javascript to add to the page.
     $settings = array();
     // Iterate through the form, finding fieldsets.
-    foreach (element_children($form) as $key) {
+    foreach (element_children($form) as $delta => $key) {
       // We need to make sure that the element we have is a fieldset
       // and the user has access to this field.
       if (isset($fieldsets[$key]) &&
         (isset($form[$key]['#type']) && $form[$key]['#type'] == 'fieldset') &&
         (!isset($form[$key]['#access']) || $form[$key]['#access'] != FALSE)) {
         // Add the JavaScript.
-        $settings[$key] = array('name' => $form[$key]['#title']);
+        $settings[$key] = array(
+          'name' => $form[$key]['#title'],
+          'weight' => $form[$key]['#weight'] + (0.01 * $delta),
+        );
         // If there's a summary callback, then add it.
         if (isset($form[$key]['#summary_callback']) || isset($fieldsets[$key])) {
           $settings[$key]['callback'] = (isset($form[$key]['#summary_callback']) ? $form[$key]['#summary_callback'] : $fieldsets[$key]);
@@ -80,6 +83,9 @@
         }
       }
 
+      // User sort orders by the "weight" key.
+      uasort($settings, '_user_sort');
+
       // Build necessary classes on the DIV.
       $classes = array('vertical-tabs');
 
