// js严格模式
"use strict";

// 阻止浏览器橡皮筋效果
document.addEventListener('touchmove', function(e) {
    e.preventDefault(); //阻止默认的处理方式(阻止下拉滑动的效果)
}, { passive: false }); //passive 参数不能省略，用来兼容ios和android

// 阻止body冒泡
document.body.addEventListener('touchmove', function(e) {
    e.stopPropagation();
});

// 加载动画元素父级设置相对定位，溢出隐藏
$('.blackInOut,.blackOut,.whiteOut').parent().css({ "position": "relative", "overflow": "hidden" });


// 等高
$(document).ready(function() {
    $('.c-dg').matchHeight();
});

// 导航
function cNav() {
    var oBody = $("body");
    var oHead = $("#c-header");
    var oNav = $("#c-header .c-nav");
    var oBtn = $("#c-header .c-switch");
    var oL = $("#c-header .c-nav>li");
    var oTitle = $("#c-header .c-nav2 li .c-title-box");
    var num = 0;
    var i = $(window).scrollTop();
    var oP = $("#c-placeholder");
    var b = true;
    var t = null;
    // 手机端导航显示
    oBtn.click(function() {
        if (b) {
            b = false;
            t = $(window).scrollTop();
            oBody.addClass('c-open');
            oBody.css("top", -t);
        } else {
            b = true;
            oBody.removeClass('c-open');
            oBody.css("top", "0");
            $(window).scrollTop(t);
        }
    });

    // 窗口重置隐藏手机端导航
    $(window).resize(function() {
        if ($("#c-header .c-nav").css("display") == "block") {
            oBody.removeClass('c-open');
        }
    });

    // 手机端导航栏目下拉
    oTitle.click(function() {
        $(this).next().stop().slideToggle();
    });

    // 鼠标移入导航样式
    oHead.hover(function() {
        $(this).addClass("c-style2");
    }, function() {
        if (i <= oHead.outerHeight() && oP.length == 0) {
            $(this).removeClass("c-style2");
        } else {
            $(this).addClass("c-style2");
        }
    });

    // 导航显示及样式
    function fn1() {
        if ($(window).scrollTop() - i > 0 && $(window).scrollTop() > oHead.outerHeight()) {
            i = $(window).scrollTop();
            oHead.addClass("c-head-move");
            oHead.addClass("c-style2");
        } else if ($(window).scrollTop() - i < 0) {
            i = $(window).scrollTop();
            oHead.removeClass("c-head-move");
            if ($(window).scrollTop() <= oHead.outerHeight() && oP.length == 0 && !oBody.hasClass("c-open")) {
                oHead.removeClass("c-style2");
            } else if ($(window).scrollTop() > oHead.outerHeight()) {
                oHead.addClass("c-style2");
            } else if ($(window).scrollTop() <= oHead.outerHeight() && oP.length != 0) {
                oHead.addClass("c-style2");
            }
        }
    }
    fn1();
    $(window).scroll(function() {
        oBody.removeClass('c-open');
        fn1();
    });

    // pc导航动画
    oL.each(function() {
        if ($(this).hasClass("on")) {
            num = $(this).index();
        }
        $(this).hover(function() {
                oL.eq(num).removeClass("on");
                $(this).children("ul").stop().slideDown();
            },
            function() {
                oL.eq(num).addClass("on");
                $(this).children("ul").stop().slideUp();
            });
    });
}
cNav();

// 顶部搜索
function topForm() {
    var obj = $("#c-header form");
    var oBox = obj.find(".c-box");
    obj.hover(function() {
        oBox.stop().fadeIn();
    }, function() {
        oBox.stop().fadeOut();
    });
}
topForm();

// 首页轮播
function banner1() {
    var obj = $(".c-banner1");
    var swiper = new Swiper(obj, {
        // effect : 'fade',
        loop: true,
        speed: 1000,
        autoplay: {
            delay: 3000,
            disableOnInteraction: false,
        },
        // navigation: {
        //     nextEl: '.swiper-button-next',
        //     prevEl: '.swiper-button-prev',
        // },
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        // breakpoints: {
        //     768: {
        //         slidesPerView: 3,
        //         spaceBetween: 20,
        //     }
        // }
    });
    // obj.hover(function() {
    //     swiper.autoplay.stop();
    // }, function() {
    //     swiper.autoplay.start();
    // });
}
banner1();

// 首页大事件轮播
function banner2() {
    if ($("#c-home3").length != 0) {
        var oText = $("#c-home3 .c-year");
        var oBanner2 = $(".c-banner2-2");
        var swiper1 = new Swiper($(".c-banner2-1"), {
            centeredSlides: true,
            loop: true,
            direction: 'vertical',
            slidesPerView: "auto",
            speed: 500,
        });
        var swiper2 = new Swiper($(".c-banner2-2"), {
            centeredSlides: true,
            autoplay: {
                delay: 3000,
                disableOnInteraction: false,
            },
            loop: true,
            direction: 'vertical',
            slidesPerView: "auto",
            speed: 500,
            on: {
                slideChangeTransitionStart: function() {
                    oText.text(oBanner2.find(".swiper-slide-active").text());
                },
            },
            scrollbar: {
                el: '.swiper-scrollbar',
            },
        });
        swiper1.controller.control = swiper2;
        swiper2.controller.control = swiper1;
        $("#c-home3 .c-banner2-wrap").hover(function() {
            swiper2.autoplay.stop();
        }, function() {
            swiper2.autoplay.start();
        });
    }
}
banner2();

// 发展历程轮播
function banner3() {
    var obj = $(".c-banner3");
    var swiper = new Swiper(obj, {
        loop: true,
        slidesPerView: 5,
        speed: 500,
        spaceBetween: 20,
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        breakpoints: {
            1580: {
                slidesPerView: 4,
            },
            1260: {
                slidesPerView: 3,
            },
            972: {
                slidesPerView: 2,
            },
            748: {
                slidesPerView: 1,
            }
        }
    });
    obj.hover(function() {
        swiper.autoplay.stop();
    }, function() {
        swiper.autoplay.start();
    });
}
banner3();

// 物业服务、核心产品轮播
function banner4() {
    var obj = $(".c-banner4");
    obj.each(function() {
        var swiper = new Swiper($(this), {
            loop: true,
            slidesPerView: 3,
            speed: 500,
            spaceBetween: 20,
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            },
            breakpoints: {
                1260: {
                    slidesPerView: 2,
                },
                972: {
                    slidesPerView: 2,
                },
                748: {
                    slidesPerView: 1,
                }
            }
        });
        $(this).hover(function() {
            swiper.autoplay.stop();
        }, function() {
            swiper.autoplay.start();
        });

    });
}
banner4();

// 首页大事件轮播
function banner5() {
    if ($("#c-news1").length != 0) {

        var oDot = $("#c-news1 .c-banner-wrap .c-dot");
        var str = "";
        var num1 = $("#c-news1 .c-banner-wrap .c-banner5-1 .c-wrap").length;
        for (var i = 0; i < num1; i++) {
            str += "<div></div>";
        }
        oDot.html(str);
        var aDot = $("#c-news1 .c-banner-wrap .c-dot div");
        aDot.eq(0).addClass("on");

        var num2 = 0;
        var swiper1 = new Swiper($(".c-banner5-1"), {
            loop: true,
            speed: 500,
        });
        var swiper2 = new Swiper($(".c-banner5-2"), {
            autoplay: {
                delay: 3000,
                disableOnInteraction: false,
            },
            loop: true,
            speed: 500,
            on: {
                slideChange: function() {
                    if (this.activeIndex > num1) {
                        num2 = 0;
                    } else if (this.activeIndex < 1) {
                        num2 = num1 - 1;
                    } else {
                        num2 = this.activeIndex - 1
                    }
                    aDot.eq(num2).addClass("on").siblings().removeClass("on");
                },
            },
        });
        swiper1.controller.control = swiper2;
        swiper2.controller.control = swiper1;
        $("#c-news1 .c-banner-wrap").hover(function() {
            swiper2.autoplay.stop();
        }, function() {
            swiper2.autoplay.start();
        });
        aDot.click(function() {
            console.log($(this).index())
            swiper2.slideTo($(this).index() + 1, 500, false);
        });
    }
}
banner5();

// 多彩园区
function service3() {
    var aLi1 = $("#c-service3 .c-list1 li");
    var aLi2 = $("#c-service3 .c-list2 li");
    var num = 0;

    function fn1() {
        aLi1.eq(num).addClass("on").siblings().removeClass("on");
        aLi2.eq(num).addClass("on").siblings().removeClass("on");
    }
    fn1();
    aLi1.click(function() {
        num = $(this).index();
        fn1();
    });
}
service3();

// 职位展开
$(".c-join-list.c-dt>li").each(function() {
    var _this = $(this);
    $(this).find(".c-more-btn").click(function() {
        $(this).prev().stop().slideToggle();
        $(this).toggleClass("on");
    });
});

// 可视化数据滚动
function visualData(obj) {
    $(window).load(function() {
        obj.each(function() {
            var h = Number($(this).html());
            var t = "";
            var n = Math.ceil(h / 20);
            var a = true;
            var This = $(this);
            if ($(this).length != 0) {
                t = $(this).offset().top;
            }
            This.html(0);
            fn1();
            $(window).scroll(function() {
                fn1();
            });

            function fn1() {
                var wT = $(window).scrollTop();
                if (wT > t - $(window).height() + 50 && wT < t - 50 && a == true) {
                    a = false;
                    var y = 0;
                    var timer2 = setInterval(function() {
                        if (y >= h) {
                            y = h;
                            clearInterval(timer2);
                        }
                        This.html(y);
                        y += n;
                    }, 100);
                }
            }
        });
    });
}
visualData($(".c-num-move"));


// 侧边栏回到顶部
function goTop() {
    var obj = $("#c-go-top");
    var oBtn = $("#c-go-top");
    oBtn.click(function() {
        $("html,body").animate({ scrollTop: 0 }, 500);
    });

    function fn1() {
        if ($(window).scrollTop() > $(window).height()) {
            obj.fadeIn();
        } else {
            obj.fadeOut();
        }
    }
    fn1();
    $(window).scroll(function() {
        fn1();
    });
}
goTop();

// 底部导航
function footerNav() {
    var aList = $("#c-footer .c-list-box");
    if ($(window).width() <= 972) {
        aList.each(function() {
            var This = $(this);
            $(this).find(".c-title-box").click(function() {
                This.toggleClass("on");
                This.find(".c-list").stop().slideToggle();
            });
        });
    }
}
footerNav();

// 点击底部微信弹出二维码
function weixin() {
    var a = $(".c-common-box2 .c-wx-btn");
    var b = $("#c-footer .c-wx-btn");
    var w = $("#c-footer .c-weixin");
    var d = w.find(".c-img-box");
    a.click(function() {
        w.stop().fadeToggle();
    });
    b.click(function() {
        w.stop().fadeToggle();
    });
    d.click(function() {
        return false;
    });
    w.click(function() {
        w.stop().fadeToggle();
    });
}
weixin();



// 页面进入动画
(function($) {
    function wow() {
        var t = .1,
            e = !0,
            wow = new WOW({
                boxClass: "wow",
                animateClass: "animated",
                offset: 0,
                callback: function(e) {
                    (e = $(e)).css("animation-delay", t.toFixed(1) + "s"),
                        t += .1;
                }
            });
        $(window).scroll(function() {
                e && (t = .2, setTimeout(function() {
                    e = !0
                }, 150), e = !1)
            }),
            wow.init();
    }
    wow();
}(jQuery));


// 运动曲线
$.extend(jQuery.easing, {
    easeIn: function(x, t, b, c, d) { //加速曲线 
        return c * (t /= d) * t + b;
    },
    easeOut: function(x, t, b, c, d) { //减速曲线 
        return -c * (t /= d) * (t - 2) + b;
    },
    easeBoth: function(x, t, b, c, d) { //加速减速曲线 
        if ((t /= d / 2) < 1) { return c / 2 * t * t + b; }
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },
    easeInStrong: function(x, t, b, c, d) { //加加速曲线 
        return c * (t /= d) * t * t * t + b;
    },
    easeOutStrong: function(x, t, b, c, d) { //减减速曲线
        return -c * ((t = t / d - 1) * t * t * t - 1) + b;
    },
    easeBothStrong: function(x, t, b, c, d) { //加加速减减速曲线
        if ((t /= d / 2) < 1) { return c / 2 * t * t * t * t + b; }
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    },
    elasticIn: function(x, t, b, c, d, a, p) { //正弦衰减曲线（弹动渐入）
        if (t === 0) { return b; }
        if ((t /= d) == 1) { return b + c; }
        if (!p) { p = d * 0.3; }
        if (!a || a < Math.abs(c)) { a = c; var s = p / 4; } else { var s = p / (2 * Math.PI) * Math.asin(c / a); }
        return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
    },
    elasticOut: function(x, t, b, c, d, a, p) { //正弦增强曲线（弹动渐出
        if (t === 0) { return b; }
        if ((t /= d) == 1) { return b + c; }
        if (!p) { p = d * 0.3; }
        if (!a || a < Math.abs(c)) { a = c; var s = p / 4; } else { var s = p / (2 * Math.PI) * Math.asin(c / a); }
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    },
    elasticBoth: function(x, t, b, c, d, a, p) { if (t === 0) { return b; } if ((t /= d / 2) == 2) { return b + c; } if (!p) { p = d * (0.3 * 1.5); } if (!a || a < Math.abs(c)) { a = c; var s = p / 4; } else { var s = p / (2 * Math.PI) * Math.asin(c / a); } if (t < 1) { return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; } return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + c + b; },
    backIn: function(x, t, b, c, d, s) { //回退加速（回退渐入）
        if (typeof s == 'undefined') { s = 1.70158; }
        return c * (t /= d) * t * ((s + 1) * t - s) + b;
    },
    backOut: function(x, t, b, c, d, s) {
        if (typeof s == 'undefined') {
            s = 3.70158; //回缩的距离 
        }
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    backBoth: function(x, t, b, c, d, s) { if (typeof s == 'undefined') { s = 1.70158; } if ((t /= d / 2) < 1) { return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; } return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; },
    bounceIn: function(x, t, b, c, d) { //弹球减振（弹球渐出） 
        return c - this['bounceOut'](x, d - t, 0, c, d) + b;
    },
    bounceOut: function(x, t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b; } return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b; },
    bounceBoth: function(x, t, b, c, d) { if (t < d / 2) { return this['bounceIn'](x, t * 2, 0, c, d) * 0.5 + b; } return this['bounceOut'](x, t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b; }
});