/* 
 * WuCan  phone:18588262364 
 * https://juejin.cn/user/1767670430828375
 * https://gitee.com/kingdom10
 * http://124.71.81.168/
 * */

//渐滚渐现 参数：绑定块类名，延迟时间，动画模式(1为只运行一次，默认为无限)，自定义动画类名(默认为向上渐隐渐现)
function fadeAnim(_node, time, num, animClass) {
    $("body").append('<div class="fixed_top"></div>');
    var topValue = $(".fixed_top").offset().top;
    var bTop = $(_node).offset().top - $(window).height();
    var timeB = time > 2 ? time : 0;
    var numB = time < 2 ? time : 0;
    numB = num ? num : numB;
    var animClassB = "animTop";
    if (typeof animClass == "string") {
        animClassB = animClass;
    } else if (typeof time == "string") {
        animClassB = time;
    } else if (typeof num == "string") {
        animClassB = num;
    }
    //if (client.browser.ie != 7) {  //不支持IE7
    function animFun() {
        $(_node).addClass("animInto");
        bTop = $(_node).offset().top - $(window).height() + 100;
        if ($(_node).index() > $(_node).length - 1) { //最后一个块处理（防止小高度块不出现）
            bTop -= 110
        }
        if (topValue > bTop) {
            setTimeout(function () {
                $(_node).addClass(animClassB);
            }, timeB)
        } else if (numB != 1) {
            $(_node).removeClass(animClassB);
        }
    }

    animFun();
    $(window).scroll(function () {
        topValue = $(".fixed_top").offset().top;
        animFun(_node);
    })
    //}
}
//fadeAnim(".class",400,1,"animClass");


//添加触发与操作active  参数：触发块、操作块、指定事件（默认mouseenter）
function addActive(enterSelect, blockSelect, event) {
    var m = []
    var n = m.length
    var event = event || "mouseenter"
    m.push(0)
    function showBlock() {
        $(enterSelect).eq(m[n]).addClass("active").siblings().removeClass("active");
        $(blockSelect).eq(m[n]).addClass("active").siblings().removeClass("active");
    }
    $(enterSelect).on(event, function () {
        m[n] = $(this).index();
        showBlock()
    }).eq(0).trigger(event)
    n++
}
//addActive(".ho_li", ".ho_liBl","click")


$(function () {
    //判断IE6、7、8提示下载新版IE
    function IEVersion() {
        var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
        var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
        var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
        var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
        if (isIE) {
            var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
            reIE.test(userAgent);
            var fIEVersion = parseFloat(RegExp["$1"]);
            if (fIEVersion == 7) {
                return 7;
            } else if (fIEVersion == 8) {
                return 8;
            } else if (fIEVersion == 9) {
                return 9;
            } else if (fIEVersion == 10) {
                return 10;
            } else {
                return 6; //IE版本<=7
            }
        } else if (isEdge) {
            return 'edge'; //edge
        } else if (isIE11) {
            return 11; //IE11  
        } else {
            return -1; //不是ie浏览器
        }
    }
    if (IEVersion() > 5 && IEVersion() < 9) {
        $("body").append('<div class="hint_content" style="position: fixed;top: 0px;left: 0px;width: 100%;height: 100%;z-index: 9999999; background: #eeeeee;"><img src="/images/t_1.jpg" style="position: fixed;top: 50%;left: 50%;margin-top: -248px;margin-left: -412px;"><a href="https://www.microsoft.com/zh-cn/edge" target="_block" style="position: absolute;top: 50%;z-index: 90;left: 50%;margin-left: -180px;margin-top: 101px;text-decoration: underline;font-size: 18px;">前往下载：https://www.microsoft.com/zh-cn/edge</a></div>')
    }

    //全屏自适应
    var wHeight = $(window).height();
    function resize() {
        wHeight = $(window).height();
        $(".com_conBlock").css({
            minHeight: wHeight - $(".com_banner").height() - $("#Footer").outerHeight() + 3  //设定内容块全屏的最小高
        });
    }
    setTimeout(function () {
        $(".com_img img").imagesLoaded(function () {
            resize();
        })
    }, 10)
    $(window).resize(function () {
        resize();
    });

    // 前端自适应双图处理，类名绑定（img_node绑图，bg_node绑背景），w-src(对应PC)，t-src（对应微站）
    $(".img_node,.video_node").each(function () {
        var _this = $(this);
        if ($(window).width() > 768) {
            _this.attr("src", $(this).attr("w-src"));
        } else {
            var src = $(this).attr("t-src") || $(this).attr("w-src");
            _this.attr("src", src);
        }
    })
    $(".bg_node").each(function () {
        var _this = $(this);
        if ($(window).width() > 768) {
            _this.css("background-image", "url(" + $(this).attr("w-src") + ")");
        } else {
            var src = $(this).attr("t-src") || $(this).attr("w-src");
            _this.css("background-image", "url(" + src + ")");
        }
    })


    //导航选中状态
    function navActive(ar, select) {
        var href = location.href.toLowerCase();
        var i = 0;
        ar.forEach(function (item, m) {
            function bindIndex(text) {
                if (href.indexOf(text) > 0) {
                    i = m + 1;
                }
            }
            if (item instanceof Array) {  //如果是数组，需进行二层遍历
                item.forEach(function (inItem, n) {
                    bindIndex(inItem);
                })
            } else {
                bindIndex(item);
            }
        })
        $(select).eq(i).addClass("active");
    }
    //默认选中第一个栏目，参数从第二栏目开始放
    navActive(["/aboutus/", "/project/", "/solutions/", "/advantages/", "news",  "/human/", "/contact/"], ".he_liBl"); //一级导航选中
    var navAr = [["/xincai", "/video", "/social", "/electronics"], ["/culture", "/training", "/consumer"], ["team","/feature"]]
    navActive(navAr, ".active .he_ul a"); //二级导航选中

    var navUl = $(".active .he_ul a").clone();
    if ($(".active .he_ul a").length < 1) {
        $(".com_li").eq(2).remove();
    }
    $(".nav_ul").html(navUl);//页面二级导航拷贝


    //二级导航
    if ($(window).width() >= 768) {
        $(".he_liBl").hover(function () {
            $(this).find(".he_block").css({ "display": "block" });
        }, function () {
            $(".he_block").css({ "display": "none" });
        })
    } else {//移动端二级导航
        $(".he_liBl").on("click", function () {
            $(this).find(".he_block").stop(true, true).slideToggle();
            $(this).siblings().find(".he_block").stop(true, true).slideUp();
            $(this).toggleClass("active").siblings().removeClass("active");
            $(".tou_ico").html("+");
            if ($(this).hasClass("active")) {
                $(this).find(".tou_ico").html("-");
            }
        })
    }

    //参数选中
    var href = location.href;
    var pa = parseInt(href.split("on=")[1]) || 0;
    if (href.indexOf("on=") > 0) {
        $(".nav_ul a").eq(pa).addClass("active").siblings().removeClass("active");
        $(".active .he_ul a").eq(pa).addClass("active").siblings().removeClass("active");
    }

    //自动标题与面包屑
    $(".this_span").html($(".nav_ul a.active").text());
    $(".this_nav").html($(".he_liBl.active .he_a").text());
    //$(".com_ti").html($(".he_liBl.active .he_a").attr('tiEn'));
    //var bannerNode = '<img src="' + $(".he_liBl.active .he_a").attr('banner') + '"/>'
    //$(".com_img").html(bannerNode);
    var t = href.indexOf('/Solutions/') > 0 ? "解决方案" : ''
    if ($(".he_liBl.active .he_ul").length < 1) {
        $(".com_tiCh").html($(".he_liBl.active .he_a").text());
        $(".com_tiEn").html($(".he_liBl.active .he_a").attr('tiEn'));
    } else {
        $(".com_tiCh").html($(".nav_ul a.active").text() + t);
        $(".com_tiEn").html($(".nav_ul a.active").attr('tiEn'));
    }

    //统一初始化公共swiper	
    if ($(".swiper-container.comSwiper").length > 0) {
        $(".swiper-container.comSwiper").each(function (n) {
            if ($(this).find(".swiper-slide").length > 1) {
                var cl = "swiper" + n
                var m = parseInt($(this).attr("num")) || 1
                if ($(window).width() < 800) {m = 1}
                $(this).addClass(cl);
                $(this).after('<div class="comIco ' + cl + '"></div><div class="sw_prev ' + cl + '"></div><div class="sw_next ' + cl + '"></div>')
                var swArr = [];
                swArr[n] = new Swiper('.swiper-container.' + cl, {
                    //autoplay: 5000,
                    speed: 600,
                    loop: true,
                    slidesPerView: m,
                    autoplayDisableOnInteraction: false,
                    pagination: '.comIco.' + cl,
                    paginationClickable: true,
                    watchActiveIndex: true,//即时更新索引值
                    calculateHeight: true,//计算容器高度
                    resizeReInit: true,//窗口变化重新初始化
                    updateOnImagesReady: true,//加载完成重新初始化。
                })
                $("body").on("click", ".sw_prev." + cl, function () {
                    swArr[n].swipePrev();
                })
                $("body").on("click", ".sw_next." + cl, function () {
                    swArr[n].swipeNext();
                })
                $("body").on("mouseenter", ".comIco." + cl + " span", function () {
                    var on = $(this).index();
                    swArr[n].swipeTo(on);
                })
            }
        })
    }


    //视频(关联有样式)   
    function videoResize() {
        var topV = 0
        var wHeight = $(window).height()
        var videoHeight = $(".videoBl_conBlock video").height()
        if (videoHeight > wHeight) {
            topV = 0
            $(".videoBl_conBlock video,.videoBl_clear").css({ "height": wHeight })
        } else {
            topV = (wHeight - videoHeight) / 2;
        }
        $(".videoBl_conBlock video,.videoBl_clear").css({ "top": topV })
    }
    $(".vid_button").on("click", function () {
        if ($(".vidBl_content").length < 1) {
            $("body").append('<div class="vidBl_content"><div class= "vidBl_bg" ></div ><div class="videoBl_conBlock"></div><div class="videoBl_clear"><img src="/images/close.png" /></div></div >');
        }
        var src = $(this).attr("da-src");
        if (src != "" && src != undefined) {
            $(".vidBl_content").stop(true, true).fadeIn(500);
            $(".videoBl_conBlock").html('<video id="comVideo" loop="loop" autoplay="" controls=""><source src="' + src + '" type="video/mp4"></video>');
            var videoNode = document.getElementById("comVideo")
            videoNode.play();
            videoResize()
            videoNode.oncanplay = function () {
                videoResize()
            }
        }
    })
    $("body").on("click", ".vidBl_bg,.videoBl_clear", function () {
        $(".vidBl_content").stop(true, true).fadeOut();
        $(".videoBl_conBlock").html("");
    })
    $(".vidBl_content").bind('mousewheel', function (event, delta) {
        event.stopPropagation()
        return true; // 返回值在这
    });
    $(window).resize(function () {
        videoResize()
    })

    //返回顶部
    if ($("body").height() > 2000) {
        $("body").append('<div class="top_null" style="position: fixed;top:0;left:0;width:0px;height:0px;opacity: 0;"></div><div class="top_button" style="position: fixed;bottom: 10%;right: 3%;width: 46px;height: 46px;background: #fff;border-radius: 200px;text-align: center;line-height: 46px;cursor: pointer;box-shadow: 0 0 5px 0 #ccc;z-index: 990;display:none;border: 1px solid #ddd;">Top</div>')
        $(window).scroll(function () {
            var sTop = $(".top_null").offset().top;
            if (sTop > 1500) {
                $(".top_button").css({ "display": "block" });
            } else {
                $(".top_button").css({ "display": "none" });
            }
        })
        $("body").on("click", ".top_button", function () {
            $("html,body").stop().animate({ scrollTop: 0 });
        })
    }


 

    //移动端导航
    function hideNav() {
        $(".touch_nav").removeClass("cur");
        $(".he_conBlock").css({
            width: 0
        })
        $(".he_after").css({ "display": "none" });
    }
    $(".touch_nav").on("click", function () {
        if ($(".touch_nav").hasClass("cur")) {
            hideNav();
        } else {
            $(".touch_nav").addClass("cur");
            $(".he_conBlock").css({
                width: 200
            })
            if ($(".he_after").length < 1) {
                $(".he_content").append('<div class="he_after" style="display:none"></div>');
            }
            $(".he_after").stop(true, true).fadeIn();
            $(".tou_ico").html("+");
        }
    })
    $("body").on("click", ".he_content .he_after", function () {
        hideNav();
    })

    //兼容苹果hover事件
    $("div").on("mouseover", function () { });

    $(".nav_ul").addClass("s"+$(".nav_ul a").length)

})


function AutomaticTitle(pa) {
    $(".nav_ul a").eq(pa).addClass("active").siblings().removeClass("active");
    $(".active .he_ul a").eq(pa).addClass("active").siblings().removeClass("active");
    //自动标题与面包屑
    $(".com_tiCh").html($(".nav_ul a.active").text());
    $(".com_tiEn").html($(".nav_ul a.active").attr('tiEn'));
    $(".this_span").html($(".nav_ul a.active").text());
    $(".this_nav").html($(".he_liBl.active .he_a").text());
}

$(function () {
    // 延迟CNZZ统计, 以免影响页面载入
    var cz = document.createElement("script");
    cz.src = "//s9.cnzz.com/z_stat.php?id=1281125825&web_id=1281125825";
    document.getElementsByTagName('body')[0].appendChild(cz);
});