$(document).ready(function(){
	$('img.expander').each(function(){
		$smallimg = $(this);
		$smallimg.css('cursor', 'pointer');
		var simg = $smallimg.attr('src');
		var limg = simg.replace('.png', '_large.png');
		$.preLoadImages(limg);
		$smallimg.before('<img src="'+limg+'" title="'+$smallimg.attr('title')+'" class="large '+$smallimg.attr('class')+'" />');
		var $largeimg = $smallimg.parent('div').find('img.expander.large');
		$largeimg.hide();
		$(window).load(function(){
			var limgwidth = $largeimg.width();
			var limgheight = $largeimg.height();
			$largeimg.css('cursor', 'pointer').css('width', $smallimg.width()).css('height', $smallimg.height());
			$smallimg.click(function(){
				$smallimg.hide();
				$largeimg.show().animate({width: limgwidth, height: limgheight}, 500);
			});
			$largeimg.click(function(){
				$largeimg.animate({width: $smallimg.width(), height: $smallimg.height()}, 500, function(){
					$largeimg.hide();
					$smallimg.show();
				});
			});
		});
	});
});
(function($) {
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)
