window.addEvent('domready', function(){

	var images = $$('#changer-images img');

	var changerFx = new Fx.Elements(images, {
		link: 'cancel',
		duration: 1000
	});

	images.each(function(image){
		image.setStyle('opacity', 0);
		image.setStyle('visibility', 'visible');
	});

	var initial = {};
	var current = 1;
	var working = {};

	images.each(function(image, index){
		if (index == 0) {
			initial[index] = {'opacity': 1};
		} else {
			initial[index] = {'opacity': 0};
		};
	});

	changerFx.set(initial);

	var changeimage = function(){

		// console.log ('insert: ' + current);
		// console.log('logic: ' + current);

		images.each(function(image, index){
			if (current == index) {
				working[index] = {'opacity': 1};			
			} else {
				working[index] = {'opacity': 0};
			};
		});

		if (current == (images.length-1)) { 
			current = 0;
		} else {
			current = current + 1;
		}; 

		changerFx.start(working);
	};

	changeimage.periodical(5000);
});
