Event.observe(window, 'load', function()
{
	newAnimation = new Animation();
	newAnimation.slideshow(1,null,4000,'dia');
});


var Animation = Class.create(
{
	slideshow: function(start,last,interval,target)
	{
		if (last == null) {
			this.last		= 0;
			
			$$('.diaimg').each(function(item, index) {
				this.last 	= this.last + 1;
			}.bind(this));
			
			last = this.last;
		}
		
		var frame 		= start;
		var nextframe 	= start+1;
		
		Effect.Appear(target+'1',{duration:.5,from:0.0,to:1.0});   
		
		if (last > 1) {
			setInterval(function()
			{   
				Effect.Fade(target+frame,
						{	duration:1.5,
							from:1.0,
							to:0.0,
							afterFinish:function()
							{
								$(target+frame).hide();
								
							    frame = nextframe;
							    nextframe = (frame == last) ? start : nextframe+1;
							},
							beforeStart:function()
							{
							    Effect.Appear(target + nextframe,{duration:1.5,from:0.0,to:1.0});
							}
						});
			}, interval);   
			return; 
		}
	}
});
