--- C:/devel/VertrigoServ/www/drupal/modules/thickbox.orig/thickbox.module	Sat Feb 17 13:32:35 2007
+++ C:/devel/VertrigoServ/www/drupal/modules/thickbox/thickbox.module	Sat Mar 10 01:20:20 2007
@@ -61,11 +61,11 @@
     if (arg(0) != 'admin' && arg(0) != 'img_assist' && arg(1) != 'add' && arg(2) != 'edit') {
       $path = drupal_get_path('module', 'thickbox');
       drupal_add_css($path .'/thickbox.css');
-      drupal_add_js($path . '/thickbox.js');
       if (variable_get('thickbox_auto', 0) && module_exists('image')) {
         drupal_add_js("var thickbox_derivative = " . drupal_to_js(variable_get('thickbox_derivative', 'preview')) . ";", 'inline');
         drupal_add_js($path . '/thickbox_auto.js');
       }
+      drupal_add_js($path . '/thickbox.js');
     }
   }
 
--- C:/devel/VertrigoServ/www/drupal/modules/thickbox.orig/thickbox_auto.js	Sat Feb 17 13:32:35 2007
+++ C:/devel/VertrigoServ/www/drupal/modules/thickbox/thickbox_auto.js	Sat Mar 10 01:11:54 2007
@@ -1,25 +1,65 @@
+/**
+ * $Id$
+ * ATTENTION: this script has to be loaded _before_ thickbox.js 
+ */ 
+
 $(document).ready(function() {
-  // autocreation for drupal imag enodes
-  // select links, that contain images with class "image" AND "thumbnail"
-  // overwrite only in case they are not manually set as thickbox
-  $("a[img.image.thumbnail]").not(".thickbox").click(TB_drupal_init);
+	
+	// 1. "mark" the category overview pictures
+	$("ul.galleries a[img.image.thumbnail]").addClass("category");
+
+
+	// 2. Group the images in specific contexts
+	
+	// find all the nodes
+	$(".node .content").each(function(i) {
+		var group = "node-g" + i;
+		TB_drupal_rewrite(this, group);
+	});
+	
+	// find the categories
+	$("ul.images").each(function(i) {
+		var group = "gallery-g" + i;
+		TB_drupal_rewrite(this, group);
+	});
 
-  // now care for those links inside the gallery-listing
-  $("ul.galleries a[img.image.thumbnail]").not(".thickbox").unclick(TB_drupal_init);
+	// find all the blocks
+	/* seems useless because the defualt blocks are allways containing only one image
+	$(".block .content").each(function(i) {
+		var group = "block-g" + i;
+		TB_drupal_rewrite(this, group);
+	});
+	*/
+	
+	/* are there any other elements/contexts which should group images? */	
+	
+	
+	// 3. Rewrite the remaining images without grouping
+	TB_drupal_rewrite(document, null);
 });
 
-function TB_drupal_init() {
-  var i = $(this).children("img");
-  var t = i.title() || i.attr("alt") || null;
-  if (thickbox_derivative == "original") {
-    var u = i.src().replace(".thumbnail", "");
-  }
-  else {
-    var u = i.src().replace(".thumbnail", "." + thickbox_derivative);
-  }
-  var g = null; //not yet supported, would require the rewrite
-
-  TB_show(t,u,g);
-  this.blur();
-  return false;
+
+function TB_drupal_rewrite(context, group) {
+	// Process only images, that have not been rewritten (.thickbox) and that are not categorys
+	$("a[img.image.thumbnail]", context).not(".thickbox").not(".category").each(function(i) {
+
+		var img = $(this).children("img");
+		var title = $(this).attr("title") || img.attr("title") || img.attr("alt") || null;
+		
+		/**
+		 * ATTENTION: Until the derivate Bug (http://drupal.org/node/125610) is fixed, 
+		 * the script should allways use the original picture ("true || ").
+		 */		 
+		if (true || thickbox_derivative == "original") {
+    	var href = img.attr("src").replace(".thumbnail", "");
+  	}
+  	else {
+  		var href = img.attr("src").replace(".thumbnail", "." + thickbox_derivate);
+  	}
+	
+	 // finally rewrite the link and wait for thickbox.js to apply the effects
+	 $(this).attr({href: href, title: title, rel: group});
+	 $(this).addClass("thickbox");
+	});
+	
 }
