faded = false;
timer = 500;
id = 0

function init() {
	setTimeout('loadnew();', timer);
}

function loadnew() {
	id = id + 1;
	if(id > 3) { id = 0; }

	rand = Math.random() * 100000;

	// request new images
	$.ajax({
		url: "wp-content/themes/flashpunk/slideshow.php?id=" + rand,
		success: function(data) {
			// on success, load new images
			$('#slideshow_hidden_' + id).html(data);
			
			// begin fadeout. On completion, fade in new images
			$('#slideshow_' + id).fadeTo(500, 0, function() { shownew(); });
		}
	});
}

function shownew() {
	// set new images and show them
	document.getElementById('slideshow_' + id).innerHTML = document.getElementById('slideshow_hidden_' + id).innerHTML;
	$('#slideshow_' + id).fadeTo(1, 1.0);
	
	// reset timer
	setTimeout('loadnew();', timer);
}
