// IE10以下浏览器提示
function hiUpgrade() {
    window.AESKey = '';
    // 判断浏览器是否支持placeholder属性
    function isSupportPlaceholder() {
        var input = document.createElement('input');
        return 'placeholder' in input;
    };
    //判断是否是IE浏览器，包括Edge浏览器
    function IEVersion() {
        //取得浏览器的userAgent字符串
        var userAgent = navigator.userAgent;
        //判断是否IE浏览器
        var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
        if (isIE) {
            // ie10及以下
            var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
            reIE.test(userAgent);
            var fIEVersion = parseFloat(RegExp["$1"]);
            if (fIEVersion < 10 || !isSupportPlaceholder()) {
                return true;
            }
        } else {
            return false;
        }
    }
    var tpl = '<div id="hi-upgrade"><div class="hi-wrap"><p class="hi-title">无法正常浏览本网站！</p><div class="hi-close">继续浏览</div><div class="hi-text1"><p>1、您的浏览器版本过低，请升级您的浏览器。</p><p>2、如果您的浏览器是最新版本，请<span>切换到极速模式</span>访问。</p><p>3、您使用的是IE10以下的浏览器，建议您<span>使用主流浏览器</span>访问。</p></div><p class="hi-text2"><span>主流浏览器下载</span></p><ul class="hi-list"><li><a href="https://www.google.cn/intl/zh-CN/chrome/" target="_blank"><div class="hi-ico1"></div><p>谷歌浏览器</p></a></li><li><a href="http://www.firefox.com.cn/download/" target="_blank"><div class="hi-ico2"></div><p>火狐浏览器</p></a></li><li><a href="http://browser.360.cn" target="_blank"><div class="hi-ico3"></div><p>UC浏览器</p></a></li><li><a href="https://www.uc.cn" target="_blank"><div class="hi-ico4"></div><p>360浏览器</p></a></li><li><a href="https://browser.qq.com" target="_blank"><div class="hi-ico5"></div><p>QQ浏览器</p></a></li><li><a href="https://ie.sogou.com" target="_blank"><div class="hi-ico6"></div><p>搜狗浏览器</p></a></li></ul></div></div>';
    if (IEVersion()) {
        document.write(tpl);
    }
}
hiUpgrade();

// 使用IE浏览器提示
// function hiUpgrade() {
//     window.AESKey = '';
//     // 判断浏览器是否支持placeholder属性
//     function isSupportPlaceholder() {
//         var input = document.createElement('input');
//         return 'placeholder' in input;
//     };
//     //判断是否是IE浏览器，包括Edge浏览器
//     function IEVersion() {
//         //取得浏览器的userAgent字符串
//         var userAgent = navigator.userAgent;
//         //判断是否IE浏览器
//         var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
//         if (isIE) {
//             // ie10及以下
//             var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
//             reIE.test(userAgent);
//             var fIEVersion = parseFloat(RegExp["$1"]);
//             if (fIEVersion <= 10 || !isSupportPlaceholder()) {
//                 return true;
//             }
//         } else if (!!window.ActiveXObject || "ActiveXObject" in window) {
//             // ie11
//             return true;
//         } else {
//             return false;
//         }
//     }
//     var tpl = '<div id="hi-upgrade"><div class="hi-wrap"><p class="hi-title">无法正常浏览本网站！</p><div class="hi-close">继续浏览</div><div class="hi-text1"><p>1、您的浏览器版本过低，请升级您的浏览器。</p><p>2、如果您的浏览器是最新版本，请<span>切换到极速模式</span>访问。</p><p>3、您使用的是IE浏览器，请<span>使用主流浏览器</span>访问。</p></div><p class="hi-text2"><span>主流浏览器下载</span></p><ul class="hi-list"><li><a href="https://www.google.cn/intl/zh-CN/chrome/" target="_blank"><div class="hi-ico1"></div><p>谷歌浏览器</p></a></li><li><a href="http://www.firefox.com.cn/download/" target="_blank"><div class="hi-ico2"></div><p>火狐浏览器</p></a></li><li><a href="http://browser.360.cn" target="_blank"><div class="hi-ico3"></div><p>UC浏览器</p></a></li><li><a href="https://www.uc.cn" target="_blank"><div class="hi-ico4"></div><p>360浏览器</p></a></li><li><a href="https://browser.qq.com" target="_blank"><div class="hi-ico5"></div><p>QQ浏览器</p></a></li><li><a href="https://ie.sogou.com" target="_blank"><div class="hi-ico6"></div><p>搜狗浏览器</p></a></li></ul></div></div>';
//     if (IEVersion()) {
//         document.write(tpl);
//     }
// }
// hiUpgrade();


// 刷新页面直接回到顶部
// if (history.scrollRestoration) {
//     history.scrollRestoration = 'manual';  //auto刷新在当前位置  manual刷新在头部位置
// }

// 设置:root变量
function setRootDefault(name,key){
    document.documentElement.style.setProperty(name,key);
}
function setAllRoot(){
    setRootDefault("--color",'#005CE6');
    setRootDefault("--vh",$(window).height()+'px');
}
setAllRoot();
$(window).resize(function() {
    setAllRoot();
});




// 导航
function headNav() {
    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 = 0;
    var oP = $("#c-placeholder");
    var b = true;
    var t = null;

    // 窗口重置隐藏手机端导航
    $(window).resize(function() {
        if ($(window).width()>991) {
            oBody.removeClass('c-open');
        }
    });

    // 手机端导航栏目下拉
    oTitle.click(function() {
        $(this).next().stop().slideToggle();
        $(this).toggleClass("on");
    });

    // 鼠标移入导航样式
    oHead.hover(function() {
        $(this).addClass("c-style2");
    }, function() {
        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");
        }
    });

    // 手机端导航显示
    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);
        }
    });

    // 导航显示及样式
    function fn1() {
        if ($(window).scrollTop() - i > 0 && $(window).scrollTop() > oHead.outerHeight() && !oBody.hasClass("c-open")) {
            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() {
        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();
            });
    });
}
headNav();

// 顶部搜索
// 下拉搜索
$("#c-header .c-gn .x-btt").hover(function(){
    $("#c-header .x-sxia").stop().slideToggle()
})

// function headSearch() {
//     var obj = $("#c-header form");
//     var oBox = obj.find(".c-box");
//     obj.hover(function() {
//         oBox.stop().fadeIn();
//     }, function() {
//         oBox.stop().fadeOut();
//     });
//     // obj.submit(function(){
//     //     if(!$(this).find("input").val()){
//     //         layer.msg('请输入搜索的关键词！', {
//     //             icon: 7
//     //         });
//     //         return false;
//     //     }
//     // });
// }
// headSearch();

// 首页轮播
// function homeBanner() {
//     var swiper = new Swiper(".x-index1 .swiper-container", {
//         effect : 'fade',
//         // loop: true,
//         // speed: 800,
//         fadeEffect: {
//             crossFade: true,
//         },
//         autoplay: {
//             delay: 3000,
//             disableOnInteraction: false,
//         },
//         // navigation: {
//         //     nextEl: '.swiper-button-next',
//         //     prevEl: '.swiper-button-prev',
//         // },
//         // pagination: {
//         //     el: '.swiper-pagination',
//         //     clickable: true,
//         // },
//         // breakpoints: {
//         //     767: {
//         //         slidesPerView: 3,
//         //         spaceBetween: 20,
//         //     }
//         // }
//         on:{
//             init: function(){
//               swiperAnimateCache(this); //隐藏动画元素 
//               swiperAnimate(this); //初始化完成开始动画
//             }, 
//             slideChangeTransitionEnd: function(){ 
//               swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
//               //this.slides.eq(this.activeIndex).find('.ani').removeClass('ani'); 动画只展现一次，去除ani类名
//             } 
//         },
//     });
//     // // 设置全屏
//     // HiSetClientHeight({
//     //     element:$(".c-home-banner .swiper-slide img"),//设置全屏的元素（此元素已循环，可为多个元素设置全屏）
//     //     subtractedHeight:$("#c-header").outerHeight(),//全屏减去的高度
//     // });
// }
// homeBanner();


function handleVideoSlideChange(swiper) {
    // 将所有非激活幻灯片中的视频静音
    // $(".x-index1 .swiper-slide:not(.swiper-slide-active) video").each(function() {
    //     this.muted = true;
    // });

    if (swiper && swiper.params) {
        if ($(".x-index1 .swiper-slide-active video").length != 0) {
            var oV = $(".x-index1 .swiper-slide-active video");
            // oV[0].muted = false; // 取消静音
            if (oV[0].readyState < 4) {
                // 视频还没有加载完毕，不执行切换操作
                oV.on("loadeddata", function () {
                    handleVideoSlideChange(swiper);
                });
                return;
            }
            swiper.autoplay.stop();
            var oTime = oV[0].duration;
            oV[0].currentTime = 0;
            swiper.params.autoplay.delay = (oTime * 1000) - 500;
            oV.trigger('play');
            oV[0].addEventListener("ended", function () {
                swiper.slideNext();
                swiper.autoplay.start();
            });
        }else{
         swiper.params.autoplay.delay = 5000;
        }
    }
}

function banner1() {
    var obj = $(".x-index1 .swiper-container");
    var oS = $(".x-index1 .swiper-slide");
    var oKg = true;

    var swiper1 = new Swiper(obj, {
        loop: true,
        speed: 1000,
        autoplay: {
            delay: 4000,
            disableOnInteraction: false,
        },
        observer: true,
        observeParents: true,
        navigation: {
            nextEl: '.x-index1 .x-next',
            prevEl: '.x-index1 .x-prev',
        },
        on: {
            init: function () {
                swiperAnimateCache(this); //隐藏动画元素 
                swiperAnimate(this); //初始化完成开始动画
                var _this = this;
                if ($(".x-index1 .swiper-slide-active video").length != 0) {
                    _this.autoplay.stop();
                    var oV = $(".x-index1 .swiper-slide-active video");
                    // oV[0].muted = false; // 取消静音
                    if (oV[0].readyState < 4) {
                        // 视频还没有加载完毕，不执行切换操作
                        oV.on("loadeddata", function () {
                            _this.init();
                        });
                        return;
                    }
                    var oTime = oV[0].duration;
                    oV[0].currentTime = 0;
                    _this.params.autoplay.delay = (oTime * 1000) - 500;
                    oV.trigger('play');
                    oV[0].addEventListener("ended", function () {
                        _this.slideNext();
                        _this.autoplay.start();
                    });
                }
            },
            slideChangeTransitionStart: function () {
                handleVideoSlideChange(this);
            },
            slideChangeTransitionEnd: function(){ 
              swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
            },
        },    
    });
}

$(document).ready(function () {
    banner1();
});




// 可视化数据滚动
function visualData(obj) {
    $(document).ready(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 sidePop() {
    var obj = $("#c-go-top");
    function fn1() {
        if ($(window).scrollTop() > $(window).height()) {
            obj.fadeIn();
        } else {
            obj.fadeOut();
        }
    }
    fn1();
    $(window).scroll(function() {
        fn1();
    });
}
sidePop();

// 页面回到顶部
function goTop() {
    $("html,body").animate({ scrollTop: 0 }, 500);
}

// 底部导航
function footerNav() {
    var aList = $(".x-foot .c-list-box");
    aList.each(function() {
        var This = $(this);
        $(this).find(".c-title-box").click(function() {
            if ($(window).width() < 768) {
                This.toggleClass("on");
                This.find(".c-list").stop().slideToggle();
            }
        });
    });
}
footerNav();

// 二维码弹窗
function codePop() {
    var b = $("#c-footer .c-code-btn");
    var w = $("#c-code-pop");
    var c = w.find(".c-close");
    var d = w.find(".c-img-box");
    var oImg = w.find(".c-img-box>img");
    b.click(function() {
        oImg.attr("src",$(this).data("img-src"));
        w.stop().fadeToggle();
        
    });
    d.click(function() {
        return false;
    });
    w.click(function() {
        w.stop().fadeToggle();
    });
    c.click(function() {
        w.stop().fadeToggle();
    });
}
codePop();

// 鼠标跟随
function imousehover(obj,obj2){
    // 鼠标跟随效果
    const isPad =
    navigator.maxTouchPoints &&
    navigator.maxTouchPoints > 2 &&
    /MacIntel/.test(navigator.platform);

    // 鑷畾涔夐紶鏍�
    class CustomCursor {
        constructor(hoverItems) {
        this.cursor = obj;
        this.cursorInner = $(".inner", this.cursor);
        this.pageX = 0;
        this.pageY = 0;
        this.move = true;
        this.hoverItems = hoverItems;
        }
    
        init() {
        if (this.cursor[0]) {
            this.initCursor();
            this.initHovers();
            this.initMove();
        }
        }
    
        initCursor() {
        this.pageX = $(window).width() / 2 - 50;
        this.pageY = $(window).height() / 2 - 50;
        $(document).on("mousemove", (e) => {
            this.pageX = e.clientX;
            this.pageY = e.clientY;
        });
        const render = () => {
            if(this.move) {
            window.TweenMax.to(this.cursor, 0.5, {
                x: this.pageX,
                y: this.pageY,
                ease: "Power1.easeOut",
            });
            }
            requestAnimationFrame(render);
        };
        render();
        }
    
        initHovers() {
        const handleMouseEnter = (e) => {
            window.TweenMax.to(this.cursor, 0.5, {
            scale: 1,
            opacity: 1,
            ease: "Power1.easeOut",
            });
            e.stopPropagation();
        };
        const handleMouseLeave = () => {
            window.TweenMax.to(this.cursor, 0.5, {
            scale: 0,
            opacity: 0,
            ease: "Power1.easeOut",
            });
            
            // this.cursor.removeClass(function (i, v) {return v.replace('cursor', '');});
        };
        this.hoverItems.each(function (i, item) {
            $(item).on("mouseenter", handleMouseEnter);
            $(item).on("mouseleave", handleMouseLeave);
        });
        }
        initMove() {
        const handleMouseMove = (e) => {
            if($(e.target).closest('.owl-nav')[0]) {
                this.initCircle(e.target, "[class*='owl-']");
            } else if($(e.target).closest('.searchOnOff')[0]) {
                this.initCircle(e.target, ".searchOnOff");
            } else {
                window.TweenMax.to(this.cursor, 0.5, {
                    scale: 1,
                    // background: 'yellow',
                    ease: "Power1.easeOut",
                });
                window.TweenMax.to(this.cursorInner, 0.5, {
                    opacity: 1,
                    ease: "Power1.easeOut",
                });
                this.move = true;
            }
            if($(e.currentTarget).hasClass('ff_topSlider') || $(e.currentTarget).parents('.mlist.project')[0]) {
            // const sxPos = (e.clientX / window.innerWidth) * 200 - 100;
            // this.cursor.toggleClass("next", sxPos > 0);
                this.cursor.addClass('more');
            } else if($(e.currentTarget).hasClass('videom') || $(e.currentTarget).parents('.bodyvideom')[0]) {
                this.cursor.addClass('play');
            } else if($(e.currentTarget).parents('.team_tabs')[0]) {
                this.cursor.addClass('drag');
            } else if($(e.currentTarget).hasClass('post-next')) {
                this.cursor.addClass('next');
            }
        };
        
        this.hoverItems.each(function (i, item) {
            $(item).on("mousemove", item, handleMouseMove);
        });
        }
        initCircle(target, elm) {
        var _sTop = $(window).scrollTop();
        var _offset = Math.min($(target).closest(elm).outerWidth(), $(target).closest(elm).outerHeight());
        var _x = Math.round($(target).closest(elm).offset().left + _offset / 2);
        var _y = Math.round($(target).closest(elm).offset().top + _offset / 2 - _sTop);
        this.move = false;
        window.TweenMax.to(this.cursor, 0.5, {
            scale: 0.5,
            x: _x,
            y: _y,
            background: 'rgba(255,255,255,0)',
            ease: "Power1.easeOut",
        });
        window.TweenMax.to(this.cursorInner, 0.5, {
            opacity: 0,
            ease: "Power1.easeOut",
        });
        }
    }

    if(!isPad) {
        // 澧炲姞榧犳爣鐘舵€�
        // $('body').append('<div class="cursor"><div class="inner">More</div></div>');
        const cursor = new CustomCursor(obj2);
        cursor.init();
    }
}

// 引用鼠标跟随效果
if($(window).width() > 991){
    imousehover($('.about .box3 .container2 .list .box3-mouse'),$('.about .box3 .container2 .list'));
    imousehover($('.about .box4 .container2 .list .box4-mouse'),$('.about .box4 .container2 .list'));
    imousehover($('.about .box5 .container2 .list .box5-mouse'),$('.about .box5 .container2 .list'));
    imousehover($('.safety-guarantee .container2 .list .box-mouse'),$('.safety-guarantee .container2 .list'));
    imousehover($('.quality .box3 .container2 .list .box-mouse'),$('.quality .box3 .container2 .list'));
}

//文字歌词效果
function HiTextLyric2(data) {
    var obj1=data.element;
    var obj2=data.element2;
    var regex = /(<br>|\S)/g;
    var nNum=data.offset;
    var sClass=data.class;
    var duration=data.duration;
    if (obj1.length != 0) {
        obj2.each(function(){
            var _this = $(this);
            var arr = _this.html().match(regex);
            _this.html('');
            var str = '';
            arr.forEach(element => {
                str+='<span>'+element+'</span>';
            });
            _this.html(str);
            // var obj3 = _this.find('span');
            // var a = duration/obj3.length;
        });
    }
}

// 调用 文字歌词效果
HiTextLyric2({
    element:$(".text7"),//进入可视区的元素
    element2:$(".text7"),//执行效果的元素
});

$(".text7 span").addClass(" wow fadeInUp3")


if($(".pub-btn").length > 0){
    $(".pub-btn").each(function(){
        // let thisindex = $(this).index()
        // console.log(thisindex)
        HiAddClass({
            element:$(this),//进入可视区的元素
            element2:$(this),//添加class的元素（此元素已循环，可为多个元素添加class）
            class:'on',//添加的class名
            offset: 0.3,//距离可视区底部位置添加class(0为底部，0.5为一半，1为顶部)
            once:false,//是否只执行一次（即每次进入可视区是否都会重新执行）
        });
    })
}





HiVideoPlay({
    element:$(".x-index1"),//进入可视区的元素
    element2:$(".x-index1 .x-con .swiper-container .swiper-wrapper .swiper-slide .public-img video"),//要播放的视频元素（此元素已循环，可执行多个视频播放）
    offset: 0,//距离可视区底部位置播放视频(0为底部，0.5为一半，1为顶部)
    once:false,//是否只执行一次（即每次进入可视区是否都会重新执行）
});


HiVideoPlay({
    element:$(".about .box2"),//进入可视区的元素
    element2:$(".about .box2 .bg video"),//要播放的视频元素（此元素已循环，可执行多个视频播放）
    offset: 0.5,//距离可视区底部位置播放视频(0为底部，0.5为一半，1为顶部)
    once:false,//是否只执行一次（即每次进入可视区是否都会重新执行）
});