var lastMenu = 0;
var myTimer = false;
var activepic = 0;
var piclist = new Array();

$(function() {
	$(".fppic").each(function() {
		piclist.push($(this).val());
	});
	if (piclist.length) {
		activepic = 1;
		startTimer(piclist[activepic]);
	}
});

function showMenu(menuId,state) {
	if (state == 1) {
		clearTimeout(myTimer);
		document.getElementById("subMenu"+menuId).style.visibility = "visible";
		if (lastMenu != menuId && lastMenu) {
			document.getElementById("subMenu"+lastMenu).style.visibility = "hidden";
		}
		lastMenu = menuId;
	}
	else if (state == 0) {
		myTimer = setTimeout(function() {hideMenu(menuId, state)},1000);
	}
}

function hideMenu(menuId,state) {
	document.getElementById("subMenu"+menuId).style.visibility = "hidden";
}

function hilite(obj,state) {
	obj.style.backgroundColor = state ? "#d0d0d0" : "";
}

function startTimer(picnumber)
{
	// automatically swap images on front page
	var img = new Image();
	var imageUrl = "showPhoto.php?pid=" + picnumber + "&width=900&height=900";
	$(img).attr('src', imageUrl);
	$(img).load(function() {
	    swapPic($(this));
	});
}

function swapPic(img)
{
	$(".activepic").oneTime(10000, function() {
	    if ($(".activepic a").length) {
	        $(".activepic a img").remove();
	        $(".activepic a").append(img);
	    }
	    else {
	        $(".activepic img").remove();
	        $(".activepic").append(img);
	    }
	    activepic++;
	    if (activepic == piclist.length) activepic = 0;
	    startTimer(piclist[activepic]);
	});
}
