﻿// JScript File
var $$ = $.fn;

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow : {
    Ready : function()
    {
      //alert("start SLIDESHOW");
      $('div.tmpSlideshowControl')
        .hover(
          function() {
            //alert("hover: " + $(this).SplitID());
            $(this).addClass('tmpSlideshowControlOn');
          },
          function() {
            $(this).removeClass('tmpSlideshowControlOn');
          }
        )
        .click(
          function() {
            //$$.Slideshow.Interrupted = true;
            $$.Slideshow.Interrupted = false;
            //alert('this.id substring' + parseInt(this.id.substring(this.id.length-1)));
            //alert(this.id.substring(this.id.length-1));
            if (this.id.substring(this.id.length-1) == 't'){
                //alert("Counter = " + $$.Slideshow.Counter);
                $$.Slideshow.Counter = $$.Slideshow.Counter + 1;
                //alert("Counter + 1 = " + $$.Slideshow.Counter);
                if ($$.Slideshow.Counter > $('div.tmpSlide').length) {
                    $$.Slideshow.Counter = $('div.tmpSlide').length;
                    //alert("Counter + 1 = " + $$.Slideshow.Counter);
                }
            }
            if (this.id.substring(this.id.length-1) == 'v'){
                //alert("Counter = " + $$.Slideshow.Counter);
                $$.Slideshow.Counter = $$.Slideshow.Counter - 1;
                //alert("Counter - 1 = " + $$.Slideshow.Counter);
                if ($$.Slideshow.Counter < 1) {
                    $$.Slideshow.Counter = 1;
                    //alert("Counter - 1 = " + $$.Slideshow.Counter);
                }
            }            
            $$.Slideshow.Counter = parseInt(this.id.substring(this.id.length-1));
            //alert("this counter=" + $$.Slideshow.Counter);
            
            if ($(this).SplitID() != 'Prev' && $(this).SplitID() != 'Next') {
            $('div.tmpSlide').hide();
            $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');

            $('div#tmpSlide-' + $(this).SplitID()).show()
            $(this).addClass('tmpSlideshowControlActive');
            //alert($(this).SplitID());
            }
            else{
            if ($(this).SplitID() == 'Prev'){
                if ($$.Slideshow.Prev < 1) {
                    $$.Slideshow.Prev = 1;
                }
                //alert('Prev clicked, Prev=' + $$.Slideshow.Prev);
                $$.Slideshow.Counter = $$.Slideshow.Prev;
                $('div.tmpSlide').hide();
                $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
                $('div#tmpSlide-' + $$.Slideshow.Counter).show()
                $('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
            }
            else {
                if ($(this).SplitID() == 'Next'){
                    if ($$.Slideshow.Next > $('div.tmpSlide').length) {
                        $$.Slideshow.Next = $('div.tmpSlide').length;
                    }
                    //alert('Prev clicked, Next=' + $$.Slideshow.Next);
                    $$.Slideshow.Counter = $$.Slideshow.Next;
                    $('div.tmpSlide').hide();
                    $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
                    $('div#tmpSlide-' + $$.Slideshow.Counter).show()
                    $('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
                }
            }
                //alert("click: " +  $(this).SplitID() + " - CURRENT=" + $$.Slideshow.Current + " - Next=" + $$.Slideshow.Next + " - Prev=" + $$.Slideshow.Prev);
            return;
            }
          }
        );

      this.Counter = 1;
      this.Prev = 1;
      this.Next = 2;
      this.Interrupted = false;

      this.Transition();
    },

    Transition : function()
    {
      //alert ("In Transition");
      if (this.Interrupted) {
        return;
      }
      
      this.Last = this.Counter - 1;
      if (this.Last < 1) {
        this.Last = $('div.tmpSlide').length;
      }
        this.Current = $$.Slideshow.Counter;
        this.Prev = $$.Slideshow.Counter - 1;
        this.Next = $$.Slideshow.Counter + 1;
                
      $('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 > $('div.tmpSlide').length) {
            $$.Slideshow.Counter = 1;
          }

          setTimeout('$$.Slideshow.Transition();', 7000);
        }
      );
    }
  }
});

$(document).ready(
  function() {
  if ($('div.tmpSlide').length > 1){
  //alert("start");
    $$.Slideshow.Ready();
  }}
);

