var rotateSlide = setInterval ( "displayNext(1000)", 7000 );
var animating;

function displayNext(switchSpeed) {
	var $active = $('.ImageSlideshow IMG.active');
    $active.addClass('last-active');
    animating = true;
	var $next =  $active.next('IMG').length ? $active.next('IMG')
	: $('.ImageSlideshow IMG:first');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, switchSpeed, function() {
            $active.removeClass('active last-active');
            animating = false;
        });
}

function displayPrev(switchSpeed) {
	var $active = $('.ImageSlideshow IMG.active');
    $active.addClass('last-active');
    animating = true;
	var $prev =  $active.prev('IMG').length ? $active.prev('IMG')
	: $('.ImageSlideshow IMG:last');
    $prev.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, switchSpeed, function() {
            $active.removeClass('active last-active');
            animating = false;
        });
}

function nextSlide() {
	clearInterval(rotateSlide);
	if (!animating) {
		displayNext();
	}
	rotateSlide = setInterval ( "displayNext(1000)", 5000 );
}


function prevSlide() {
	clearInterval(rotateSlide);
	if (!animating) {
		displayPrev();
	}
	rotateSlide = setInterval ( "displayNext(1000)", 5000 );
}

