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

slideSwitch = (
   function ($) {
      function slideSwitch() {
         var
            initialised = $('.slideshow:not(:has(IMG.active)) IMG:last-child').addClass('active'),
            active = $('.slideshow IMG.active').add(initialised),
            next = active.filter('IMG:last-child').siblings('IMG:first-child').add(active.filter(':not(IMG:last-child)').next('IMG'));
         
         active.addClass('last-active').removeClass('active');

         next.each(function (index) {
            var
               node = $(this),
               lastNode = node.siblings('IMG.last-active')
               opacity = lastNode.css('opacity');

            opacity = (opacity == null || opacity == 0 ) ? 1.0 : opacity;
            node.css({'opacity': 0.0})
               .addClass('active')
               .animate({'opacity': opacity}, 1000);
            lastNode.animate({'opacity': 0.0}, {
                  'duration':1000,
                  'complete': function () {
                     $(this).attr('style', function (index, value) {
                           value = (value) ? value : '';
                           return value.replace(/(;?\s*)opacity:\s*[\d.]+\s*;\s*/, '$1');
                        })
                        .removeClass('last-active');
                  }
               });
         });
      }
      $(function() {
          setInterval( "slideSwitch()", 3000 );
      });
      
      return slideSwitch;
   }
)(jQuery);


