var $$ = $.fn;

  $$.extend({
      SplitID: function() {
          return this.attr('id').split('-').pop();
      },

      Slideshow: {
          Ready: function() {
              $('span.tmpSlideshowControl')
        .hover(
          function() {
              $(this).addClass('tmpSlideshowControlOn');
          },
          function() {
              $(this).removeClass('tmpSlideshowControlOn');
          }
        )
        .click(
          function() {
              $$.Slideshow.Interrupted = true;

              $('div.tmpSlide').hide();
              $('span.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');

              $('div#tmpSlide-' + $(this).SplitID()).show()
              $(this).addClass('tmpSlideshowControlActive');

              $$.Slideshow.Counter = parseInt($(this).SplitID());
              setTimeout('$$.Slideshow.Resume();', 3000); // Resume after 5 seconds  
          }
        );

              this.Counter = 1;
              this.Interrupted = false;

              this.Transition();
          },

          Resume: function() {
              this.Interrupted = false;
              this.Transition();
          },

          Transition: function() {
              if (this.Interrupted) {
                  return;
              }

              this.Last = this.Counter - 1;

              if (this.Last < 1) {
                  this.Last = $('div.tmpSlide').length;
              }

              $('div#tmpSlide-' + this.Last).fadeOut(1000);

              $('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn(
              1000,
        function() {
            $('span#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
            $('span#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');


            $$.Slideshow.Counter++;

            if ($$.Slideshow.Counter > $('div.tmpSlide').length) {
                $$.Slideshow.Counter = 1;
            }

            setTimeout('$$.Slideshow.Transition();', 3000);
        }
      );
          }
      }
  });

  $(document).ready(
  function() {
      $$.Slideshow.Ready();
  }
);

