var slideshowsize = 0;
var imgindex = -1;
var timeoutid;

$(document).ready(function() {
	slideshowsize = $(".frontpageimage img").length;

	if(slideshowsize > 1) {
		$(".frontpageimage img").css("z-index", 0);
		$(".frontpageimage img:eq(0)").css("z-index", 10);

		startFadeNext();

		$(document).unload(function() {
			clearTimeout(timeoutid);
		});
	}
});

function startFadeNext()
{
	var previousimg = imgindex;
	imgindex++;
	if(imgindex >= slideshowsize)
	{
		imgindex = 0;
	}

	$(".frontpageimage img:eq(" + previousimg + ")").css("z-index", "20");
	$(".frontpageimage img:eq(" + imgindex + ")").css("z-index", "10");

	$(".frontpageimage img:eq(" + previousimg + ")").fadeOut( "slow", function() {
		$(this).css("z-index", "0");
		$(this).show();
	});
	timeoutid = setTimeout( "startFadeNext()", 10000 );
}
