$(document).ready(function() {

  // Used for the pre-loading of images, must be declared outside the local
  // function due to how some browsers clean up variables
  var loadImages = [];

  // Preload all images with a class of thumbnail
  $('img.inactive').each(function() {
      var cacheImage = document.createElement('img');
      cacheImage.src = "/images/"+this.id;
      loadImages.push(cacheImage);
  });

});

/***
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.
***/

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

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

  // Use this to pull the images in the order they appear in the markup
  var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');

  // These three lines pull the images in a random order
  // var $sibs  = $active.siblings();
  // var rndNum = Math.floor(Math.random() * $sibs.length );
  // var $next  = $( $sibs[ rndNum ] );

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

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

$(function() {
    setInterval( "slideSwitch()", 6000 );
});

