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

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

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

    var sibs  = active.siblings();
    var rndNum = Math.floor(Math.random() * sibs.length );
    var next  = jQ( sibs[ rndNum ] );


    active.addClass('last-active');

    next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            active.removeClass('active last-active');
        });
}             
jQ(document).ready(function() {  
    var playSlideshow=setInterval( "slideSwitch()", 9000 );
    jQ('#slideshow').hover(function() {
      clearInterval(playSlideshow);
    },
    function() {
      playSlideshow =  setInterval( "slideSwitch()", 9000 );
    });
    jQ('#prevpic').click(function(){ 
      clearInterval(playSlideshow);
      slideSwitch();
      playSlideshow =  setInterval( "slideSwitch()", 9000 );
      return false;
    });  
    jQ('#nextpic').click(function(){ 
      clearInterval(playSlideshow);
      slideSwitch();
      playSlideshow =  setInterval( "slideSwitch()", 9000 );
      return false;
    });    
});
