window.addEvent('domready',function() {
	var showDuration = 15000;
	var container = $('bigimage');
	if(container != null) {
		var images = container.getElements('img');
		var smallimages = $('small').getElements('img');
		var currentIndex = 0;
		var interval;
		$$('#small img').set('opacity','0.4');
		smallimages[0].set('opacity','1');
		$$('#bigimage img').set('opacity',0);
		images[0].fade('in');
		var show = function() {
			images[currentIndex].fade('out');
			smallimages[currentIndex].tween('opacity','0.4');
			images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
			smallimages[currentIndex].tween('opacity','1');
		};
		window.addEvent('load',function(){
			interval = show.periodical(showDuration);
		});
		$$('div#small img').addEvent('mouseover',function() {
			$clear(interval);
			for(var i=0; i<smallimages.length; i++) {
				if(smallimages[i] == this) {
					images[i].fade('in');
					smallimages[i].tween('opacity','1');
					currentIndex = i;
				} else {
					images[i].fade('out');
					smallimages[i].tween('opacity','0.4');
				}
			}
		});
		$$('div#small img').addEvent('mouseout',function() {
			interval = show.periodical(showDuration);
		});
	}
});
