function slideSwitch( slideTo ) {
var jQueryactive = jQuery('#slideshow div.active');
//var jQueryactiveb = jQuery('#slide-buttons li a.active');

if ( jQueryactive.length == 0 ) jQueryactive = jQuery('#slideshow div:last');
//if ( jQueryactiveb.length == 0 ) jQueryactiveb = jQuery('#slide-buttons li a.active:last');

var jQuerynext = jQueryactive.next().length ? jQueryactive.next()
: jQuery('#slideshow div:first');
//var jQuerybutton = jQueryactiveb.next().length ? jQueryactiveb.next()
//: jQuery('#slide-buttons li a:first');

jQueryactive.addClass('last-active');
//jQueryactiveb.addClass('last-active');

// added “slideTo” variable to allow transition to a selected slide
// defaults to null, but if it’s >= 0, it will use this index for “$next”
var slideTo = ( slideTo+1 )? slideTo : null;
if ( slideTo != null ) jQuerynext = jQuery('#slideshow div').eq(slideTo);

jQuerynext.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
jQueryactive.removeClass('active last-active');
});
//jQuerybutton.css({opacity: 0.0})
//.addClass('active')
//.animate({opacity: 1.0}, 1000, function() {
//jQueryactiveb.removeClass('active last-active');
//});
}

jQuery(document).ready(function(){

// hide all images except first to avoid initial flicker
jQuery("#slideshow div").css({opacity: 0.0});
jQuery("#slideshow div:first").css({opacity: 1.0});

// use setInterval to traverse list
var playSlideshow = setInterval( "slideSwitch()", 5000 );
slideSwitch();
// create buttons to move to specific slide
var jQueryslideButtons = jQuery("#slide-buttons a.slide-button");
jQueryslideButtons.click(function(){
jQueryplayButton.addClass('hidden');
jQuerypauseButton.removeClass('hidden');
// stop the slideshow, to keep it from trying to overlap our transition
clearInterval(playSlideshow);
// call the function using the index of the clicked button
slideSwitch( jQueryslideButtons.index(this) );
// restart the slideshow
setTimeout( playSlideshow = setInterval( "slideSwitch()", 5000 ), 5000);
});
var jQuerypauseButton = jQuery("#slide-buttons a.pause-button");
jQuerypauseButton.click(function(){
// stop the slideshow
clearInterval(playSlideshow);
jQuerypauseButton.addClass('hidden');
jQueryplayButton.removeClass('hidden');
});
var jQueryplayButton = jQuery("#slide-buttons a.play-button");
jQueryplayButton.click(function(){
slideSwitch( jQueryslideButtons.index(this) );
jQueryplayButton.addClass('hidden');
jQuerypauseButton.removeClass('hidden');
// restart the slideshow
setTimeout( playSlideshow = setInterval( "slideSwitch()", 5000 ), 5000);
});
});
