--- /tmp/image_gallery.module_old	2009-06-01 15:16:59.000000000 +0200
+++ image_gallery.module	2009-06-01 15:45:47.000000000 +0200
@@ -145,7 +145,7 @@
 /**
  * Image gallery callback, displays an image gallery
  */
-function image_gallery_page($type = NULL, $tid = 0) {
+function image_gallery_page($type = NULL, $tid = 0, $index = NULL) {
   $galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1);
   for ($i=0; $i < count($galleries); $i++) {
     $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image');
@@ -205,8 +205,49 @@
     drupal_set_title($gallery->name);
   }
 
-  $content = theme('image_gallery', $galleries, $images);
-  return $content;
+  if ($index == NULL) {
+    $content = theme('image_gallery', $galleries, $images);
+    return $content;
+  } else {
+    $previous = NULL;
+    $next = NULL;
+    foreach ($images as $nr => $image) {
+      if ($image->nid == $index) {
+        if ($nr != 0) {
+		  $previous = $images[$nr-1]->nid;
+		}
+        if ($nr != count($images)-1) {
+          $next = $images[$nr+1]->nid;
+        }
+        break;
+      }
+    }
+    return array('next' => $next, 'previous' => $previous);
+  }
+}
+
+function image_gallery_link($type, $object, $teaser = false) {
+  $links = array();
+  $taxobj = current($object->taxonomy);
+  if (!$taxobj) {
+    return $links;
+  }
+  $gallery_links = image_gallery_page(NULL, $taxobj->tid, $object->nid);
+  if ($gallery_links['next'] != NULL) {
+  	$links['gallery_next'] = array(
+      	'title' => t('next image'),
+        'href' => 'node/' . $gallery_links['next'],
+        'attributes' => array('title' => t('next image')),
+  	);
+  }
+  if ($gallery_links['previous'] != NULL) {
+  	$links['gallery_previous'] = array(
+   	   'title' => t('previous image'),
+       'href' => 'node/' . $gallery_links['previous'],
+   	   'attributes' => array('title' => t('previous image')),
+  	);
+  }
+  return $links;
 }
 
 function image_gallery_admin() {
