// This function only runs the slideshow. It takes the slides (HTML list items), 
// piles them on top of each other, and then moves through them.
// Speed is controlled through JS, but dimensions are controlled through CSS.

var switchSlide;
var pauseTime = 75;	// Default speeds
var fadeTime = 50;
function slideSwitch($nextSlide){
	jQuery('.slideshow').each(function(i){
		/*clearInterval(switchSlide); // This is so we can set the local pauseTime if it exists
		var localPause = $(this).data('pauseTime');
		var localFade = $(this).data('fadeTime');
		var thisPause = (typeof localPause !== "undefined") ? localPause : pauseTime;
		var thisFade = (typeof localFade !== "undefined") ? localFade : fadeTime;*/
			
		if ($(this).children().size() > 1) {
			var $active = $(this).children('li.active');
			if ($nextSlide)
				var $next = $nextSlide;
			else
				var $next = ($active.next().length) ? $active.next() : $(this).children('li:first');
		   
			$active.addClass('last-active');
			$next.css({opacity: 0.0})
				.addClass('active')
				.animate({opacity: 1.0}, fadeTime, function() {
					$active.removeClass('active last-active');
				});
		}
	});
}
jQuery(function($){
    // Make everything active if js is enabled
    jQuery('.gallery').addClass('slideshow');
	jQuery('.slideshow').each(function(i){
		$(this).children('li:first').addClass('active');
	});
    switchSlide = setInterval( "slideSwitch(0)", pauseTime );
});