var bigmatch = /s400/i;	// Regular expression to match large image URLs
var lilmatch = /s72/i;	// Regular expression to match small image URLs

// Create a function that will
// monitor an image and return
// only when an image has fully loaded.
$.fn.image = function(src, f){
  return this.each(function(){ 
	var i = new Image(); 
	i.onload = f; 
	i.src = src; 
	this.appendChild(i);
  }); 
} 

$(document).ready(function(){
	$("#PicasaThumbs .thumbWrap img").click(function() {
		var myNewSrc = $("#PicasaNewest").attr("src").replace(bigmatch, "s72");
		var myNewHref = $("#PicasaNewest").parent("a").attr("href");
		var newLgSrc = $(this).attr("src").replace(lilmatch, "s400");
		var newLgHref = $(this).parent("a").attr("href");
		
		$("#PicasaNewest").fadeOut("fast", function () {

			$(this).image(newLgSrc, function(){
					
				$("#PicasaNewest").attr("src", newLgSrc)
				.parent("a").attr("href", newLgHref)
				.children("#PicasaNewest").fadeIn("fast");
				
			});
		});
		
		$(this).attr("src", myNewSrc);
		$(this).parent("a").attr("href", myNewHref);
		return false;
	});
});	
