$(function () {

    // 滚动效果添加
    $('.com-title, .contact-main, .offer form').attr('data-scroll-reveal', 'enter bottom over .8s and move 30px');
    $('.index-banner, .index-about ul').attr('data-scroll-reveal', 'enter left over .8s and move 30px');
    $('.position, .banner, .index-about .img').attr('data-scroll-reveal', 'enter right over .8s and move 30px');
    $('.index-app .main li, .index-make .main li').each(function() {
        $(this).attr('data-scroll-reveal', 'after ' + ($(this).index()*2) / 10 + 's enter bottom over .8s and move 30px');
    });
    $('.index-product .main li, .product .main li, .news li').each(function() {
        $(this).attr('data-scroll-reveal', 'after ' + ($(this).index()%2*2) / 10 + 's enter bottom over .8s and move 30px');
    });
    $('.index-solution .main li').each(function() {
        $(this).attr('data-scroll-reveal', 'after ' + ($(this).index()%4*2) / 10 + 's enter bottom over .8s and move 30px');
    });
    $('.pro-content .item li').each(function() {
        $(this).attr('data-scroll-reveal', 'after ' + ($(this).index()%5*2) / 10 + 's enter bottom over .8s and move 30px');
    });

    // 滚动效果初始化
    window.scrollReveal = new scrollReveal({ reset: false, move: '50px' });

    // 数字自动增长
    if ($('.counter').length) {
        var counter = $('.counter');
        counter.waypoint(function (direction) {
          if (direction == 'down') {
            counter.countTo();
          }
        }, { offset: '64%'});
      }

    // 首页新闻切换
    $('.index-news .nav a').hover(function(){
        $(this).addClass('active').siblings().removeClass('active');
        $('.index-news .item').eq($(this).index()).addClass('active').siblings().removeClass('active');
    });

    // 点击返回顶部
    $('.go-top').on('click', function(){
        $('body,html').animate({ scrollTop:0 }, "fast");
    });

    // 鼠标hover效果添加
    $('.index-product li,.manage .main li, .product li, .index-case li').addClass('hover-img-big');
    $('.product li, .index-case li').addClass('hover-color');
    $('.lr-ti li').addClass('center-img-hover');
    $('.index-product .more, .index-about .more, .index-about .ser, .o-footer a, .pro-detail .txt .more a').addClass('hvr-bg-move2');
    $('.index-make .more, .com-detail .more .back, .index-solution .more').addClass('hvr-bg-move');
    $('.index-news .tit a:last-child').addClass('hvr-color');
    $('.index-news .left h4').addClass('hover-left-move');

    // 相册放大效果初始化
    $('.imgs-btn').click(function() {
        layer.photos({
          photos: $(this).parent().get(0),
          anim: 5
        });
    });

    // 分页
    $('.position .prev a').text('上一个');
    $('.position .next a').text('下一个');

    // 页面滚动事件
    $(window).scroll(function () {
        if($(window).scrollTop() > 500){
            $('.go-top').fadeIn(500);
        }
        else{
            $('.go-top').fadeOut(500);
        }
    });

    // 二级导航栏锚点点击切换
    $('.position a').on('click',function(e){
        if (this.href.split('#')[1]) {
            e.preventDefault();
            $(this).addClass('active').siblings().removeClass('active');
            $('body,html').animate({
                scrollTop: $('#'+this.href.split('#')[1].toString()).offset().top-85
            }, 0);
        }
    });
    // 底部二级导航点击切换
    $('.footer .nav .active a').on('click',function(e){
        if (this.href.split('#')[1]) {
            $('body,html').animate({
                scrollTop: $('#'+this.href.split('#')[1].toString()).offset().top - 85
            }, 1);
        }
    });

    // url锚点获取
    if(window.location.hash){
        $('body,html').animate({
            scrollTop: $(window.location.hash.toString()).offset().top - 85
        }, 1);

    }

	// 初始化轮播
    var index_banner = new Swiper ('.index-banner', {
        autoplay: true,
        navigation: {
            prevEl: '.index-banner .swiper-button-prev',
            nextEl: '.index-banner .swiper-button-next'
        }
     });
    var index_case = new Swiper ('.index-case .swiper-container', {
        autoplay: true,
        slidesPerView : 3,
        spaceBetween : 20,
        pagination: {
            el: '.index-case .swiper-pagination',
            clickable :true,
        },
     });
    var a_cop = new Swiper ('.about-cop .swiper-container', {
        slidesPerView : 4,
        spaceBetween : 20,
        navigation: {
            prevEl: '.about-cop .swiper-button-prev',
            nextEl: '.about-cop .swiper-button-next'
        }
     });
    var a_pro = new Swiper ('.about-pro .swiper-container', {
        slidesPerView : 1,
        centeredSlides : true,
        loop: true,
        loopAdditionalSlides: 1,
        navigation: {
            prevEl: '.about-pro .swiper-button-prev',
            nextEl: '.about-pro .swiper-button-next'
        },
        on: {
            init: function() {
                this.slideTo(1);
            }
        }
     });
    var list = new Swiper ('.pro-detail .list .swiper-container', {
        direction : 'vertical',
        slidesPerView : 5,
        spaceBetween : 10,
        watchSlidesVisibility: true,
     });
    var detail = new Swiper ('.pro-detail .big .swiper-container', {
        direction : 'vertical',
        slidesPerView : 1,
        thumbs: {
            swiper: list
        },
        navigation: {
            prevEl: '.pro-detail .swiper-button-prev',
            nextEl: '.pro-detail .swiper-button-next'
        }
     });

});

// 点击切换当前
;(function($, window, document,undefined){
    $.fn.toggleOn = function (target) {
        $(this).on('click', function(){
            $(this).addClass('active').siblings().removeClass('active');
            if(target) {
                target.eq($(this).index()).addClass('active').siblings().removeClass('active');
            }
        });
    }
})(jQuery, window, document);

// 点击加载更多
;(function($, window, document,undefined){
    $.fn.getMore = function(btn,num,loadNum,speed){
            var sum = $(this).find("li").hide().size();
            if(num >= sum) btn.hide();
            $(this).find("li:lt(" + num + ")").show();
            that = $(this);
            btn.on("click",function(){
                num += loadNum;
                that.find("li:lt(" + num + ")").slideDown(speed?speed:400);
                if(num >= sum) $(this).hide();
            });
        }
})(jQuery, window, document);
function chkForm2() {
    var name = $('#f_name').val();
    var shouji = $('#f_shouji').val();
    var introduce = '咨询';
    if(name == '') {
        alert('请填写您的姓名');
        return false;
    }
    if(shouji == '') {
        alert('请填写您的电话');
        return false;
    }
    subForm2();
}
function chkForm3() {
    var name = $('#f_name1').val();
    var shouji = $('#f_shouji1').val();
    var introduce = $('#introduce').val();
    if(name == '') {
        alert('请填写您的姓名');
        return false;
    }
    if(shouji == '') {
        alert('请填写您的电话');
        return false;
    }
    if(introduce == '') {
        alert('请填写您的留言');
        return false;
    }
    subForm2();
}

function subForm2() {
    $.ajax({
        type: "POST",
        url: $(".J_ajaxForms").attr('action'),
        data: $(".J_ajaxForms").serialize(),
        success: function(msg) {
            msg = eval("(" + msg + ")");
            if (msg.status == 1) {
                alert("谢谢您的留言，我们会尽快与您联系.");
                window.location.reload();
            } else {
                alert(msg.txt);
            }
        }
    });
}
