// code to execute when the DOM is ready
$(function() {
	slideshow();
});


// creates a slideshow that cross-fades images

function slideshow() {
	// look for any element with class 'slideshow'
	$('.slideshow').each(function() {
		// hide all slides except the first one
		$(this).find('.slide:not(:first)').each(function(i) {
			$(this).css({display: 'none',opacity: 0});
		});
	});
	
	// switch the slide every five seconds
	setInterval("slideshow_switch()",5000);
}
	
function slideshow_switch() {
	$('.slideshow').each(function() {
		$(this).find('.slide:visible').each(function(i) {
			if (i == 0) {
				$(this).animate({opacity: 0},1000,function(){$(this).css({display: 'none'})});
				if ($(this).is(':last-child')) {
					$(this).parents('.slideshow').find('.slide:first').css({display: 'block'}).animate({opacity: 1},1000);
				}
				else {
					$(this).next().css({display: 'block'}).animate({opacity: 1},1000);
				}
			}
		});
	});
}