// switchthumbs, (c)2008 by DBTech.DE
// thanks to lightbox-team for inspiration

// global variables
var masterThumb;
var masterThumbHeight;
var masterThumbWidth;

// thumbs class
var Thumbs = Class.create();

Thumbs.prototype = {

	// initialize()
	// Constructor runs on completion of the DOM loading. Calls updateImageList and then
	// the function inserts html at the bottom of the page which is used to display the shadow
	// overlay and the image container.
	//
	initialize: function() {

		this.updateThumbsList();

	},

	updateThumbsList: function() {

		if (!document.getElementsByTagName){ return; }
		var images = document.getElementsByTagName('img');

		// loop through all image tags, process 'switchthumbs' references in the rel attribute
		for (var i=0; i<images.length; i++) {
			var image = images[i];
			var imageSrcAttribute = String(image.getAttribute('src'));
			var imageRelAttribute = String(image.getAttribute('rel'));
			if (imageSrcAttribute && (imageRelAttribute.toLowerCase().match(/^switchthumbs$/))) {
				// set thumbs onmouseover event
				image.onmouseover = function () {myThumbs.switchThumb(this); return false;}
			}
			if (imageSrcAttribute && (imageRelAttribute.toLowerCase().match(/^switchthumbs_master$/))) {
				// set masterThumb
				masterThumb = image;
				masterThumbHeight = image.height;
				masterThumbWidth = image.width;
			}
		}

	},

	switchThumb: function(imageLink) {
		var srcURL = imageLink.src; // small image "5.kl.jpg", "5.jpg"
		srcURL = srcURL.replace(/(\d+)\.kl\.(\w+)/, '$1.$2')
		//alert(srcURL);
		var Zoom = masterThumbHeight / imageLink.height;
		masterThumb.src = srcURL;
		masterThumb.width = masterThumbWidth;
		masterThumb.height = masterThumbHeight;
	}
}

// -----------------------------------------------------------------------------------

function initThumbs() { myThumbs = new Thumbs(); }
Event.observe(window, 'load', initThumbs, false);