Index: image_attach.module
===================================================================
--- image_attach.module	(revision 7)
+++ image_attach.module	(revision 10)
@@ -127,7 +127,7 @@
     foreach (image_get_sizes() as $key => $size) {
       $image_sizes[$key] = $size['label'];
     }
-    
+
     $form['image_attach'] = array(
       '#type' => 'fieldset',
       '#title' => t('Image Attach settings'),
@@ -167,6 +167,30 @@
       '#default_value' => variable_get('image_attach_weight_body_'. $form['#node_type']->type, 0),
       '#description' => t("This value determines the order of the image when displayed in the body."),
     );
+    
+    // CCK integration
+    if (module_exists('content')) {
+      $content_type = content_types($form['#node_type']->type);
+      $form['image_attach']['cck'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('CCK integration'),
+        '#collapsible' => FALSE,
+        '#description' => t("This settings control integration with CCK. These are ignored if no fields are configured for this content type."),
+      );
+      $form['image_attach']['cck']['image_attach_weight_teaser_cck'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Leave CCK to set teaser image weight'),
+        '#default_value' => variable_get('image_attach_weight_teaser_cck_'. $form['#node_type']->type, 0),
+        '#description' => t("This value determines if CCK handles the order of the image when displayed in the teaser.<br/>If enabled the value of setting 'Teaser image weight' is ignored"),
+      );
+      $form['image_attach']['cck']['image_attach_weight_body_cck'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Leave CCK to set full node image weight'),
+        '#default_value' => variable_get('image_attach_weight_body_cck_'. $form['#node_type']->type, 0),
+        '#description' => t("This value determines if CCK handles the order of the image when displayed in the body.<br/>If enabled the value of setting 'Full node image weight' is ignored"),
+      );
+      $form['#validate'][] = 'image_attach_node_type_form_validate';
+    }   
   }
   // Node edit form.
   else if (isset($form['type']) && $form['type']['#value'] != 'image') {
@@ -227,6 +251,21 @@
 }
 
 /**
+ * Validate node type form settings.
+ */
+function image_attach_node_type_form_validate($form, &$form_state) {
+  // Validate CCK integration settings
+  if (module_exists('content')) {
+    $content_type = content_types($form['#node_type']->type);
+    if (empty($content_type['fields']) && ($form_state['values']['image_attach_weight_teaser_cck'] || $form_state['values']['image_attach_weight_body_cck'])) {
+      $t_args = array('%name' => $form['#node_type']->name);
+      drupal_set_message(t("CCK integration settings will be ignored: no fields configured for %name content type.", $t_args), 'warning');
+    }
+  }
+}
+
+
+/**
  * Implementation of hook_nodeapi().
  */
 function image_attach_nodeapi(&$node, $op, $teaser, $page) {
@@ -300,9 +339,22 @@
     case 'view':
       if ($node->iid) {
         $teaser_or_body = $teaser ? 'teaser' : 'body';
+        
+        // Determines value of weight
+        $weight = NULL;
+        if (module_exists('content') && variable_get("image_attach_weight_{$teaser_or_body}_cck_{$node->type}", 0)) {
+          $content_type = content_types($form['#node_type']->type);
+          if (!empty($node->type)) {
+          $weight = content_extra_field_weight($node->type, 'image_attach');
+          }
+        }
+        if (is_null($weight)) {
+          $weight = variable_get("image_attach_weight_{$teaser_or_body}_{$node->type}", 0);
+        }
+        
         $node->content['image_attach'] = array(
           '#value' => theme("image_attach_{$teaser_or_body}", $node),
-          '#weight' => variable_get("image_attach_weight_{$teaser_or_body}_{$node->type}", 0),
+          '#weight' => $weight,
         );
       }
       break;
@@ -494,3 +546,15 @@
   }
 }
 
+/**
+ * Implementation of hook_content_extra_fields.
+ * 
+ * Leave CCK to set field order
+ */
+function image_attach_content_extra_fields($type_name) {
+  $extra = array();
+  if (variable_get('image_attach_'. $type_name, 0) && (variable_get('image_attach_weight_teaser_cck_'. $type_name, 0) || variable_get('image_attach_weight_body_cck_'. $type_name, 0))) {
+    $extra = array('image_attach' => array('label' => t('Image attach'), 'weight' => 0));  
+  }
+  return $extra;
+}
\ No newline at end of file
