Event.observe(window, 'load', function(){
	$$('div.mod_photos_diaporama_accueil').each(function(item){
		item.update('');
		item.setStyle({position:'relative'});
		this.img1 = Builder.node('img', { className:'modphotos_item', src:'', style:'display:none; position:absolute; top:0; left:0;' });
		this.img2 = Builder.node('img', { className:'modphotos_item', src:'', style:'display:none; position:absolute; top:0; left:0;' });
		item.appendChild(this.img1);
		item.appendChild(this.img2);
		new Ajax.Request('ajax.mod.photos.diaporama.php?id='+item.getAttribute('rel'), 	{
			method:'post',
			asynchronous:true,
			onSuccess: function(t) {
				if(t.responseText != ""){
					var img = t.responseText.evalJSON();
					img1.src = img.src;
					img1.title = img.title;
					new Effect.Appear(img1, {duration:2,afterFinish:function(){}});
				}
			},
			onComplete: function(){},
			evalScripts:true
		});

		new Ajax.Request('ajax.mod.photos.diaporama.php?id='+item.getAttribute('rel'), 	{
			method:'post',
			asynchronous:true,
			onSuccess: function(t) {
				if(t.responseText != ""){
					var img = t.responseText.evalJSON();
					img2.src = img.src;
				}
			},
			onComplete: function(){},
			evalScripts:true
		});
		new PeriodicalExecuter(function(pe) {
			new Ajax.Request('ajax.mod.photos.diaporama.php?id='+item.getAttribute('rel'), 	{
				method:'post',
				asynchronous:true,
				onSuccess: function(t) {
					if(t.responseText != ""){
						var toShow = img1.visible() ? img2 : img1;
						var toMask = img1.visible() ? img1 : img2;
						var img = t.responseText.evalJSON();
						new Effect.Fade(toMask, {duration:2,afterFinish:function(){toMask.src = img.src;toMask.title = img.title;}});
						new Effect.Appear(toShow, {duration:2,afterFinish:function(){}});
					}
				},
				onComplete: function(){},
				evalScripts:true
			});
		},6);

	});

});
