$(function () {
    // 滚动效果添加
    $('.com-wow, .about-title h3, .solution-title, .index-nav, .page-title h3, .com-title h3, .lr-ti li')
    .addClass('wow fadeInUp');
    $('.com-wow-left')
    .addClass('wow fadeInLeft');
    $('.com-wow-right, .lr-ti li .img')
    .addClass('wow fadeInRight');

    // 滚动效果添加
    $('.about-title p, .page-title p, .index-info .title p, .com-title p')
    .addClass('wow fadeInUp').attr('data-wow-delay', '.2s');

    // 滚动效果添加
    $('.contact .right .qrcode')
    .addClass('wow fadeInRight').attr('data-wow-delay', '.4s');

    // 滚动效果添加
    $('.com-wow1 li').each(function() {
        $(this).addClass('wow fadeInUp').attr('data-wow-delay', ($(this).index()*2) / 10 + 's');
    });
    $('.com-wow2 li').each(function() {
        $(this).addClass('wow fadeInUp').attr('data-wow-delay', ($(this).index()%2*2) / 10 + 's');
    });
    $('.com-wow3 li').each(function() {
        $(this).addClass('wow fadeInUp').attr('data-wow-delay', ($(this).index()%3*2) / 10 + 's');
    });
    $('.com-wow4 li').each(function() {
        $(this).addClass('wow fadeInUp').attr('data-wow-delay', ($(this).index()%4*2) / 10 + 's');
    });
    $('.com-wow5 li').each(function() {
        $(this).addClass('wow fadeInUp').attr('data-wow-delay', ($(this).index()%5*2) / 10 + 's');
    });

    // 滚动效果初始化
    new WOW({offset: 200}).init();

    // 手机导航
    $('.header-m .head-nav-bars').on('click', function(){
        $(this).find('span').toggleClass('active');
        $('.header-m .nav').toggleClass('active');
    });
    $('.header-m .nav').on('click', function(){
        $(this).removeClass('active');
        $('.header-m .head-nav-bars span').removeClass('active');
    });

    // 公共切换
    $('.com-show .com-show-nav').find('.a').on('mouseenter', function(){
        $(this).addClass('active').siblings().removeClass('active');
        $(this).parents('.com-show').find('.com-show-item').eq($(this).index()).addClass('active').siblings().removeClass('active');
    });

    // 点击返回顶部
    $('.go-top').on('click', function(){
        $('body,html').animate({ scrollTop:0 }, "fast");
    });

    // 相册放大效果初始化
    $('.imgs-btn').click(function() {
        layer.photos({
          photos: $(this).parent().get(0),
          anim: 5
        });
    });

    // 点击播放视频
    $('.video-btn').click(function() {
        var vlink = $(this).data('link');
        layer.open({
            type: 2,
            title: false,
            area: ['800px', '600px'],
            shade: 0.8,
            closeBtn: 0,
            shadeClose: true,
            content: vlink
        });
    });

    // 页面滚动事件
    $(window).scroll(function () {
        if($(window).scrollTop() > 500){
            $('.go-top').fadeIn(500);
        }
        else{
            $('.go-top').fadeOut(500);
        }
    });


	// 初始化轮播
    var index_banner = new Swiper('.index-banner .swiper-container', {
        autoplay: true,
        navigation: {
            prevEl: '.index-banner .swiper-button-prev',
            nextEl: '.index-banner .swiper-button-next'
        },
        pagination: {
            el: '.index-banner .swiper-pagination',
            clickable :true,
        },
     });
    var icase = new Swiper ('.index-case .swiper-container', {
        slidesPerView: 'auto',
        autoplay: true,
        navigation: {
            prevEl: '.index-case .swiper-button-prev',
            nextEl: '.index-case .swiper-button-next'
        }
     });

    var list = new Swiper ('.pro-detail .list .swiper-container', {
        slidesPerView : 4,
        spaceBetween : 10,
        watchSlidesVisibility: true,
     });

    var detail = new Swiper ('.pro-detail .big .swiper-container', {
        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 checkForm(e) {
    var $form = $(e).parents('.J_ajaxForms');
    var name = $form.find('[name="name"]').val();
    var shouji = $form.find('[name="shouji"]').val();
    var introduce = $form.find('[name="introduce"]').val();
    if (name == '') {
        alert('请填写您的姓名');
        return false;
    }
    if (shouji == '') {
        alert('请填写您的手机');
        return false;
    }
    if (introduce == '') {
        $form.find('[name="introduce"]').val('咨询');
    }
    if(!(/^1[3456789]\d{9}$/.test(shouji))){
        alert('请填写正确的手机');
        return false;
    }
    submitForm($form);
}

function resetForm(e) {
    var $form = $(e).parents('.J_ajaxForms');
    $form.find('[name="name"]').val('');
    $form.find('[name="shouji"]').val('');
    $form.find('[name="introduce"]').val('');
    $form.find('[name="email"]').val('');
}

function submitForm($form) {
    $.ajax({
        type: "POST",
        url: $form.attr('action'),
        data: $form.serialize(),
        success: function(msg) {
            var res = JSON.parse(msg);
            if (res.status == 1) {
                alert("谢谢您的留言，我们会尽快与您联系.");
                window.location.reload();
            } else {
                alert(res.txt);
            }
        }
    });
}


// 默认动画效果修改
;(function(h) {
    h.extend(h.easing, {
        easein: function(d, a, e, b, c) {
            return b * (a /= c) * a + e
        },
        easeinout: function(d, a, e, b, c) {
            if (a < c / 2) return 2 * b * a * a / (c * c) + e;
            d = a - c / 2;
            return - 2 * b * d * d / (c * c) + 2 * b * d / c + b / 2 + e
        },
        easeout: function(d, a, e, b, c) {
            return - b * a * a / (c * c) + 2 * b * a / c + e
        },
        expoin: function(d, a, e, b, c) {
            d = 1;
            b < 0 && (d *= -1, b *= -1);
            return d * Math.exp(Math.log(b) / c * a) + e
        },
        expoout: function(d, a, e, b, c) {
            d = 1;
            b < 0 && (d *= -1, b *= -1);
            return d * ( - Math.exp( - Math.log(b) / c * (a - c)) + b + 1) + e
        },
        expoinout: function(d, a, e, b, c) {
            d = 1;
            b < 0 && (d *= -1, b *= -1);
            return a < c / 2 ? d *
            Math.exp(Math.log(b / 2) / (c / 2) * a) + e: d * ( - Math.exp( - 2 * Math.log(b / 2) / c * (a - c)) + b + 1) + e
        },
        bouncein: function(d, a, e, b, c) {
            return b - jQuery.easing.bounceout(d, c - a, 0, b, c) + e
        },
        bounceout: function(d, a, e, b, c) {
            return (a /= c) < 1 / 2.75 ? b * 7.5625 * a * a + e: a < 2 / 2.75 ? b * (7.5625 * (a -= 1.5 / 2.75) * a + 0.75) + e: a < 2.5 / 2.75 ? b * (7.5625 * (a -= 2.25 / 2.75) * a + 0.9375) + e: b * (7.5625 * (a -= 2.625 / 2.75) * a + 0.984375) + e
        },
        bounceinout: function(d, a, e, b, c) {
            return a < c / 2 ? jQuery.easing.bouncein(d, a * 2, 0, b, c) * 0.5 + e: jQuery.easing.bounceout(d, a * 2 - c, 0, b, c) * 0.5 + b * 0.5 + e
        },
        elasin: function(d,
        a, e, b, c) {
            var d = 1.70158,
            f = 0,
            g = b;
            if (a == 0) return e;
            if ((a /= c) == 1) return e + b;
            f || (f = c * 0.3);
            g < Math.abs(b) ? (g = b, d = f / 4) : d = f / (2 * Math.PI) * Math.asin(b / g);
            return - (g * Math.pow(2, 10 * (a -= 1)) * Math.sin((a * c - d) * 2 * Math.PI / f)) + e
        },
        elasout: function(d, a, e, b, c) {
            var d = 1.70158,
            f = 0,
            g = b;
            if (a == 0) return e;
            if ((a /= c) == 1) return e + b;
            f || (f = c * 0.3);
            g < Math.abs(b) ? (g = b, d = f / 4) : d = f / (2 * Math.PI) * Math.asin(b / g);
            return g * Math.pow(2, -10 * a) * Math.sin((a * c - d) * 2 * Math.PI / f) + b + e
        },
        elasinout: function(d, a, e, b, c) {
            var d = 1.70158,
            f = 0,
            g = b;
            if (a == 0) return e;
            if ((a /=
            c / 2) == 2) return e + b;
            f || (f = c * 0.3 * 1.5);
            g < Math.abs(b) ? (g = b, d = f / 4) : d = f / (2 * Math.PI) * Math.asin(b / g);
            return a < 1 ? -0.5 * g * Math.pow(2, 10 * (a -= 1)) * Math.sin((a * c - d) * 2 * Math.PI / f) + e: g * Math.pow(2, -10 * (a -= 1)) * Math.sin((a * c - d) * 2 * Math.PI / f) * 0.5 + b + e
        },
        backin: function(d, a, e, b, c) {
            return b * (a /= c) * a * (2.70158 * a - 1.70158) + e
        },
        backout: function(d, a, e, b, c) {
            return b * ((a = a / c - 1) * a * (2.70158 * a + 1.70158) + 1) + e
        },
        backinout: function(d, a, e, b, c) {
            d = 1.70158;
            return (a /= c / 2) < 1 ? b / 2 * a * a * (((d *= 1.525) + 1) * a - d) + e: b / 2 * ((a -= 2) * a * (((d *= 1.525) + 1) * a + d) + 2) + e
        },
        linear: function(d, a, e, b, c) {
            return b * a / c + e
        }
    })
})(jQuery);

// 背景相对移动动画封装
;(function($, window, document,undefined){
    $.fn.bgmove = function (options) {
        var defaults = {
            speed: 500,
            fx: 'backout'
        }
        var last = $(this).parent().find('.active');
        if (!last.length) {
            return;
        }
        var bg = $(this).parent().find('.bg');

        options = $.extend({}, defaults, options);

        var move = function(target) {
            bg.stop().animate({
                    left: (target.position() && target.position().left) + parseInt(target.css('marginLeft')),
                    width: target.outerWidth()
                },
                options.speed,
                options.fx
            );
        }
        $(this).on('mousemove', function(){
           move($(this));
        });
        $(this).parent().on('mouseleave', function(){
            move(last);
        });
        $(window).resize(function() {
            move(last);
        });
        move(last);
    }
})(jQuery, window, document);
