var show_started = false;
var nPic;
var picName;
var timeout = 0;
var maxPos = 0;

function StartSlideShow() {
	if (!show_started) {
		show_started = true;

		document.getElementById("newimg").style.opacity = 0;
		document.getElementById("newimg").style.filter = "alpha(opacity=0)";
		document.getElementById("newimg-div").style.display = "inline";

		picName = '';
		nPic = Math.floor(Math.random() * 59);
		timeout = setTimeout("nextPic()", 2500);
	}
}

var pic = new Image();
pic.style.display = "none";


function hideMenuMaxPos() {
	if (maxPos) {
		for (i = 0; i <= maxPos; i++)
			document.getElementById("vert" + i).style.color = "#9fcfeb";
		document.getElementById("horz" + maxPos).style.color = "#9fcfeb";
		maxPos = 0;
	}
}
	
function nextPic() {
	clearTimeout(timeout);
	
	document.getElementById("photo-dots").style.display = "none";
	hideMenuMaxPos();
	
	nPic++;
	nPic %= 60;
	o = 0;
	if (picName) document.getElementById("oldimg").src = picName;
	document.getElementById("newimg").style.opacity = 0;
	document.getElementById("newimg").style.filter = "alpha(opacity=0)";

	picName = "/images/2010/life-" + nPic + ".jpg";
	pic.src = picName;
	checkLoadingPic();
}





function choosePic(chPic, pos) {
	clearTimeout(timeout);
	
	document.getElementById("photo-dots").style.display = "inline";
	document.getElementById("photo-dots").style.opacity = 1;
	document.getElementById("photo-dots").style.filter = "alpha(opacity=100)";

	hideMenuMaxPos();
	for (i = 0; i <= pos; i++)
		document.getElementById("vert" + i).style.color = "#ebeb9f";
	document.getElementById("horz" + pos).style.color = "#ebeb9f";
	maxPos = pos;

	picName = '';
	newPicName = '/images/2010/ch-' + chPic + '.jpg';
	document.getElementById("oldimg").src = newPicName;
	document.getElementById("newimg").src = newPicName;
	pic.src = newPicName;

	timeout = setTimeout("nextPic()", 4000);	
}





function checkLoadingPic() {
	clearTimeout(timeout);

	if (pic.complete == true) {
		document.getElementById("newimg").src = pic.src;
		changePic();
	}
	else
		timeout = setTimeout("checkLoadingPic()", 80); 
}

function changePic() {
	clearTimeout(timeout);
	
	o += 20;
	document.getElementById("newimg").style.opacity = o / 100;
	document.getElementById("newimg").style.filter = "alpha(opacity=" + o + ")";
	
	document.getElementById("photo-dots").style.opacity = o / 100;
	document.getElementById("photo-dots").style.filter = "alpha(opacity=" + o + ")";
	
	
	if (o < 100)
		timeout = setTimeout("changePic()", 80)
	else
		timeout = setTimeout("nextPic()", 4000);
}

