$(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() {
    var qicon = $(this);
    $('.ref-exp').fadeOut();
    var len = qicon.attr('href').length;
    var refid = qicon.attr('href').slice(1, len);
    if (!qicon.next().hasClass('ref-exp-wrap')) {
      qicon.after('<div class="ref-exp-wrap"></div>');
    }
    if (qicon.next().children().attr('id') != refid) {
      var defx = 0;
      var defy = 0;
      $('div#' + refid).appendTo(qicon.next()).css( {
        top : defy,
        left : defx,
        width : '450px',
        display : 'none'
      });
    }
    tc = qicon.next().children('#' + refid);
    tc.fadeIn(function() {
      $("body").click(function() {
        $('.ref-exp').fadeOut();
      });

      $('body').keydown(function(e) {
        if (e.which == 27) {
          $('.ref-exp').fadeOut();
        }
      });
    });
    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');
  }

  /* ログインフォーム */
  $('form#user-login input[name="name"]').focus();

  /* 掲載サイトブロックのショートカットリンク */
  $('#aside #views-navigation-block ul li a').mouseenter(function(e) {
    enterflag = e.currentTarget;
    var element = $(this);
    setTimeout(function() {
      if (enterflag == e.currentTarget) {
        element.parent('li').siblings('li').children('ul').slideUp('fast');/* この行いらないかも。 */
        element.siblings('ul').slideDown('fast');
      }
    }, 300);
  });
  $('#aside #views-navigation-block ul li').mouseleave(function(e) {
    enterflag = '';
    $(this).children('ul').slideUp('fast');
  });
});

