/*
 * @Author: mjy
 * @Date: 2020-1-14
 */
// $(document).ready(function() {
//     $('#fullpage').fullpage({
//         scrollOverflow: true,
//         scrollingSpeed: 1200,
//     })
// })

window.onload = function () {

  // $('.header-nav-l').css('height', $(window).height() + 'px');
  $('.header-nav .tit').click(function (e) {
    e.stopPropagation();
    if ($('.header-nav').width() > $('.header-nav .tit').width()) {
      $('.header .logo .img2').hide();
      $('.header .logo .img1').show();
      $('.header-nav').animate({
        width: '1.1rem'
      });
      $('.header-nav').css('height', $('.header-nav .tit').height() + .14 + 'rem');
    } else {
      $('.header-nav').css('height', $(window).height() + 'rem');
      $('.header-nav').animate({
        width: '5.3rem'
      });
      $('.header .logo .img1').hide();
      $('.header .logo .img2').show();
    }
    $(document).click(function () {
      if ($('.header-nav').width() > $('.header-nav .tit').width()) {
        $('.header .logo .img2').hide();
        $('.header .logo .img1').show();
        $('.header-nav').animate({
          width: '1.1rem'
        });
        $('.header-nav').css('height', $('.header-nav .tit').height() + .14 + 'rem');
      }
    })
  })

  //首页头条轮播
  jQuery(".index-headline .headline-item").simpleSwitch({
    playTime: 4000,
    type: 'top',
  });


  var swiper3 = new Swiper('.index-wrap5-box', {
    loop: true,
    navigation: {
      nextEl: '.index-wrap5 .next',
      prevEl: '.index-wrap5 .prev',
    },
    autoplay: {
      delay: 4000,
      disableOnInteraction: false,
    },
  });

  var swiper4 = new Swiper('.index-wrap1-tab', {
    loop: true,
    pagination: {
      el: '.index-wrap1-tab .pagination',
      clickable: true,
    },
    autoplay: {
      delay: 4000,
      disableOnInteraction: false,
    },
  });
  $('.index-bgcar ul li').SwitchFade({
    playTime: 4000,
    num: '.fade-num span',
    text: '.fade-txt a',
  });

  $('.index-switch').tabSwitch({
    tabHead: '.index-tit .tit',
    tabCont: '.index-item',
    cur: 'cur'
  });

  //回到顶部
  $(".go-top").click(function () {
    $("html,body").animate({
      scrollTop: 0
    }, 500);
  })
  $(window).scroll(function () {
    var gun = $(document).scrollTop();
    if (gun <= 400) {
      $(".go-top").hide()
    } else {
      $(".go-top").show()
    }
  });

  var mySwiper1 = new Swiper('.box', {
        direction: 'vertical',
        observer: true,
        observerParents: true
    });
    var mySwiper2 = new Swiper('.sec-section', { //瀛恠wiper
        direction: 'vertical',
    })
    var startScroll, touchStart, touchCurrent;
    mySwiper2.slides.on('touchstart', function(e) {
        startScroll = this.scrollTop;
        touchStart = e.targetTouches[0].pageY;
    }, true);
    mySwiper2.slides.on('touchmove', function(e) {
        touchCurrent = e.targetTouches[0].pageY;
        var touchesDiff = touchCurrent - touchStart;
        var slide = this;
        var onlyScrolling =
            (slide.scrollHeight > slide.offsetHeight) && //allow only when slide is scrollable
            (
                (touchesDiff < 0 && startScroll === 0) || //start from top edge to scroll bottom
                (touchesDiff > 0 && startScroll === (slide.scrollHeight - slide.offsetHeight)) || //start from bottom edge to scroll top
                (startScroll > 0 && startScroll < (slide.scrollHeight - slide.offsetHeight)) //start from the middle
            );
        if (onlyScrolling) {
            e.stopPropagation();
        }
    }, true);
    var mySwiper5 = new Swiper('.fir-section', { //瀛恠wiper
        direction: 'vertical',
        nested: true,
        //resistanceRatio: 0,
        slidesPerView: 'auto',
        freeMode: true,
        scrollbar: {
            el: '.fir-scrollbar',
        },
    })

  // 首页回到顶部
  $(".sec-section .go-top").click(function () {
    // mySwiper2.slideTo(0, 500, false);
    $(".sec-section-c").animate({
      scrollTop: 0
    }, 500);
  });
  $(".sec-section-c").scroll(function () {
    var gun = $(".sec-section-c").scrollTop();
    if (gun <= 400) {
      $(".go-top").hide()
    } else {
      $(".go-top").show()
    }
  });
};
