--- xspf_playlist_thumb.module.orig	2009-05-06 19:56:18.000000000 +0200
+++ xspf_playlist_thumb.module	2009-09-12 18:57:37.640625000 +0200
@@ -98,9 +98,10 @@ function xspf_playlist_thumb_xspf_playli
   switch($op){
     case 'define':
       $items = array(
-        'xspf_playlist_thumb--1' => t('none'),
-        'xspf_playlist_thumb--2' => t('XSPF: Default thumbnail'),
-        'xspf_playlist_thumb--3' => t('Drupal: Upload attached files'),
+        'xspf_playlist_thumb--1' => t('None'),
+        'xspf_playlist_thumb--2' => t('Drupal: Upload attached files'),
+        'xspf_playlist_thumb--3' => t('XSPF: CCK Imagefield/Filefield field'),
+        'xspf_playlist_thumb--4' => t('XSPF: Default thumbnail'),
       );
       return $items;
     break;
@@ -115,7 +116,16 @@ function xspf_playlist_thumb_xspf_playli
         '#prefix' => '<div id="xspf_playlist--2_config" class="xspf_playlist_config_thumb">',
         '#suffix' => '</div>',
       );
-      return $form;
+      $form['xspf_playlist_thumb_cck_imagefield_field_'. $node->type] = array(
+        '#type' => 'select',
+        '#title' => t('CCK Imagefield/filefield field name with the thumbnail'),
+        '#options' => xspf_playlist_thumb_cck_fields($node->type),
+        '#default_value' => variable_get('xspf_playlist_thumb_cck_imagefield_field_'. $node->type, NULL),
+        '#description' => t('Enter a CCK Imagefield/Filefield Field name with the thumbnail you wish to use'),
+        '#prefix' => '<div id="xspf_playlist--4_config" class="xspf_playlist_config_thumb">',
+        '#suffix' => '</div>',
+      );
+	  return $form;
     break;
 
     case 'return':
@@ -124,14 +134,15 @@ function xspf_playlist_thumb_xspf_playli
           return;
         break;
         case 2:
-          // return default thumbnail
-          return variable_get('xspf_playlist_thumb_'. $node->type, null);
+          return xspf_playlist_thumb_get_attached_files($node);
         break;
-
         case 3:
-          return xspf_playlist_thumb_get_attached_files($node);
+          return xspf_playlist_thumb_get_cck_imagefield_files($node, variable_get('xspf_playlist_thumb_cck_imagefield_field_'. $node->type, null));
         break;
-
+        case 4:
+          // return default thumbnail
+          return variable_get('xspf_playlist_thumb_'. $node->type, null);
+        break;        
       }
     break;
   }
@@ -162,7 +173,43 @@ function xspf_playlist_thumb_get_attache
         $thumbs[] = $file->filepath;
       }
     }
-    if ($thumbs) {return $thumbs;}
+  return $thumbs ? $thumbs : '';
+  }
+}
+
+/**
+ * Return an array of files defined in a CCK Imagefield/Filefield field in a node suitable for use as thumbnail images.
+ *
+ * @param $node
+ *   A node object.
+ * @param $field_name
+ *   CCK Field name where is the thumbnail
+ */
+function xspf_playlist_thumb_get_cck_imagefield_files($node, $field_name) {
+  if (isset($node->{$field_name})) {
+    $thumbs = array();
+    foreach ($node->{$field_name} as $field) {
+      $thumbs[] = $GLOBALS['base_path'] . $field['filepath'];
+    }
+  return $thumbs ? $thumbs : '';
+  }
+}
+
+/**
+ * This function gets a list of all CCK fields that can be used for this content type 
+ *
+ */
+function xspf_playlist_thumb_cck_fields($content_type) {
+  // get our content type's field
+  $fields = content_fields(NULL, $content_type);
+  if ($fields) {
+    foreach ($fields as $name => $field) {
+      // only bother with specified field types Filefield and Imagefield
+        if (in_array($field['type'], array('image', 'filefield') )) {
+          $return[$field['field_name']] .=  t('CCK !type: !name', array('!type' => $field['type'], '!name' => $field['widget']['label']));
+      }
+    }
+    return $return;
   }
 }
 
