// JavaScript Document

function slideSwitch() {
    var $active = $('.slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('.slideshow IMG:last');

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

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

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

function slideSwitch2(el) {
	var $active = el.find('img.active');
	if ( $active.length == 0 ) $active = el.find('img:last');
	
	var $next =  $active.next().length ? $active.next()
		: el.find('img:first');
		
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 0, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
	var playSlideshow;
	$('.active').before('<span class="hoverprompt">* Hover mouse over image to animate</span>'); 
	$('.slideshow').hover(function() {					  
		var $this = $(this);
		$this.find('.hoverprompt').hide();
		playSlideshow = setInterval(function() {slideSwitch2($this);}, 750);
	}, function() {
		clearInterval(playSlideshow);
		var $this = $(this);
		$this.find('.hoverprompt').show();
		}
	);
		   
	//var playSlideshow;
//	$('.active').before('<span class="hoverprompt">* Hover mouse over image to animate</span>'); 
//    $('.slideshow').hover(function() {
//    	playSlideshow = setInterval( "slideSwitch()", 750 );
//		$('.hoverprompt').hide();
//	},
//	function() {
//		clearInterval(playSlideshow);
//		$('.hoverprompt').show();
//	});
});
