// JavaScript Document
// ランダム表示 / 画像切替 | Ability Consultant


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 = false;
						$$.Slideshow.Counter = parseInt(this.id.substring(this.id.length-1));
						
						$('.tmpSlide').stop(); /* 表示 -アニメーション-を利用時に必要 */
						$('.tmpSlide').hide();
						$('.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
	
						// スライド操作
						var elem = $('#tmpSlide-' + $(this).SplitID());
	
						// 表示
						elem.show();
	
						// フェードイン
						elem.css({"opacity": "0.3"})
						elem.show();
						elem.fadeTo(1000,1.0);
						
						$(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 = 4;
      }

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

          $$.Slideshow.Counter++;

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

          setTimeout('$$.Slideshow.Transition();', 6000);
        }
      );
    }
  },
	
	Slideshow02 : {
    Ready : function()
    {
      $('.tmpSlideshowControl02')
        .hover(
          function() {
            $(this).addClass('tmpSlideshowControlOn');
          },
          function() {
            $(this).removeClass('tmpSlideshowControlOn');
          }
        )
        .click(
          function() {
            $$.Slideshow02.Interrupted = false;
						$$.Slideshow02.Counter = parseInt(this.id.substring(this.id.length-1));
						
						$('.tmpSlide02').stop(); /* 表示 -アニメーション-を利用時に必要 */
						$('.tmpSlide02').hide();
						$('.tmpSlideshowControl02').removeClass('tmpSlideshowControlActive');
	
						// スライド操作
						var elem = $('#tmpSlide02-' + $(this).SplitID());
	
						// 表示
						elem.show();
	
						// フェードイン
						elem.css({"opacity": "0.3"})
						elem.show();
						elem.fadeTo(1000,1.0);
						
						$(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 = 4;
      }

      $('#tmpSlide02-' + this.Last).fadeOut(
        'slow',
        function() {
          $('#tmpSlideshowControl02-' + $$.Slideshow02.Last).removeClass('tmpSlideshowControlActive');
          $('#tmpSlideshowControl02-' + $$.Slideshow02.Counter).addClass('tmpSlideshowControlActive');
          $('#tmpSlide02-' + $$.Slideshow02.Counter).fadeIn('slow');

          $$.Slideshow02.Counter++;

          if ($$.Slideshow02.Counter > 4) {
            $$.Slideshow02.Counter = 1;
          }

          setTimeout('$$.Slideshow02.Transition();', 6000);
        }
      );
    }
  },
	
	Slideshow03 : {
    Ready : function()
    {
      $('.tmpSlideshowControl03')
        .hover(
          function() {
            $(this).addClass('tmpSlideshowControlOn');
          },
          function() {
            $(this).removeClass('tmpSlideshowControlOn');
          }
        )
        .click(
          function() {
            $$.Slideshow03.Interrupted = false;
						$$.Slideshow03.Counter = parseInt(this.id.substring(this.id.length-1));
						
						$('.tmpSlide03').stop(); /* 表示 -アニメーション-を利用時に必要 */
						$('.tmpSlide03').hide();
						$('.tmpSlideshowControl03').removeClass('tmpSlideshowControlActive');
	
						// スライド操作
						var elem = $('#tmpSlide03-' + $(this).SplitID());
	
						// 表示
						elem.show();
	
						// フェードイン
						elem.css({"opacity": "0.3"})
						elem.show();
						elem.fadeTo(1000,1.0);
						
						$(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 = 4;
      }

      $('#tmpSlide03-' + this.Last).fadeOut(
        'slow',
        function() {
          $('#tmpSlideshowControl03-' + $$.Slideshow03.Last).removeClass('tmpSlideshowControlActive');
          $('#tmpSlideshowControl03-' + $$.Slideshow03.Counter).addClass('tmpSlideshowControlActive');
          $('#tmpSlide03-' + $$.Slideshow03.Counter).fadeIn('slow');

          $$.Slideshow03.Counter++;

          if ($$.Slideshow03.Counter > 4) {
            $$.Slideshow03.Counter = 1;
          }

          setTimeout('$$.Slideshow03.Transition();', 6000);
        }
      );
    }
  }

});

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