var $$ = $.fn;

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow2 : {
    Ready : function()
    {
      $('div.tmpSlideshowControl2')
        .hover(
          function() {
            $(this).addClass('tmpSlideshowControl2On');
          },
          function() {
            $(this).removeClass('tmpSlideshowControl2On');
          }
        )
        .click(
          function() {
            $$.Slideshow2.Interrupted = true;
            $('div.tmpSlide2').hide();
            $('div.tmpSlideshowControl2').removeClass('tmpSlideshowControlActive2');

			$('div#tmpSlide2-' + $(this).SplitID()).show();
			
            $(this).addClass('tmpSlideshowControlActive2');
          }
        );

      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#tmpSlide2-' + this.Last).fadeOut('slow',
        function() {
          $('div#tmpSlideshowControl2-' + $$.Slideshow2.Last).removeClass('tmpSlideshowControlActive2');
          $('div#tmpSlideshowControl2-' + $$.Slideshow2.Counter).addClass('tmpSlideshowControlActive2');
          $('div#tmpSlide2-' + $$.Slideshow2.Counter).fadeIn('slow');

          $$.Slideshow2.Counter++;

          if ($$.Slideshow2.Counter > 4) {
            $$.Slideshow2.Counter = 1;
          }

          setTimeout('$$.Slideshow2.Transition();', 10000);
        }
      );
    }
  }
});

$(document).ready(
  function() {
    $$.Slideshow2.Ready();
  }
);
