

// Behaviour rules for photo galleries
var rules = {
	'div#thumbnails img': function(el) {
		el.onclick = function() {
			var fullPicture = $$('div#imagespace img')[0];
			var newURL = this.src.replace('thumbnail', 'photo');
			if (newURL != fullPicture.src) {
				fullPicture.src = newURL;
			}
		}
	}
};





// Slideshow configuration
var doSlideshow = false;
var changeSlideInMsec = 3500;
var showBackgroundForSec = 0.1;
var fadeSpeedInSec = 0.7;
var numSlides = 4;



var isFirefox10 = navigator.userAgent.match(/Firefox\/1.0/);

Event.observe(window, 'load', function() {
	window.setTimeout(switchSlideshow, changeSlideInMsec);
}, false);

var switchSlideshow = function() {
	
	// FF 1.0 doesn't change opacity of images smoothly, so don't do slideshow
	if (!doSlideshow || isFirefox10) {
		return;
	}
	
	// figure out which pic is showing
	showingId = 'slideshow1'; hiddenId = 'slideshow2';
	if ($('slideshow1').style.display == 'none') {
		showingId = 'slideshow2'; hiddenId = 'slideshow1';
	}
	showing = $(showingId);	hidden = $(hiddenId);
	
	// fade out the one that's showing and make the switch
	Effect.Fade(showing, {duration: fadeSpeedInSec, afterFinish: function() {
		showing.src.match(/([\d]{2})/);
		match = parseInt(RegExp.$1)
		next = match + 2;
		if (next > numSlides) { 
			next = next - numSlides;
		}
		showing.src = '/images/portfoliophoto0'+next+'.jpg';
	}});
	
	// after delay, fade in the one that's not showing
	Effect.Appear(hidden, {delay: showBackgroundForSec, duration: fadeSpeedInSec});
	
	// set it up again
	window.setTimeout(switchSlideshow, changeSlideInMsec);	
}