--- image_gallery.module	2008-02-12 20:15:50.000000000 +0000
+++ patched_image_gallery.module	2008-10-05 13:11:52.025000000 +0100
@@ -109,30 +109,59 @@ function image_gallery_term_path($term) 
   return 'image/tid/'. $term->tid;
 }
 
+/**
+ * Image load single node page -- with customised breadcrumb to deal with multi-taxonomy terms
+ */
 function image_gallery_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
   switch ($op) {
     case 'view':
       if ($page && !$teaser && $node->type == 'image') {
-        $vid = _image_gallery_get_vid();
-        $terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vid);
-        $term = array_pop($terms);
-        if ($term) {
-          $vocabulary = taxonomy_get_vocabulary($vid);
+        //Check if this node belongs in the current taxonomy
+        $terms = taxonomy_node_get_terms_by_vocabulary($node->nid, _image_gallery_get_vid());
+        $ctidok=0; // Flag to indicate if there was a match, 0 (no matches) by default
+        foreach ($terms as $term) {
+          if($_SESSION['current_tid'] == $term->tid) {
+            $ctidok=1; // Yes i do belong! set a flag and stop searching
+            break;
+          }
+        }
+        //If the current session = 0 or node doesnt belong to the current tid then do this stuff
+        if ($_SESSION['current_tid'] == 0 || $ctidok==0) {
+          // If Session var for current_tid empty
+          $term = array_pop($terms);
+          if ($term) {
+            $vocabulary = taxonomy_get_vocabulary(_image_gallery_get_vid());
           // Breadcrumb navigation
-          $breadcrumb = array();
-          $breadcrumb[] = array('path' => 'image', 'title' => $vocabulary->name);
-          if ($parents = taxonomy_get_parents_all($term->tid)) {
-            $parents = array_reverse($parents);
-            foreach ($parents as $p) {
-              $breadcrumb[] = array('path' => 'image/tid/'. $p->tid, 'title' => $p->name);
+            $breadcrumb = array();
+            $breadcrumb[] = array('path' => 'image', 'title' => $vocabulary->name);
+            if ($parents = taxonomy_get_parents_all($term->tid)) {
+              $parents = array_reverse($parents);
+              foreach ($parents as $p) {
+                $breadcrumb[] = array('path' => 'image/tid/'. $p->tid, 'title' => $p->name);
+              }
             }
-          }
           $breadcrumb[] = array('path' => 'node/'. $node->nid);
-          menu_set_location($breadcrumb);
+          $_SESSION['current_tid'] = $p->tid;
+        }
+// end
+        }
+        else {
+          $tid = $_SESSION['current_tid'];
+          $gallery = taxonomy_get_term($tid);
+          $breadcrumb[] = array('path' => 'image/tid/'. $tid, 'title' => $gallery->name);
+          $parents = taxonomy_get_parents_all($tid);
+          foreach ($parents as $parent) {
+            $breadcrumb[] = array('path' => 'image/tid/'. $parent->tid, 'title' => $parent->name);
+          }
+          $breadcrumb = array_reverse($breadcrumb);
+          $terms = taxonomy_node_get_terms($current_nid);
+          drupal_set_title($title->name);
         }
       }
-      break;
+    menu_set_location($breadcrumb);
+    $content = theme('image_gallery', $galleries, $images);
   }
+  return $content;
 }
 
 /**
@@ -146,7 +175,14 @@ function image_gallery_page($type = NULL
     $descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree));
     // The values of $descendant_tids should be safe for raw inclusion in the
     // SQL since they're all loaded from integer fields in the database.
-    $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC';
+// Use Nodeorder if enabled
+    if (module_exists ('nodeorder')) {
+      $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, tn.weight_in_tid ASC';
+    }
+// default to standard query
+    else {
+          $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC';
+    }
     if ($nid = db_result(db_query_range(db_rewrite_sql($sql), 0, 1))) {
       $galleries[$i]->latest = node_load(array('nid' => $nid));
     }
@@ -154,7 +190,16 @@ function image_gallery_page($type = NULL
 
   $images = array();
   if ($tid) {
-    $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), variable_get('image_images_per_page', 6), 0, db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d"), $tid);
+// Store current tid so multi-taxonomy terms OK
+     $_SESSION['current_tid'] = $tid;
+// Respect Nodeorder
+     if (module_exists ('nodeorder')) {
+       $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} tn INNER JOIN {node} n ON tn.nid=n.nid WHERE n.status=1 AND n.type='image' AND tn.tid=%d ORDER BY tn.weight_in_tid ASC"), variable_get('image_images_per_page', 6), 0, db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d"), $tid);
+     }
+// default to standard query
+     else {
+       $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), variable_get('image_images_per_page', 6), 0, db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d"), $tid);
+     }
     while ($node = db_fetch_object($result)) {
       $images[] = node_load(array('nid' => $node->nid));
     }
