var intervalID = 0;
var slideshowIndex = 0;
var photoInUse = "photoBottom";
var targetAlpha = 100;
var alphastep = 1;
var alpha = 0;
var canStartFade = false;
var photoImage = new Image ();

function showSubmenu (id,show){
	document.getElementById(id).style.display = (show ? "block" : "none");
}

function setAlpha (object,_alpha){
	object.style.opacity = (_alpha/100);
	object.style.MozOpacity = object.style.opacity;
	object.style.filter = 'alpha(opacity='+_alpha+')';
}

function stepFade (){
	alpha += alphastep;
	
	if (alphastep > 0){
		if (alpha > targetAlpha){
			setTimeout ("stepSlideshow()",3000);
			clearInterval (intervalID);
		}
		else
			setAlpha (document.getElementById('photoTop'),alpha);
	}
	else{
		if (alpha < targetAlpha){
			setTimeout ("stepSlideshow()",3000);
			clearInterval (intervalID);
		}
		else
			setAlpha (document.getElementById('photoTop'),alpha);
	}
}

function startFade (){
	if (canStartFade){
		document.getElementById(photoInUse).src = "files/header/step"+slideshowIndex+".png";
		if (targetAlpha == 100) {
			alpha = 0;
			alphastep = 1;
		}
		else{
			alpha = 100;
			alphastep = -1;
		}
		intervalID = setInterval ("stepFade()",10);
	}
}

function stepSlideshow (){
	canStartFade = true;
	if (photoInUse == "photoBottom"){
		photoInUse = "photoTop";
		targetAlpha = 100;
		alpha = 0;
	}
	else{
		photoInUse = "photoBottom";
		targetAlpha = 0;
		alpha = 100;
	}
	slideshowIndex ++;
	if (slideshowIndex > 8) slideshowIndex = 0;
	//alert (slideshowIndex+" "+photoInUse+" "+alpha+" "+targetAlpha);
	
	document.getElementById(photoInUse).onload = startFade();
	photoImage.onload = function (){ document.getElementById(photoInUse).src = "files/header/step"+slideshowIndex+".png"; };
	photoImage.src = "files/header/step"+slideshowIndex+".png";
}
