diff -u C:\Documents and Settings\acfulton\Desktop\ad.new\image/ad_image.module C:\Documents and Settings\acfulton\Desktop\ad.new\imagenew/ad_image.module
--- C:\Documents and Settings\acfulton\Desktop\ad.new\image/ad_image.module	2009-11-23 19:45:40.000000000 +1300
+++ C:\Documents and Settings\acfulton\Desktop\ad.new\imagenew/ad_image.module	2010-02-24 17:24:07.573148800 +1300
@@ -28,7 +28,16 @@
   if (isset($ad->aid) && (isset($ad->filepath) || isset($ad->remote_image))) {
     $output = '<div class="image-advertisement" id="ad-'. $ad->aid .'">';
     if (isset($ad->url) && !empty($ad->url)) {
-      $image = theme('ad_image_image', !empty($ad->remote_image) ? $ad->remote_image : $ad->filepath, check_plain($ad->tooltip), check_plain($ad->tooltip));
+      if (module_exists('imagecache')) {
+        $groups = array_keys($ad->taxonomy);
+        $tid = $groups[0];  //can an advert be in more than one group?  if so need a more robust way of knowing which group is being rendered
+        $image_cache_preset = variable_get('ad_groups_imagecache_'. $tid, '');
+        $image = theme('ad_image_imagecache', !empty($ad->remote_image) ? $ad->remote_image : $ad->filepath, $image_cache_preset, check_plain($ad->tooltip), check_plain($ad->tooltip));
+      }
+      else {
+        $image = theme('ad_image_image', !empty($ad->remote_image) ? $ad->remote_image : $ad->filepath, check_plain($ad->tooltip), check_plain($ad->tooltip));
+      }
       $output .= l($image, $ad->redirect .'/@HOSTID___', array('attributes' => ad_link_attributes(), 'absolute' => TRUE, 'html' => TRUE));
     }
     else {
@@ -75,6 +84,32 @@
 }
 
 /**
+ * Return a themed ad image.
+ *
+ * @param $path
+ *   Either the path of the ad image file (relative to base_path()) or a full
+ *   URL.
+ * @param $preset
+ *   The name of the imagecache preset to use to process the image
+ * @param $alt
+ *   The alternative text for text-based browsers.
+ * @param $tooltip
+ *   The tooltip text is displayed when the image is hovered in some popular
+ *   browsers.
+ * @param $attributes
+ *   Associative array of attributes to be placed in the img tag.
+ * @return
+ *   A string containing the image tag.
+*/
+function theme_ad_image_imagecache($path, $preset, $alt = '', $tooltip = '', $attributes = NULL) {
+  //NB this will not work for a remote image.
+  $image = theme('imagecache', $preset, $path, check_plain($alt), check_plain($tooltip), $attributes);
+  
+  //because this may be called from the serve.php file, the url of the image gets the path of the ad module prepended to it
+  return str_replace(drupal_get_path('module', 'ad') .'/', '', $image);
+}
+
+/**
  * Implementation of hook_theme().
  */
 function ad_image_theme() {
@@ -95,6 +130,16 @@
         'getsize' => TRUE,
       ),
     ),
+    'ad_image_imagecache' => array(
+      'file' => 'ad_image.module',
+      'arguments' => array(
+        'path' => NULL,
+        'preset' => NULL,
+        'alt' => '',
+        'tooltip' => '',
+        'attributes' => NULL,
+      ),
+    ),
   );
 }
 
@@ -576,7 +621,7 @@
     '#default_value' => isset($node->tooltip) ? $node->tooltip : '',
     '#description' => t('Optionally enter text to appear when a mouse pointer hovers over the ad image.'),
   );
-
+  
   if (variable_get('ad_image_remote_images', FALSE)) {
     $form['ad_image']['remote_image'] = array(
       '#type' => 'textfield',
