var $$ = $.fn;

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

  Slideshow : {
    Ready : function()
    {
      $('div.eventSlideshowControl')
        .hover(
          function() {
            $(this).addClass('eventSlideshowControlOn');
          },
          function() {
            $(this).removeClass('eventSlideshowControlOn');
          }
        )
		.click(
			function() {
				$$.Slideshow.Interrupted = false;
				$$.Slideshow.Counter = parseInt(this.id.substring(this.id.length-1));
				$('div.eventSlide').hide();
				$('div.eventSlideshowControl').removeClass('eventSlideshowControlActive');

				$('div#eventSlide-' + $(this).SplitID()).show()
				$(this).addClass('eventSlideshowControlActive');
			}
		);
		
      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 = 4;
      }

      $('div#eventSlide-' + this.Last).fadeOut(
        'slow',
        function() {
          $('div#eventSlideshowControl-' + $$.Slideshow.Last).removeClass('eventSlideshowControlActive');
          $('div#eventSlideshowControl-' + $$.Slideshow.Counter).addClass('eventSlideshowControlActive');
          $('div#eventSlide-' + $$.Slideshow.Counter).fadeIn('fast');

          $$.Slideshow.Counter++;

          if ($$.Slideshow.Counter > 4) {
            $$.Slideshow.Counter = 1;
          }

          setTimeout('$$.Slideshow.Transition();', 4000);
        }
      );
    }
  }
});

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