var home_images = null;
var home_index = 0;

$(document).ready(function() {
	$.get("../data/home.xml", function(data) {
		home_images = $("image", data).get();
		preload_images();
		setInterval(rotate_image, 3000);
	});
});

function rotate_image () {
	//fade out the old the image and
	$("#showcase_image").fadeTo("slow", 0.0, swapShowCase);
	$("#showcase_text").fadeTo("slow", 0.0);
	home_index = ++home_index % home_images.length;
}

function swapShowCase (sender) {
	$("#showcase_text p").text($(home_images[home_index]).attr("text"));
	$("#showcase_image img").attr("src", $(home_images[home_index]).attr("src"));
	setTimeout(fadeShowcaseIn, 250)
}

function fadeShowcaseIn(){
	$("#showcase_image").fadeTo("slow", 1.0);
	$("#showcase_text").fadeTo("slow", 1.0);
}


function preload_images(){
	for (var i = home_images.length - 1; i >= 0; i--){
		jQuery("<img>").attr("src", $(home_images[i]).attr("src"));
	};
}
