// List of all valid header images
var headList = new Array();
headList[0] = "images/header_harmaamittari.jpg";
headList[1] = "images/header_hyppy.jpg";
headList[2] = "images/header_punainenmittari.jpg";
headList[3] = "images/header_valkoinenmittari.jpg";

var imageIndex = 0;

// state=1 fades in, state=0 fades out
function doAnim(state, id) {
	if (state == 0) {
		fade(100, 0, id);

		// timeout length should be at least the amount of time taken by fade()
		window.setTimeout('swapForeground()',600)

		// fade in after some time
		window.setTimeout("doAnim(1, '"+id+"')",7500);
	} else {
		fade(0, 1, id);
		
		// timeout length should be at least the amount of time taken by fade()
		window.setTimeout('swapBackground()',600);

		// fade out after some time
		window.setTimeout("doAnim(0, '"+id+"')",7500);
	}
}

function swapForeground() {
	imageIndex += 1;

	if (imageIndex >= headList.length) {
		imageIndex = 0;
	}

	var img = document.getElementById('headerimg'); 
	img.src = headList[imageIndex];
}

function swapBackground() {
	imageIndex += 1;

	if (imageIndex >= headList.length) {
		imageIndex = 0;
	}

	var img = document.getElementById('header').style; 
	img.background = "url("+headList[imageIndex]+")";
}

// state=1 fades in, state=0 fades out
function fade(opa, state, id) {
	if ((state == 0 && opa >= 0) || (state == 1 && opa <= 100)) {
		setOpacity(opa, id);

		if (state == 0) {
			opa -= 10;
		} else {
			opa += 10;
		}

		window.setTimeout("fade(" + opa + "," + state + ",'" + id + "')", 50);				
	}
}

// Set opacity in various ways to make sure all browsers see it
function setOpacity(opa, id) {
	var object = document.getElementById(id).style; 
    object.opacity = (opa / 100); 
    object.MozOpacity = (opa / 100); 
    object.KhtmlOpacity = (opa / 100); 
    object.filter = "alpha(opacity=" + opa + ")"; 
}

function show(id) {
	if (id != 'submenu1') {document.getElementById('submenu1').style.display='none';}
	if (id != 'submenu2') {document.getElementById('submenu2').style.display='none';}
	if (id != 'submenu3') {document.getElementById('submenu3').style.display='none';}
	if (id != 'submenu4') {document.getElementById('submenu4').style.display='none';}
	if (id != 'submenu5') {document.getElementById('submenu5').style.display='none';}
	var d = document.getElementById(id);
	if (d) {d.style.display='block';}
}

function hide(id) {
	var d = document.getElementById(id);
	if (d) {d.style.display='none';}
}

function hide_all() {
	document.getElementById('submenu1').style.display='none';
	document.getElementById('submenu2').style.display='none';
	document.getElementById('submenu3').style.display='none';
	document.getElementById('submenu4').style.display='none';
	document.getElementById('submenu5').style.display='none';
}

