var spotlightInterval;

function slideSwitch(cls) {
	var next, active = jQuery('.'+cls+' .group.active');
	if (active.length == 0) {
		active = jQuery('.'+cls+' .group:last');
	}

	next =  active.next().length ? active.next() : jQuery('.'+cls+' .group:first');

	active.addClass('last-active');
	next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1500, function() {
		active.removeClass('active last-active');
	});
}

function spotlightSwitch(nr) {
	if (nr == 0) {
		nr = (jQuery('#spotlight ol .active').index() + 1) % jQuery('#spotlight ol').children().size() + 1;
	} else {
		clearInterval(spotlightInterval);
	}

	if (!jQuery('#spotlight ol li:nth-child('+nr+')').hasClass('active')) {
		jQuery('#spotlight ul .active').animate({opacity: 0.0}, 300, function() {
			jQuery('#spotlight ol li.active').removeClass('active');
			jQuery('#spotlight ol li:nth-child('+nr+')').addClass('active');
			jQuery(this).removeClass('active');
			jQuery('#spotlight ul li:nth-child('+nr+')').css('opacity', 0.0).addClass('active').animate({opacity: 1.0}, 300);
		});
	}
}
	
jQuery(function() {
	jQuery.each(['s1', 's2', 's3', 's4'], function(index, value) {
		if (jQuery('.'+value).children().size() > 1) {
			setInterval('slideSwitch(\''+value+'\')', 10000);
		}
	});
	
	jQuery('#spotlight ol li').click(function() {
		spotlightSwitch(jQuery(this).text());
	});
	
	spotlightInterval = setInterval('spotlightSwitch(0)', 10000);
});
