

setInterval( "slideSwitch()", 4000 );


function slideSwitch() {
	var active = $('.slideshow img.active');
	var count = $("#SlideshowCount #Active");
	var slides = $(".slideshow img");

	//alert('1: ' + slides.eq(0).attr("src") + '. 2: ' + slides.eq(1).attr("src") + '. 3: ' + slides.eq(2).attr("src") + '. 4: ' + slides.eq(3).attr("src"));
	
	if ( active.length == 0 ) active = $('.slideshow img:last');

	var next =  active.next().length ? active.next()
		: $('.slideshow img:first');

	// uncomment below to pull the divs randomly
	//var sibs2  = active2.siblings();
	//var rndNum = Math.floor(Math.random() * sibs2.length );
	//var next2  = $( sibs2[ rndNum ] );

	active.addClass('last-active');

	
	if ($(".slideshow img").length > 1) {
			next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {

				active.removeClass('active last-active');
				
				slides.each(function(i) {
					if (slides.eq(i).hasClass("active")) {
						count.text(i+1);
					}
				});		
			});
	}
	
}

