/*************************************************************************************************************
 * Init
 *************************************************************************************************************/

 
/*************************************************************************************************************
 * Functions
 *************************************************************************************************************/ 

function slideshow_init() {
	val = false;

	$.each($('.slideshow'), function() {
		$.each($(this).find('.hidden'), function() {
			val = true;	// activate slideshow mode only if there are some hidden slides
		});		
	});
	
	return val;
}

function slideshow_nextImage() {
	$.each($('.slideshow'), function() {
		// hide current image
		current = $(this).find('.slide:visible');
		current.fadeOut("normal", function() {
			// show next image
			next = $(this).next('.slide:hidden');
			if( ! next[0]) {
				next = $(this).parent().find('.slide:hidden:first-child');
			}
			next.fadeIn();
		});
		
	});
}

/*************************************************************************************************************
 * When DOM structure has been loaded
 *************************************************************************************************************/
$(document).ready(function() {

	if(slideshow_init())
		setInterval(slideshow_nextImage, 5000);

});
