var $$ = $.fn;

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

  Slideshow : {
    Ready : function()
    {
      $('.tmpSlideshowControl')
        .hover(
          function() {$(this).addClass('tmpSlideshowControlOn');},
          function() {$(this).removeClass('tmpSlideshowControlOn');}
        )
        .click(
          function() {
            $$.Slideshow.Interrupted = true;

            $('.tmpSlide').hide();
	//	$('.tmpSlide').fadeOut('slow');
            $('.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');

        //  $('div#tmpSlide-' + $(this).SplitID()).show()
			$('#tmpSlide-' + $(this).SplitID()).fadeIn('slow');
            $(this).addClass('tmpSlideshowControlActive');
          }
        );

      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 = $('.tmpSlide').length;
      }

      $('div#tmpSlide-' + this.Last).fadeOut(
        'slow',
        function() {
          $('#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
          $('#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
          $('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn('slow');

          $$.Slideshow.Counter++;

          if ($$.Slideshow.Counter > $('.tmpSlide').length) {
            $$.Slideshow.Counter = 1;
          }

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

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