var arr_i = new Array(3);
var arr_t = new Array(3);
var arr_id = new Array(3);
var arr_img = new Array("a", "a", "a");
var max = 8;
var img_index = 0;

var arr_img_obj = new Array();
arr_img_obj[0]=new Image();
arr_img_obj[0].src="images/1-a.jpg";
arr_img_obj[1]=new Image();
arr_img_obj[1].src="images/2-a.jpg";
arr_img_obj[2]=new Image();
arr_img_obj[2].src="images/3-a.jpg";
arr_img_obj[3]=new Image();
arr_img_obj[3].src="images/1-b.jpg";
arr_img_obj[4]=new Image();
arr_img_obj[4].src="images/2-b.jpg";
arr_img_obj[5]=new Image();
arr_img_obj[5].src="images/3-b.jpg";
arr_img_obj[6]=new Image();
arr_img_obj[6].src="images/1-c.jpg";
arr_img_obj[7]=new Image();
arr_img_obj[7].src="images/2-c.jpg";
arr_img_obj[8]=new Image();
arr_img_obj[8].src="images/3-c.jpg";

// Set the timeout in milliseconds
arr_t[0] = setTimeout("BeginHideLoop(1)", (Math.floor(Math.random() * max) + 2) * 1000);
arr_t[1] = setTimeout("BeginHideLoop(2)", (Math.floor(Math.random() * max) + 2) * 1000);
arr_t[2] = setTimeout("BeginHideLoop(3)", (Math.floor(Math.random() * max) + 2) * 1000);

function BeginHideLoop(n)
{
	arr_i[n - 1] = 100;
	// Set the interval in milliseconds
	arr_id[n - 1] = setInterval("SetLessOpacity(" + n + ")", 10);
}

function BeginShowLoop(n)
{
	arr_i[n - 1] = 0;
	// Set the interval in milliseconds
	arr_id[n - 1] = setInterval("SetMoreOpacity(" + n + ")", 10);
}

function SetLessOpacity(n)
{
	arr_i[n - 1]--;
	
	document.getElementById("index-image" + n).style.opacity = arr_i[n - 1] / 100;
	document.getElementById("index-image" + n).style.filter = "alpha(opacity=" + arr_i[n - 1] + ")";
	
	if(arr_i[n - 1] == 0)
	{
		clearInterval(arr_id[n - 1]);
		GetImage(n);
		SetDivHTML(n);
		BeginShowLoop(n);
	}
}

function SetMoreOpacity(n)
{
	arr_i[n - 1]++;

	document.getElementById("index-image" + n).style.opacity = arr_i[n - 1] / 100;
	document.getElementById("index-image" + n).style.filter = "alpha(opacity=" + arr_i[n - 1] + ")";
	
	if(arr_i[n - 1] == 100)
	{
		clearInterval(arr_id[n - 1]);
		// Set the timeout in milliseconds
		arr_t[n - 1] = setTimeout("BeginHideLoop(" + n + ")", (Math.floor(Math.random() * max) + 2) * 1000);
	}
}

function GetImage(n)
{
	switch(arr_img[n - 1])
	{
		case "a":
			arr_img[n - 1] = "b";
			if(n == 1)
				img_index = 3;
			if(n == 2)
				img_index = 4;
			if(n == 3)
				img_index = 5;
			break;
		case "b":
			arr_img[n - 1] = "c";
			if(n == 1)
				img_index = 6;
			if(n == 2)
				img_index = 7;
			if(n == 3)
				img_index = 8;
			break;
		case "c":
			arr_img[n - 1] = "a";
			if(n == 1)
				img_index = 0;
			if(n == 2)
				img_index = 1;
			if(n == 3)
				img_index = 2;
	}
}

function SetDivHTML(n)
{
	document.getElementById("index-image" + n).style.backgroundImage = "url(" + arr_img_obj[img_index].src + ")";
}