--- imagefield.module	2006-12-31 09:25:51.000000000 +0100
+++ imagefield.module.thickbox_1	2007-01-25 15:33:30.000000000 +0100
@@ -538,6 +538,15 @@ function imagefield_field_formatter_info
          );
     }
   }
+  if ( module_exists('imagecache') && module_exists('thickbox') ) {
+    $rules = _imagecache_get_presets();
+    foreach ($rules as $ruleid => $rulename) {
+      $formatters['thickbox]['.$rulename] = array(
+        'label' => 'Thickbox: '.$rulename,
+        'field types' => array('image'),
+        );
+    }
+  }
   return $formatters;
 }
 
@@ -556,6 +565,15 @@ function imagefield_field_formatter($fie
       return theme('imagecache', $formatter, $file['filepath'], $item['alt'], $item['title']);
     }
   }
+  if ( module_exists('imagecache') && module_exists('thickbox') ) {
+    if (strpos($formatter, 'thickbox][') !== false) {
+      list($null, $namespace) = explode('][', $formatter, 2);
+      $rules = _imagecache_get_presets();
+      if (in_array($namespace, (array) $rules)) {
+        return theme('imagefield_image_imagecache_thickbox', $namespace, $field, $file['filepath'], $item['alt'], $item['title']);
+      }
+    }
+  }
   return theme('imagefield_image', $file, $item['alt'], $item['title']);
 }
 
@@ -613,6 +631,12 @@ function theme_imagefield_image($file, $
   }
 }
 
+function theme_imagefield_image_imagecache_thickbox($namespace, $field, $path, $alt = '', $title = '', $attributes = NULL) {
+  $attributes = drupal_attributes($attributes);
+  $imagecache_path =  file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
+  return '<a href="'. check_url(file_create_url($path)) .'" class="thickbox" rel="'. $field['type_name'] .'"><img src="'. check_url($imagecache_path) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' /></a>';
+}
+
 /**
  * formats an array of images.
  * @param images
