var first = true;

window.addEvent('domready', function() {
	// Options
	var options = {
		pause: 5000,
		duration: 5000,
		loop: true,
		start: 0
	};
	// Elements
	var images = $(document.body).getElements('.images img');
	for (var i = 0; i < images.length; i++) {
		if (i != options.start) {
			images[i].setStyle('opacity', 0);
		}
		else {
			images[i].setStyle('opacity', 1);
		}
	}
	var next = options.start;
	// Period
	$('first').addEvent('load', function() {
		show();
	});
	var periodical = show.periodical(options.pause);
	// Show function
	function show() {
		if (!options.loop && next == images.length - 1) {
			$clear(periodical);
		}
		next = (next == images.length-1) ? 0 : next + 1;
		prev = (next == 0) ? images.length - 1 : next - 1;
		images[next].set('tween', {duration: options.duration});
		images[next].tween('opacity', 1);
		images[prev].set('tween', {duration: options.duration});
		images[prev].tween('opacity', 0);
	}
});