// JavaScript Document

var currentImage = document.getElementById('c1');
var currentImageId = 1;
var previousImage;

function nextImage() {
	previousImage = currentImage;
	if(currentImageId<6)
	{
		currentImageId++;
	}
	else
	{
		currentImageId = 1;
	}
	currentImage = document.getElementById('c'+currentImageId);
}

function fadeOut(opacity)
{
	if(opacity>0)
	{
		currentImage.style.opacity=opacity;
		opacity = opacity-.01;
		window.setTimeout("fadeOut("+opacity+")",1);
	}
	else {
		nextImage();
		window.setTimeout("fadeOut(1)",2000);
	}
}

function fadeIn(opacity)
{
	if(opacity<1)
	{
		currentImage.style.opacity=opacity;
		currentImage.style.filter = "alpha(opacity:"+opacity*100+")";
		
		if(previousImage)
		{ 
			previousImage.style.opacity=1-opacity; 
			previousImage.style.filter = "alpha(opacity:"+(1-opacity)*100+")";
		}
		
		opacity = opacity+.01;
		window.setTimeout("fadeIn("+opacity+")",1);
	}
	else {
		if(previousImage)
		{
			previousImage.style.opacity=0;
			previousImage.style.filter = "alpha(opacity:0)";
		}
		nextImage();
		window.setTimeout("fadeIn(0)",3000);
	}
}
