var cur = 0;
var blendDuration = 1;
var pauseDuration = 3;
var images;

function Start() {
	setTimeout(FadeSplash, 6000);

	var container = document.getElementById("ImageContainer");
	images = container.getElementsByTagName("div");
	if(images.length == 0)
		return;

	var el = images[cur];
	el.style["opacity"] = 1;
	el.style["filter"] = "alpha(opacity=100)";
	
	if(images.length > 1)
		PauseAndPrepareNext(null, null);
}

function Blend() {
	var next = (cur + 1) % images.length;

	var desc = {
		"AnimationName": "Parallel",
		"Duration": blendDuration,
		"AnimationChildren": [
			{
				"AnimationTarget": images[cur].id,
				"AnimationName": "FadeOut"
			},
			{
				"AnimationTarget": images[next].id,
				"AnimationName": "FadeIn"
			}
		]
	};

	var animation = AjaxControlToolkit.Animation.createAnimation(desc, null);
	animation.add_ended(PauseAndPrepareNext);
	animation.play();
	
	cur = next;
}

function PauseAndPrepareNext(animation, args) {
	setTimeout(Blend, pauseDuration * 1000);
}

function FadeSplash() {
	var splash = document.getElementById("SplashBox");
	if(!splash)
		return;
	
	var desc = {
		"AnimationName": "FadeOut",
		"AnimationTarget": "SplashBox",
		"Duration": 1.5
	};
	var animation = AjaxControlToolkit.Animation.createAnimation(desc, null);
	animation.add_ended(RemoveSplash);
	animation.play();
}

function RemoveSplash() {
	var splash = document.getElementById("SplashBox");
	if(splash)
		splash.style["display"] = "none";
}