// File: 	slideshow.js 
// Version: 1.1
// Date: 	June 2, 2011
// Author: Philip Westendorp
// 

// This js cycles through a set of children elements (slides) of the container. Once the end is reached it wraps around to the first. 
// An 'active' class can be added to designate the first slide of the set (does not need to be the first image)

//PURPOSE: Start the cycling of a set of elements contained within a container element.
//container: the ID of the container that contains the slides
//transitionTime: time interval used for fading betwen slides
//cycleTime		: time before next slide
function startSlideshow(container, transitionTime, cycleTime){
	//Pull the first slide that has the 'active' class
	var active = $(container + ' > .active:first');

	//If no slide was found, set to first child
	if(!active.length)
		active = $(container + ' > :first').addClass('active');

	//hide all siblings of the active slide
	//remove class 'active' from any siblings
	$(active).siblings().hide().removeClass('active');
	
	//start cycling of slides
	setInterval(function(){nextSlide(container, transitionTime)}, cycleTime);
}

//PURPOSE: Cycling to the next slide contained within the container.
//container: the ID of the container that contains the slides
//transitionTime: time interval used for fading betwen slides
function nextSlide(container, transitionTime){
	//get active and next slide; wrapping to beginning when at the end
	var active = $(container + ' > .active:first');
	var next = (active.next().length > 0) ? active.next() : $(container + ' > :first');
    
    //switch to next slide
	active.fadeOut(transitionTime, function(){
	  	active.removeClass('active');
      	next.fadeIn(transitionTime).addClass('active');
	});
}	

