var $slideInterval = 5000;
var $slideSpeed = 1000;
var $slide_timeout = null;
$(document).ready(function(){
	var $num_slides = $('#slideshow > *').length;
	if($num_slides > 0)
	{
		$('#slideshow').css({'position':'relative', 'zIndex' : '-1'});
		$('#slideshow > *').each(function(i){
			$(this).css({'position':'absolute', 'display': (i > 0 ? 'none' : 'block')});
		});
		$('body').addClass('has-slideshow');
		$slide_timeout = setTimeout(nextSlide, $slideInterval);
	}
});

function nextSlide()
{
	var $currentSlide = $('#slideshow > *:visible');
	var $nextSlide = $currentSlide.next();
	if($nextSlide.length == 0)
	{
		$nextSlide = $('#slideshow > *:first');
	}

	$currentSlide.animate({ 'opacity' : 'hide' }, $slideSpeed);
	$nextSlide.animate({ 'opacity' : 'show' }, $slideSpeed, function(){ $slide_timeout = setTimeout(nextSlide, $slideInterval); });
}

function stopSlide()
{
	clearTimeout($slide_timeout);
}

