var box;
var slideShowPop;
function slideSwitch() {
   if (!box) {
      box = outputBox();
   }

   var $active = getActiveSlide();
   var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');

   $active.addClass('last-active');

   $next.css({opacity: 0.0})
      .addClass('active')
      .animate({opacity: 1.0}, 1000, function() {
         $active.removeClass('active last-active');
      })
      .unbind('click')
      .click(function () {
         if (!slideShowPop) {
            slideShowPop = $('#slidepopup');
            slideShowPop.click(function () {
               hideSlideShowPopup();
            })
         }

         hideSlideShowPopup();
         showSlideShowPopup();
      })
   delay = $active.attr('delay');
   $active.attr('timeoutid', setTimeout("slideSwitch()", delay));
}

$(function() {
   setTimeout("slideSwitch()", 2000);
});

function getActiveSlide() {
   var $active = $('#slideshow IMG.active');
   if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
   return $active;
}

function hideSlideShowPopup() {
   slideShowPop.css('display', 'none');
   slideShowPop.attr('beingshown', 'false');

   return false;
}
function showSlideShowPopup() {
   if (slideShowPop.attr('beingshown') == "true") {
      // don't trigger the animation again
      return;
   }
   else {
      var $active = getActiveSlide();
      if ($active.attr('largeversion')) {
         slideShowPop.html('<img src="' + $active.attr('largeversion') + '" />');
         slideShowPop.css({
            top: -114,
            left: -5,
            display: 'block'
         });
      }
   }
   slideShowPop.attr('beingshown', 'true');

   return false;
}