var opacity = 0;
var fadeTimerId = 0;
var showTimerId = 0;
var photos = new Array();
var photoCount = 4;
var photoIndex = 0;
var links = new Array();
var switches = new Array();
var titles = new Array();
var subtitles = new Array();

function setOpacity(object, value)
{
	object.style.opacity = value / 100;
	object.style.filter = 'alpha(opacity=' + value + ')';
}

function fade()
{
	opacity += 6;
	setOpacity(photos[photoIndex], opacity);
	if (opacity < 100)
	{
		setTimeout("fade()", 35);
	}
}

function showPhoto(index)
{
	if (index == -1)
	{
		index = photoIndex + 1;
		if (index > photoCount - 1)
		{
			index = 0;
		}
	}
	if (photoIndex != index)
	{
		photoIndex = index;
		clearTimeout(fadeTimerId);
		clearTimeout(showTimerId);
		for (var i = 0; i < photoCount; i++)
		{
			photos[i].style.display		= 'none';
			links[i].style.display		= 'none';
			switches[i].className		= 'switch';
			titles[i].style.display		= 'none';
			subtitles[i].style.display	= 'none';
		}
		opacity = 0;
		setOpacity(photos[photoIndex], opacity);
		photos[photoIndex].style.display	= 'block';
		links[photoIndex].style.display		= 'block';
		switches[photoIndex].className		= 'switch on';
		titles[photoIndex].style.display	= 'block';
		subtitles[photoIndex].style.display	= 'block';
		fadeTimerId = setTimeout("fade()", 35);
		showTimerId = setTimeout("showPhoto(-1)", 5000);
	}
}

function pageLoad()
{
	for (var i = 0; i < photoCount; i++)
	{
		photos[i]	 = document.getElementById('photo' + i);
		links[i] 	 = document.getElementById('link' + i);
		switches[i]	 = document.getElementById('switch' + i);
		titles[i]	 = document.getElementById('title' + i);
		subtitles[i] = document.getElementById('subtitle' + i);
	}
	showTimerId = setTimeout("showPhoto(-1)", 5000);
}