$(function () {
  var win_height = $(window).height()
  $('.main').css('min-height', win_height - 195 + 'px')

  $('.content li').on('click', function (e) {
    view_source(e)
  })

  $('.download').on('click', function (e) {
    alert('功能暂未开放')
    //如果提供了事件对象，则这是一个非IE浏览器
    if (e && e.stopPropagation)
      //因此它支持W3C的stopPropagation()方法
      e.stopPropagation()
    //否则，我们需要使用IE的方式来取消事件冒泡
    else window.event.cancelBubble = true
  })

  $('.view').on('click', function () {
    viewClose()
  })

  $('.btn').on('click', function () {
    alert('网站备案中，此功能尚未开放')
  })

  $('.submit-btn').on('click', function () {
    alert('提交失败，请重新提交')
  })

  function view_source(e) {
    var e = e || window.event
    current = e.currentTarget
    src = $(current).find('img').attr('src')
    src = src.replace('-min', '')

    alt = $(current).find('p').text()
    $('.view_source .title span').text(alt)
    $('.mask').show()
    $('.view').fadeIn()
    $('.view_source').hide()
    $('.view_content').hide()
    $('.submit_loading').show()
    $('#source')
      .attr('src', src)
      .on('load', function () {
        $('.submit_loading').hide()
        $('.view_source').show()
        $('.view_content').show()
        var realWidth //真实的宽度
        var realHeight //真实的高度
        realWidth = this.width
        realHeight = this.height

        $('.download').css('top', realHeight - 120 + 'px')
        $('.view .view_source img').css('max-height', '')
        $('.view .view_source').css({ 'overflow-y': 'auto', 'overflow-x': 'hidden' })
      })
  }

  function viewClose() {
    $('.mask').hide()
    $('.view').fadeOut()
    setTimeout(function () {
      $('#source').attr('src', '')
    }, 500)
    $('.view_source').scrollTop(0)
  }

  var mySwiper = new Swiper('.swiper-container', {
    nextButton: '.swiper-button-next',
    prevButton: '.swiper-button-prev',
    pagination: '.swiper-pagination',
    paginationClickable: true,
    speed: 600,
    loop: true,
    observer: true,
    observeParents: true,
    autoplayDisableOnInteraction: false,
    autoplay: 3000,
    preloadImages: false,
    paginationBulletRender: function (swiper, index, className) {
      return '<span class="' + className + '"></span>'
    },
    /*swiper添加淡入淡出效果*/
    effect: 'fade',
    fade: {
      crossFade: false,
    },
  })
})
