//<![CDATA[	
var o_img_paths = new Array();

$$('.portfolioThumb').each(function(o_img)
	{
		var s_large = o_img.getParent().href;

	    o_img_paths.include(s_large);


	});

var s_replaceSrc = "";
var b_fadeInProgress = false;
var b_replaceImage = true;
var o_fadeOutEffect = new Fx.Morph($('case_image'), {duration: 500, transition: Fx.Transitions.Sine.easeIn});

o_fadeOutEffect.addEvent("complete", function()
{
	// If b_replaceImage is set we need to replace the image after the fadeout
	if(b_replaceImage)
	{
		// From here on see the image onload event
		$('case_image').src = s_replaceSrc;
	}
	// If this was the fadeIn effect
	else
	{
		// Set that we're done
		b_fadeInProgress = false;
		// If the new image name has been changed in the mean time we start the next fade
		if(s_replaceSrc != $('case_image').src)
		{
			fadeCaseImage(s_replaceSrc);
		}
	}
});

$('case_image').addEvent("load", function ()
{
	// If we're in progress of a fade and we've already faded out and replaced the image
	if(b_replaceImage && b_fadeInProgress)
	{
		// We start the fade in
		o_fadeOutEffect.start({'opacity' : [0,1]});
		// And set that we're done with the replace
		b_replaceImage = false;
	}
});

function fadeCaseImage(s_newSrc)
{
	// Set the to new image url which we will load after the fade out
	s_replaceSrc = s_newSrc;

	// Only start a new fade out if we're not in progress
	if(!b_fadeInProgress)
	{
		// Set the booleans
		b_replaceImage = true;
		b_fadeInProgress = true;

		// Create a preloading image
		o_replaceImage = new Element('img', {
			src: s_replaceSrc
		});

		// Start the fade out (from here on see the oncomplete)
		o_fadeOutEffect.start({'opacity' : [1,0]});
	}
}

new Asset.images(o_img_paths,
	{
		onComplete: function ()
		{
			$$('.portfolioThumb').each(function(o_img)
				{

					o_img.getParent().addEvent('click',function()
					{
						fadeCaseImage(this.href);

						return false;
					});
				});
		}
	});
		//]]>
