/*
Source: http://www.spicypeanut.net/Blog/jQuery%20Slideshow2.html
*/
var $$ = $.fn;
var $timeout = 9500; /*miliseconds (1000 = 1 second) */

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow2 : {
    Ready : function()
    {
      $('.tmp2SlideshowControl')
        .hover(
          function() {
            $(this).addClass('tmp2SlideshowControlOn');
          },
          function() {
            $(this).removeClass('tmp2SlideshowControlOn');
          }
        )
        .click(
          function() {
            $$.Slideshow2.Interrupted = true;

            $('.tmp2Slide').hide();
            $('.tmp2SlideshowControl').removeClass('tmp2SlideshowControlActive');

            $('#tmp2Slide-' + $(this).SplitID()).show()
            $(this).addClass('tmp2SlideshowControlActive');
          }
        );

      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 = $('.tmp2Slide').length;
      }

      $('#tmp2Slide-' + this.Last).fadeOut(
        'fast',
        function() {
          $('#tmp2SlideshowControl-' + $$.Slideshow2.Last).removeClass('tmp2SlideshowControlActive');
          $('#tmp2SlideshowControl-' + $$.Slideshow2.Counter).addClass('tmp2SlideshowControlActive');
          $('#tmp2Slide-' + $$.Slideshow2.Counter).fadeIn('fast');

          $$.Slideshow2.Counter++;

          if ($$.Slideshow2.Counter > $('.tmp2Slide').length) {
            $$.Slideshow2.Counter = 1;
          }

          setTimeout('$$.Slideshow2.Transition();', $timeout);
        }
      );
    }
  }
});

$(document).ready(
  function() {
    $$.Slideshow2.Ready();
  }
);
