var $$ = $.fn;

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  slideshow : {
    Ready : function()
    {
      $('div.slideshowControl').click(function() {
            $$.slideshow.Interrupted = true;

            $('div.slide').hide();
            $('div.slideshowControl').removeClass('slideshowControlActive');

            $('div#slide-' + $(this).SplitID()).show()
            $(this).addClass('slideshowControlActive');
          }
        );

      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#slide-' + this.Last).fadeOut(
        'slow',
        function() {
          $('div#slideshowControl-' + $$.slideshow.Last).removeClass('slideshowControlActive');
          $('div#slideshowControl-' + $$.slideshow.Counter).addClass('slideshowControlActive');
          $('div#slide-' + $$.slideshow.Counter).fadeIn('slow');

          $$.slideshow.Counter++;

          if ($$.slideshow.Counter > 3) {
            $$.slideshow.Counter = 1;
          }

          setTimeout('$$.slideshow.Transition();', 8000);
        }
      );
    }
  }
});

$(document).ready(
  function() {
    $$.slideshow.Ready();
  }
);
