// Gallery image switcher
// Thumbs in ul#gallery-list with phpThumb hyperlinks, main image in div#gallery-main as a phpThumb hyperlink
//
// phpThumb links must be of the form "...src=<filename>&<furtherparamshere>"

jQuery(document).ready(function()
	{
	// Added by DG for the new login/search pop-out box
	// Should be updated when the chunk "login-search-jquery" is updated
	jQuery("#login-search").addClass("jquery-login-search").hide();
	jQuery("#login-search-tab").show();
	jQuery("#login-button-tr").addClass("jquery-login-button-tr");
	jQuery("#sub-nav").css("margin-top", "27px");

	jQuery("#login-search-tab-button").click(function() {
  		jQuery("#login-search-tab").hide();
  		jQuery("#login-search").show();
  		return false;
	});
	
	jQuery('#gallery-list a').click(function()
		{
		var img;
		var oldImage_JQ = jQuery('#gallery-main img');

		img = new Image();
		img.title = this.title;
		img.style.display = 'none';

		img.onload = function()
			{
			jQuery('#gallery-main').height(oldImage_JQ.height());
			oldImage_JQ.fadeOut(1000, function () {
				jQuery(this).replaceWith(img);
				jQuery(img).fadeIn(1000);
				jQuery('#gallery-main').animate({height: img.height});
				});
			}

		// Must set src after onload for IE
		img.src = oldImage_JQ.attr('src').replace(/src=.*?&/, this.href.match(/src=.*?&/));

		return false;
		});

	// Preloader
	imgs_preloaded = new Array();
	jQuery('#gallery-list a').each(function(i)
		{
		imgs_preloaded[i] = new Image();
		imgs_preloaded[i].src = jQuery('#gallery-main img').attr('src').replace(/src=.*?&/, this.href.match(/src=.*?&/));
		});

	});

