var $$ = $.fn;
var current = 0;

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

  Slideshow : {
    Ready : function()
    {
		this.Counter = 1;
		this.Interrupted = false;
		this.Transition();
		
		
		$('div.pause').click(function() {
			$$.Slideshow.Interrupted = true;
            $('div.tmpSlide').hide();
			$(".pause").hide();
			$(".play").show();
           $('div#tmpSlide-' +current).show()
        });
			
		/* Code for play */
		$('div.play').click(function() {
			$$.Slideshow.Interrupted = false;
            $('div.tmpSlide').show();
			$(".pause").show();
			$(".play").hide();
			this.Counter = current;
			setTimeout('$$.Slideshow.Transition();', 1);
        });
		/* End code for play */
			
		$('div.tmpSlideshowControl')
			.hover(
				function() {
					$(this).addClass('tmpSlideshowControlOn');
				},
				function() {
					$(this).removeClass('tmpSlideshowControlOn');
				}
			)
        .click(
          function() {
			var activeClass = this.className;
			if(  activeClass.indexOf("pause") == -1 ) {
				//$$.Slideshow.Interrupted = true;
				$('div.tmpSlide').hide();
				$('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
			    
				$('div#tmpSlide-' + $(this).SplitID()).show()
				
				if(($(this).SplitID() == 1) || ($(this).SplitID() == 2) || ($(this).SplitID() == 3) || ($(this).SplitID() == 4) || ($(this).SplitID() == 5))
				{
					$("#txtCurrentId").val($(this).SplitID());
				}
				
				$(this).addClass('tmpSlideshowControlActive');
			}
		  }
        );
    },
    Transition : function()
    {
	  var fldCurrentId;		
      if (this.Interrupted) {
      	      //alert('test');
        return;
      }

	  fldCurrentId = $("#txtCurrentId").val();
	  if(fldCurrentId != "")
	  {
	  	this.Counter = fldCurrentId;
		$("#txtCurrentId").val("");
	  }

	  this.Last = this.Counter - 1;

      if (this.Last < 1) {
        this.Last = 5;
      }

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

          $$.Slideshow.Counter++;
		 

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

          setTimeout('$$.Slideshow.Transition();', 5000);
        }
      );
	  current = this.Counter;
    }
  }
});

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