$(function() {
  /* AV女優リストのアコーディオン */
  $("ul.avmodel-list").hover(function() {
    $(this).css("cursor", "pointer");
  });
  $('ul.avmodel-list li div.label').click(function() {
    $(this).parent().siblings().children('ul').slideUp('fast');
    $(this).siblings('ul').slideToggle('fast');
  });

  $('.block-header ul.avmodel-list').children('li:last').css('border-bottom',
      'none');
  $('.block-header ul.termlist').each(function() {
    $(this).find('li:last').css('border-bottom', 'none');
    var termlistcnt = $(this).find('li').size();
    if (termlistcnt % 2 == 0) {
      $(this).children('li').eq(-2).css('border-bottom', 'none');
    }
  });

  /* 評価基準のツールチップ */
  $("div#standard span").css( {
    opacity : "0.9",
    position : "absolute",
    display : "none"
  });
  $("div#standard span")
      .html(
          '<div class="loading"><img src="/sites/all/themes/ittoku4/images/loading.gif" /><div>');

  $("div#standard a").click(function() {
    if ($("div#standard span").css("display") == "none") {
      $("div#standard span").fadeIn("slow", function() {
        if ($(this).css('display') != 'none') {
          $("body").click(function() {
            $("div#standard span").fadeOut("slow");
          });

          $('body').keydown(function(e) {
            if (e.which == 27) {
              $("div#standard span").fadeOut("slow");
            }
          });
        }
      }).css( {
        top : "30px",
        left : "110px"
      });
      $("div#standard span").load("/sites/all/uploads/standard.html");
      return false;
    } else {
      $("div#standard span").fadeOut("slow");
      return false;
    }
  });

  /* コメ参照(※)のツールチップ */
  $('a.ref').click(function() {
    $('.ref-exp').fadeOut();
    var refid = $(this).attr('href').slice(1,this.length);
    if (! $(this).next().hasClass('ref-exp-wrap')) {
      $(this).after('<div class="ref-exp-wrap"></div>');
    }
    if ($(this).next().children().attr('id') != refid) {
      var defx = 0;
      var defy = 0;
      $('div#' + refid).appendTo($(this).next()).css( {
        top : defy,
        left : defx,
        width : '450px'
      });
    }
    tc = $(this).next().children('#' + refid);
    if (tc.css('display') == 'none') {
      tc.fadeIn(function() {
        $("body").click(function() {
          $('.ref-exp').fadeOut();
        });

        $('body').keydown(function(e) {
          if (e.which == 27) {
            $('.ref-exp').fadeOut();
          }
        });
      });
      /* ドラッグで移動
      tc.mousedown(function(e) {
        tof = $(this).offset();
        mx = e.pageX;
        my = e.pageY;
        $(this).mousemove(function(e) {
          wx = e.pageX - mx;
          wy = e.pageY - my;
          $(this).css({
            top: defy + wy,
            left: defx + wx,
          });
        });
      });
      tc.mouseup(function(e) {
        $(this).unbind('mousemove');
        toff = $(this).offset();
        defx = toff.left - tof.left;
        defy = toff.top - tof.top;
      });
      */
    }
    return false;
  });

  /* リンク集デザイン調整 */
  $("table.links tr:last-child").css("border-bottom", "none");

  /* 協賛サイトデザイン調整 */
  $("div#footer ul.links li:first-child").css("border-left", "none").css(
      "padding-left", "0");

  /* トップページ「最近の注目ムービー」デザイン調整 */
  $("body.front ul#dougalist li:odd").removeClass("odd").addClass("even");
  $("body.front ul#dougalist li:even").removeClass("even").addClass("odd");

  /* ページャー（for IE） */
  $('ul.pager li.pager-current, ul.pager li.pager-ellipsis').wrapInner(
      '<span />');

  /* 動画リストインデックスデザイン調整 */
  var index = $('.block-header ul.category-list li').size();
  $('.block-header ul.category-list li:last').css('border-bottom', 'none');
  if (index % 2 == 0) {
    $('.block-header ul.category-list li').eq(-2).css('border-bottom', 'none');
  }
});

