// 动画效果
new WOW().init();

IEVersion();

// 判断IE
function IEVersion() {
  var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
  var isIE =
    userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
  var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
  var isIE11 =
    userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1;
  // document.body.style.opacity = 0;
  document.body.style.display = "none";
  if (isIE) {
    var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
    reIE.test(userAgent);
    var fIEVersion = parseFloat(RegExp["$1"]);
    console.log(fIEVersion);
    if (fIEVersion == 7) {
      $("html").addClass("browsers");
    } else if (fIEVersion == 8) {
      $("html").addClass("browsers");
    } else if (fIEVersion == 9) {
      $("html").addClass("browsers");
    } else if (fIEVersion == 10) {
      $("html").addClass("browsers");
      return 10;
    } else {
      $("html").addClass("browsers");
    }
  } else if (isEdge) {
    // document.body.style.opacity = 1;
    document.body.style.display = "block";
    return "edge"; //edge
  } else if (isIE11) {
    // document.body.style.opacity = 1;
    document.body.style.display = "block";
    return 11; //IE11
  } else {
    // document.body.style.opacity = 1;
    document.body.style.display = "block";
    return -1; //不是ie浏览器
  }
}

// 一个参数
function ajax(url, id) {
  var ajax = $.ajax({
    url: url,
    async: false,
    type: "POST",
    data: {
      id: id,
    },
  });

  $("#list-ajax").html(ajax.responseText);
}

// 两个参数
function ajaxDoub(url, id, id2) {
  var ajax = $.ajax({
    url: url,
    async: false,
    type: "POST",
    data: {
      id: id,
      id2: id2,
    },
  });

  $("#list-show").html(ajax.responseText);
}

function ajaxSchool(url, id, id2, id3, val) {
  var ajax = $.ajax({
    url: url,
    async: false,
    type: "POST",
    data: {
      id: id,
      id2: id2,
      id3: id3,
      val: val,
    },
  });

  $("#list-show").html(ajax.responseText);
}

// 带搜索
function ajaxSearch(url, val) {
  var ajax = $.ajax({
    url: url,
    async: false,
    type: "POST",
    data: {
      val: val,
    },
  });

  $("#list-show").html(ajax.responseText);
}

// 带搜索
function ajaxVal(url, id, val) {
  var ajax = $.ajax({
    url: url,
    async: false,
    type: "POST",
    data: {
      id: id,
      val: val,
    },
  });

  $("#list-ajax").html(ajax.responseText);
}

// 分页
function page(url, sum) {
  p += 1;
  var ajax = $.ajax({
    url: url,
    type: "POST",
    data: {
      page: p,
    },
    cache: false,
    dataType: "html",
    beforeSend: function () {},
    success: function (html) {
      $("#page-box").append(html);
    },
  });
  if (p == sum - 1) {
    $(".page-btn").hide();
  }
  return false;
}

// 一个参数的搜索
function pageTab(url, id, sum) {
  $("#page-box").fadeIn(3000);

  p += 1;
  var ajax = $.ajax({
    url: NewUrl,
    type: "POST",
    data: {
      page: p,
      id: id,
    },
    cache: false,
    dataType: "html",
    beforeSend: function () {},
    success: function (html) {
      $("#page-box").append(html);
    },
  });
  if (p == sum - 1) {
    $(".page-btn").hide();
  }
  return false;
}

// 滚动效果
function scroll(num) {
  $("html,body")
    .stop()
    .animate({ scrollTop: $("#list-box").offset().top - num }, 800);
}

function scrollA(num, time) {
  $("html,body").animate(
    {
      scrollTop: $($(this).attr("href")).offset().top - num,
    },
    time
  );
}

// 头部定位
function nav(num) {
  $(".head-nav .nav-ls").eq(num).addClass("cur");
  // $(".nav-container .swiper-slide").eq(num2).addClass("cur");
}

// 返回顶部
function gotoTop(minHeight) {
  $(".back-top").click(function () {
    $("html,body").animate(
      {
        scrollTop: "0px",
      },
      "slow"
    );
  });

  minHeight ? (minHeight = minHeight) : (minHeight = 600);
  $(window).scroll(function () {
    var s = $(window).scrollTop();
    if (s > minHeight) {
      $(".back-top").fadeIn(500);
    } else {
      $(".back-top").fadeOut(500);
    }
  });
}

function scrollTabNav() {
  $(window).on("scroll resize", function () {
    winTop = $(window).scrollTop();
    if ($(".side-box").length > 0) {
      var _length = $(".side-box").length;
      for (var i = 0; i < _length; i++) {
        if (
          $(window).scrollTop() >=
          $(".side-box").eq(i).offset().top - $(".head").height()
        ) {
          $(".side-bar a").eq(i).addClass("cur").siblings().removeClass("cur");
        }
      }
    }
  });
}

$(function () {
  // let home = $("body").attr("data-idx");

  // if (!home) {
  //   // 获取二级栏目距离顶部距离
  //   let navTop = $(".nav-box").offset().top;

  //   // 获取二级栏目高度
  //   let navHeight = $(".nav-box").height();
  // }

  // 获取头部高度
  // let headHeight = $(".head").height();

  // 滚动高度
  let widTop = 0;

  function scrollNav() {
    widTop = $(document).scrollTop();

    // 头部悬浮
    if (widTop >= 100) {
      $(".head").addClass("head-scroll");
    } else {
      $(".head").removeClass("head-scroll");
    }

    // if (!home) {
    //   // 二级栏目悬浮
    //   if (widTop >= navTop - navHeight - headHeight) {
    //     $(".pub-nav").addClass("nav-fix");
    //   } else {
    //     $(".pub-nav").removeClass("nav-fix");
    //   }
    // }
  }

  scrollNav();

  $(document).scroll(function () {
    scrollNav();
  });

  // 判断头部是否添加初始底色
  let headBgIdx = $("body").attr("data-bg");
  if (headBgIdx == 1) {
    $(".head-box").addClass("initHead");
    $(".head").addClass("head-scroll2");
  }

  // 手机展开
  $(".menu").click(function () {
    if ($(this).hasClass("cur")) {
      $(this).removeClass("cur");
      $(".mb-head").slideUp();
      $(".head").removeClass("head-scroll");
      $("body").removeClass("body");
      $("html").removeClass("html");
    } else {
      $(this).addClass("cur");
      $(".mb-head").slideDown();
      $(".head").addClass("head-scroll");
      $("body").addClass("body");
      $("html").addClass("html");
    }
  });

  // 二级栏目
  $(".mb-nav").click(function () {
    if ($(this).hasClass("cur")) {
      $(this).removeClass("cur").find(".mb-nav-scd").slideUp();
    } else {
      if ($(this).find(".mb-nav-frs").attr("href") == "javascript:;") {
        $(this)
          .addClass("cur")
          .find(".mb-nav-scd")
          .slideDown()
          .parent()
          .siblings()
          .removeClass("cur")
          .find(".mb-nav-scd")
          .slideUp();
      } else {
      }
    }
  });

  // 点击导航关闭
  $(".mb-nav-scd a").click(function () {
    $(".mb-head").slideUp();
    $(".menu").removeClass("cur");
    $("body").removeClass("body");
    $("html").removeClass("html");
  });

  // pc二级下拉
  $(".head-nav .nav-ls").hover(
    function () {
      $(this).find(".pos-nav").stop(true, false).slideDown();
    },
    function () {
      $(this).find(".pos-nav").stop(true, false).slideUp();
    }
  );

  // 搜索
  $(".head-search").click(function () {
    $(".search-dialog").addClass("search-dialog-slide");
  });

  // 关闭搜索
  $(".search-dialog .form-box .close").click(function () {
    $(".search-dialog").removeClass("search-dialog-slide");
  });

  // 二级栏目
  if ($("div").hasClass("nav-container")) {
    let navIndex = $(".nav-container .swiper-slide.cur").index();
    var navSwiper = new Swiper(".nav-container", {
      observer: true,
      observeParents: true,
      slidesPerView: "auto",
    });
    navSwiper.slideTo(navIndex, 500, false);
  }

  // 链接展开
  $(".footer .top .foot-logo .link p").click(function () {
    if ($(this).hasClass("cur")) {
      $(this)
        .removeClass("cur")
        .siblings(".change")
        .stop(true, false)
        .slideUp();
    } else {
      $(this).addClass("cur").siblings(".change").stop(true, false).slideDown();
    }
  });

  let closeSrc = $(".videos_mask").attr("data-src");

  // 播放视频
  $(document).on("click", ".play", function (event) {
    event.preventDefault();
    var video = $(this).attr("data-path"); //获取视频路径
    $(".videos").html(
      '<video id="video" src=\'' +
        video +
        '\' preload="auto" controls="controls" autoplay="autoplay"></video><img class="vclose" src="' +
        closeSrc +
        '" width="25" height="25"/>'
    );
    $(".videos").fadeIn();
    $(".videos_mask").fadeIn();
  });

  function close1() {
    var v = document.getElementById("video"); //获取视频节点
    $(".videos").fadeOut(); //点击关闭按钮关闭暂停视频
    $(".videos_mask").fadeOut(); //点击关闭按钮关闭暂停视频
    v.pause();
    $(".videos").html();
  }

  // 关闭视频
  $(".videos").on("click", ".vclose", function (event) {
    event.preventDefault();
    close1();
  });
});
