var Intro = {
	slides : [],
	frame : -1,
	speed : 20000,

	showNext : function ()
	{
		var old = Intro.frame;
		Intro.frame = Math.floor(1000 * Math.random()) % Intro.slides.length;
		while (old == Intro.frame)
		{
			Intro.frame = Math.floor(1000 * Math.random()) % Intro.slides.length;
		}
		var animation = Utils.Animation.attach(
			Intro.slides[Intro.frame],
			[
				new AnimationKeyFrame( { style: { display : 'block', opacity : 0 } }, 400, false, Utils.Animation.Interpolations.exp10),
				new AnimationKeyFrame( { style: { display : 'block', opacity : 1 } }, 1)
			],
			function () { setTimeout('Intro.hideLast()', Intro.speed); }
		);
		Utils.Animation.animate(animation);
	},
	
	hideLast : function ()
	{
		var animation = Utils.Animation.attach(
			Intro.slides[Intro.frame],
			[
				new AnimationKeyFrame( { style: { display : 'block', opacity : 1 } }, 100),
				new AnimationKeyFrame( { style: { display : 'block', opacity : 0 } }, 1),
				new AnimationKeyFrame( { style: { display : 'none' } }, 1 )
			],
			Intro.showNext
		);
		Utils.Animation.animate(animation);
	},

	onLoad : function ()
	{
		Intro.slides = Utils.Dom.getElementsByClassName('intro_slide');
		for (var i = 0, l = Intro.slides.length; i != l; ++i)
		{
			Intro.slides[i].style.display = 'none';
			Intro.slides[i].style.opacity = '0';
		}
		if (Intro.slides.length) Intro.showNext();
	},
	
	init : function (c)
	{
		if (60 < ++c) return; 
		var ex;
		try
		{
			Utils.Events.addListener(window, 'load', Intro.onLoad);
		}
		catch (ex)
		{
			setTimeout('Intro.init(' + c + ')', 1000);
		}
	}

}

Intro.init(0);
