window.addEvent('domready', function(){
	$$('#slideshow img').each(function(el){
		el.setStyle('opacity', el.hasClass('active')?1:0);
	});
	
	var slideImg = function() {
		var act = $$('#slideshow img.active');
		var img = $$('#slideshow img');
		if ( act.length == 0 ) act = img.getLast();
		else act = act[0];
		
		var next = img.indexOf(act) + 1;
		if (img.length == next) next = 0;
		
		act.removeClass('active');
		var imgNext = img[next];
		imgNext.addClass('active');
		new Fx.Tween(act, {
			property: 'opacity',
			duration: 800,
			onComplete: function(){
				new Fx.Tween(imgNext, {
					property: 'opacity',
					duration: 800
				}).start(0, 1);
			}
		}).start(1, 0);
	}
	slideImg.periodical(5000);
});
