// Javascript by Miles Storey
// rigent.com

$(document).ready(function(){
	$.ajax({
		type: "GET",
		url: "xml/frontpage.xml",
		dataType: "xml",
		success: function(frontpagexml){
			// number of images in XML
			imagesNum = (frontpagexml.getElementsByTagName("image")).length;
			// for each image show it delay fade out move on
			//galNum = 0;
			// Show first image
			newImage(0,frontpagexml)
		}
	});
});

function newImage(thisNum,ref){
	$("#imageDisplay img").fadeOut(function(){
		$("#imageDisplay img").attr("src", "images/"+$(ref).find("image:eq("+thisNum+")").attr("filename")),
		$("#imageDisplay img").load(function(){$(this).fadeIn(),$(this).unbind("load")});
	});
	thisNum++;
	if(thisNum == imagesNum){
		thisNum = 0;
	}
	setTimeout(function(){newImage(thisNum,ref)},4000);
}
