$(document).ready(function()
{        
    imageRotator();
});

function imageRotator() 
{ 
    //Set the opacity of all images to 0
    $('ul.rotator li').css({opacity: 0.0});
     
    //Get the first image and display it (set it to full opacity)
    $('ul.rotator li:first').css({opacity: 1.0});
  
  setInterval('nextImage()',3500);
}
 
function nextImage() 
{ 
    // show first if only 1 image
    var current = ($('ul.rotator li.show')?  $('ul.rotator li.show') : $('#ul.rotator li:first'));

  //Get next image, if it reached the end of the slideshow, rotate it back to the first image
  var next = ((current.next().length) ? (current.next()) : $('ul.rotator li:first'));
        
    //Set the fade in effect for the next image, show class has higher z-index
    next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
 
    //Hide the current image
    current.animate({opacity: 0.0}, 1000).removeClass('show');
}
