var slideshowDelay = 6000;
var slideshowTimeout = null;

function switchSlideshow() {
	var $active = $('#slideshow > :visible');

    if($active.length == 0) {
	    $active = $('#slideshow > :first');
    }

    $active.removeClass('active');

    var $next = $active.next().length ? $active.next()
        : $('#slideshow > :first');

    $next.addClass('active');

	$active.fadeOut(100, function () {
		$next.fadeIn(400);
	});

	slideshowTimeout = setTimeout("switchSlideshow()", slideshowDelay);
}

$(function() {
	$('#slideshow :first').addClass('active');
	$('#slideshow :first').show();

	slideshowTimeout = setTimeout("switchSlideshow();", 3000);

	$('#slideshow').hover(
		function () {
			clearTimeout(slideshowTimeout);
		},
		function () {
			slideshowTimeout = setTimeout("switchSlideshow();", slideshowDelay);
		}
	);

});
