

function slideSwitch(direction) {
		if(typeof direction == "undefined"){
			direction = "next";
		}

    var $active = $('#slideshow .content IMG.active');

    if ( $active.length == 0 ){
			$active = $('#slideshow .content IMG:last');
		}
	
		var $next;
		if(direction == "next"){
   		$next =  $active.next().length ? $active.next() : $('#slideshow .content IMG:first');
		}
		else{
			$next = $active.prev().length ? $active.prev() : $('#slideshow .content IMG:first');
		}

		$third = $("#slideshow .content IMG.last-active");
		if($third != undefined){
			$third.removeClass("last-active");
		}

		$active.removeClass('active');
		$active.addClass('last-active');

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

}

$(function() {
    window.slideshow = setInterval( "slideSwitch()", 15000 );

		$("#prev").click(function(){
			if(window.slideshow != null){
        clearInterval(window.slideshow);
        window.slideshow = null;
      }

      slideSwitch("prev");
		});

		$("#next").click(function(){
   		if(window.slideshow != null){
				clearInterval(window.slideshow);
				window.slideshow = null;
			}

			slideSwitch("next");
		});

});



