var $$ = $.fn;

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow : {
    Ready : function()
    {
      $('div.exclusiveSlideshowControl')
        .hover(
          function() {
            $(this).addClass('exclusiveSlideshowControlOn');
          },
          function() {
            $(this).removeClass('exclusiveSlideshowControlOn');
          }
        )
        .click(
          function() {
            $$.Slideshow.Interrupted = true;

            $('div.exclusiveSlide').hide();
            $('div.exclusiveSlideshowControl').removeClass('exclusiveSlideshowControlActive');

            $('div#exclusiveSlide-' + $(this).SplitID()).show()
            $(this).addClass('exclusiveSlideshowControlActive');
          }
        );

      this.Counter = 1;
      this.Interrupted = false;

      this.Transition();
    },

    Transition : function()
    {
      if (this.Interrupted) {
        return;
      }

      this.Last = this.Counter - 1;

      if (this.Last < 1) {
        this.Last = 3;
      }

      $('div#exclusiveSlide-' + this.Last).fadeOut(
        'slow',
        function() {
          $('div#exclusiveSlideshowControl-' + $$.Slideshow.Last).removeClass('exclusiveSlideshowControlActive');
          $('div#exclusiveSlideshowControl-' + $$.Slideshow.Counter).addClass('exclusiveSlideshowControlActive');
          $('div#exclusiveSlide-' + $$.Slideshow.Counter).fadeIn('slow');

          $$.Slideshow.Counter++;

          if ($$.Slideshow.Counter > 3) {
            $$.Slideshow.Counter = 1;
          }

          setTimeout('$$.Slideshow.Transition();', 5000);
        }
      );
    }
  }
});

$(document).ready(
  function() {
    $$.Slideshow.Ready();
  }
);
