$(document).ready(function(){
	// Fix selected sub-menu background
	$('ul.nav ul li.current_page_item').parent().parent().addClass('current_page_item');

	setupSlideshow($('#featured_box'), 8000, true);
	setupSlideshow($('#showcase div.showcase_slide'), 1000, false);
});

function setupSlideshow(target, interval, auto) {
	interval = typeof(interval) != 'undefined' ? interval : 42;
	auto = typeof(auto) != 'undefined' ? auto : false;
	var timer;
   
	target.each(function(){
		var container = $(this);	
		var slides = container.children();	
		slides.not(':last').each(function(){
			$(this).css('display', 'none');
		});
		
		function nextSlide() {
			$(':first', container).appendTo(container).fadeIn('slow').siblings().css('display', 'none');
		}
		
		if (auto) {
			timer = setInterval(nextSlide, interval);
		} else {
			container.hover(
				function() {
					nextSlide();
					timer = setInterval(nextSlide, interval);
				},
				function() {
					clearInterval(timer);
				}
			);
		}
   });
}