// メイン画像
$(function(){
  var $btn   = $('ul#btn li');
  var $img   = $('#img img');
  var count  = 1;
  var time   = 6000;
  var timerID;
  if ($img.length < 2) {
    return false;
  }
  slideTimer();
  $btn.click(function() {
    if (count != $btn.index(this) + 1 && !(count == 0 && $img.length == $btn.index(this) + 1)) {
      count = $btn.index(this);
      $img.css('z-index', 0).fadeOut().eq(count).css('z-index', 1).fadeIn();
      $btn.removeClass().eq(count).addClass('active');
      count = count == $img.length - 1 ? 0 : count + 1;
    }
  }).mouseup(slideTimer);
  function slideTimer() {
    clearInterval(timerID);
    timerID = setInterval(function() {
      $btn.eq(count).click();
    }, time);
  }
});

// スライドバナー
$(function() {
  var $box  = $('#slide_bnr ul');
  var $btn  = $('ul#btn_bnr');
  var size  = 230;
  var count = 0;
  if ($box.find('li').length <= 4) {
    return false;
  }
  $btn.find('li.next').click(function() {
    count++;
    if (count == $box.find('img').length - 4) {
      $(this).hide();
    }
    if ($btn.find('li.prev').is(':hidden')) {
      $btn.find('li.prev').show();
    }
    slideImg();
    return false;
  }).show().end().find('li.prev').click(function() {
    count--;
    if (count == 0) {
      $(this).hide();
    }
    if ($btn.find('li.next').is(':hidden')) {
      $btn.find('li.next').show();
    }
    slideImg();
    return false;
  });
  function slideImg() {
    $box.stop().animate({
      marginLeft : - size * count + 'px'
    });
  }
});

// 動画切り替え
$(function() {
  var index = 0;
  var videoTitle = 'shaleny_2';
  video();
  $('#movie_list img').click(function() {
    if (index == $('#movie_list img').index(this)) {
      return false;
    }
    index = $('#movie_list img').index(this);
    videoTitle = $(this).attr('alt');
    video();
    return false;
  });
  function video() {
    var s1 = new SWFObject('flv/player.swf', 'player', '240', '178', '8');
    s1.addParam('allowfullscreen', 'true');
    s1.addParam('allowscriptaccess', 'always');
    s1.addParam('flashvars', 'file=' + videoTitle + '.flv&image=images/' + videoTitle + '.jpg');
    s1.write('players1');
  }
});

