Index: cck_fieldgroup_tabs.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_fieldgroup_tabs/cck_fieldgroup_tabs.module,v
retrieving revision 1.1
diff -u -r1.1 cck_fieldgroup_tabs.module
--- cck_fieldgroup_tabs.module	7 Aug 2007 04:04:47 -0000	1.1
+++ cck_fieldgroup_tabs.module	25 Sep 2007 03:00:40 -0000
@@ -18,15 +18,20 @@
     if (arg(0) == 'admin') {
       return;
     }
-    $tabset = FALSE;
     foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) {
       if (isset($form[$group_name]) && $group['settings']['form']['style'] == 'tabs') {
         // Add a tabset if not already added.
-        if (!$tabset) {
+        if (!isset($form['fieldgroup_tabs'])) {
           $form['fieldgroup_tabs'] = array(
             '#type' => 'tabset',
+            '#weight' => $group['weight'],
           );
-          $tabset = TRUE;
+        }
+        // Otherwise, reset the weight if lower than what's already set.
+        // This ensures the tabset has the weight of the lowest fieldgroup
+        // it includes.
+        else if ($group['weight'] < $form['fieldgroup_tabs']['#weight']) {
+          $form['fieldgroup_tabs']['#weight'] = $group['weight'];
         }
         $element = $form[$group_name];
         $element['#type'] = 'tabpage';
@@ -54,16 +59,21 @@
   switch ($op) {
     case 'view':
       $context = $teaser ? 'teaser' : 'full';
-      $tabset = FALSE;
       foreach (fieldgroup_groups($node->type) as $group_name => $group) {
         // $node->content[$group_name] will be set only if there was visible content.
         if (isset($node->content[$group_name]) && $group['settings']['display'][$context] == 'tabs') {
           // Add a tabset if not already added.
-          if (!$tabset) {
+          if (!isset($node->content['fieldgroup_tabs'])) {
             $node->content['fieldgroup_tabs'] = array(
               '#type' => 'tabset',
+              '#weight' => $group['weight'],
             );
-            $tabset = TRUE;
+          }
+          // Otherwise, reset the weight if lower than what's already set.
+          // This ensures the tabset has the weight of the lowest fieldgroup
+          // it includes.
+          else if ($group['weight'] < $node->content['fieldgroup_tabs']['#weight']) {
+            $node->content['fieldgroup_tabs']['#weight'] = $group['weight'];
           }
           $element = $node->content[$group_name];
           $element['#type'] = 'tabpage';
