var $$ = $.fn;
var t;
$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },
  
  

  Slideshow : {
    Ready : function()
    {
		this.Counter = 1;
      	this.Interrupted = false;
		this.Interrupted1 = false;
		
		$('div#theSlideshow')
			.hover(
			  function() {
				$$.Slideshow.Interrupted1 = true;
				clearTimeout(t);
			  },
			  function() {
				$$.Slideshow.Interrupted1 = false;
				t = setTimeout('$$.Slideshow.Transition();', 2000); 

				 /* $$.Slideshow.Transition();*/
			  }
			);

        
      $('div.tmpSlideshowControl')
        /*.hover(
          function() {
            $(this).addClass('tmpSlideshowControlOn');
			$$.Slideshow.Interrupted = true;
          },
          function() {
            $(this).removeClass('tmpSlideshowControlOn');
			$$.Slideshow.Interrupted = false;
			if ($$.Slideshow.Counter < 1) {
				$$.Slideshow.Counter = 1;
			  }
			  $$.Slideshow.Transition();

          }
        )*/
		
        .click(
          function() {
            /*$$.Slideshow.Interrupted = true;*/
			$$.Slideshow.Counter = $(this).SplitID();
            $('div.tmpSlide').hide();
            $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');

            $('div#tmpSlide-' + $(this).SplitID()).show()
            $(this).addClass('tmpSlideshowControlActive');
          }
        );

      

      this.Transition();
    },

    Transition : function()
    {
      if (this.Interrupted) {
        return;
      }
	  
	  if (this.Interrupted1) {
        return;
      }

      this.Last = this.Counter - 1;

      if (this.Last < 1) {
        this.Last = $('div.tmpSlide').length;
      }
		          
	  $('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn('slow');

      $('div#tmpSlide-' + this.Last).fadeOut(
        'fast',
        function() {
          $('div#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
          $('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');

          $$.Slideshow.Counter++;

          if ($$.Slideshow.Counter > $('div.tmpSlide').length) {
            $$.Slideshow.Counter = 1;
          }
			
    			t = setTimeout('$$.Slideshow.Transition();', 5000); 
  			 
          //setTimeout('$$.Slideshow.Transition();', 4000);
        }
      );
    }
  }
});


