/** Function to advance slide to next one **/
function slideSwitch() {
	// Find the currently active element
	var active = jQuery('#home-rotator li.active');
	// If there is no currently active element, select the last one.
	if ( active.length == 0 ) active = jQuery('#home-rotator li:last');
	// If there's a next element, proceed tot he next one, otherwise revert back to the start!
	var next =  active.next().length ? active.next()
		: jQuery('#home-rotator li:first');
	// Add a class of last-active to the current one.
	active.addClass('last-active');

	// Make the next one the active element. 
	next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			active.removeClass('active last-active');
		});
		
		// increment our key pointer for the timeouts
		++current_key;
		
		// if we've reached the end,reset
		if(current_key == timeouts.length) {
			current_key = 0;
		}
		// continue looping!
		setTimeout(slideSwitch, timeouts[current_key]);
}
