$(function() {

    var nowP0 = $(".xny-all-ids .xny-all-id0").attr("data-id");
    var nowP1 = $(".xny-all-ids .xny-all-id1").attr("data-id");
    var nowP2 = $(".xny-all-ids .xny-all-id2").attr("data-id");
    if (nowP1=='1' && nowP2=='1' && nowP0=='27313'){
        $('.xny-header-nav-1').find("a").addClass("active");
    }else if(nowP1=='1' && nowP2=='1' && nowP0=='27379'){
        $(".xny-header-main .xny-header-nav > li").eq(8).find("a").addClass("active")
    }else{
        for (var i = 0; i < $(".xny-header-main .xny-header-nav > li").length; i++) {
            if ($(".xny-header-main .xny-header-nav > li").eq(i).attr("data-id") ==  nowP1 || $(".xny-header-main .xny-header-nav > li").eq(i).attr("data-id") == nowP2) {
                $(".xny-header-main .xny-header-nav > li").eq(i).find("a").addClass("active")
            }
        }
    }
   


    $('.xd-open-index').removeClass("xd-nav-sel");
    if (nowP1=='1' && nowP2=='1' && nowP0=='27313'){
        $('.xd-open-index').addClass("xd-nav-sel");
    }else if(nowP1=='1' && nowP2=='1' && nowP0=='27379'){
        $(".xd-open-top .xd-open-item > a").eq(8).addClass(" xd-open-parent-up")
    }else{
        for (var i = 0; i < $(".xd-open-top .xd-open-item").length; i++) {
            if ($(".xd-open-top .xd-open-item > a").eq(i).attr("data-id") ==  nowP1 || $(".xd-open-top .xd-open-item > a").eq(i).attr("data-id") == nowP2) {
                $(".xd-open-top .xd-open-item > a").eq(i).addClass(" xd-open-parent-up")
                $(".xd-open-top .xd-open-item > a").eq(i).next().show();
            }
        }
    }

    var screenW = $("body,html").width();

    function searchBtn() {
        $(".xny-searchIcon").on("click", function() {
            $(".xny-searchBox").show();
            $(".xny-searchClose").show();
            
        })
        $(".xny-searchClose").on("click", function() {
            $(".xny-searchBox").hide();
            $(".xny-searchClose").hide();
            $(".xny-searchIcon").show();
        })
    }

    function indexBanner() {
        var swiper = new Swiper(".xny-banner .swiper-container", {
            pagination: {
                el: ".xny-banner .swiper-pagination",
                clickable: true,
            },
            on: {
                init: function(swiper) {
                    if (this.slides.length <= 1) {
                        $(".xny-banner .swiper-pagination").hide();
                    }
                }
            }
        });
    }

    function more() {
        $(".xny-indexYw-more").hover(function() {
            $(this).find(".icon-anniu-gengduo-xuanzhong-01").addClass(".icon-anniu-gengduo-xuanzhong-01")
        })
    }

    function indexVideo() {

        var swiper = new Swiper(".xny-indexNews-2-indexVideo-main .swiper-container", {
            loop: true,
            pagination: {
                el: ".xny-indexNews-2-indexVideo-main .swiper-pagination",
                clickable: true,
            },
            on: {
                init: function(swiper) {
                    if (this.slides.length <= 1) {
                        $(".xny-indexNews-2-indexVideo-main .swiper-pagination").hide();
                    }
                },
                slideChange: function() {

                }
            }

        });


    }

    function singleSearch(tar) {
        if (tar && tar.length != 0) {
            var defHref = tar.attr("href");
            tar.on("click", function(e) {
                if ($("#wx-search-ipt").val() == "" || $("#wx-search-ipt").val() == null) {
                    $("#wx-search-ipt").val("");
                }
                //核心代码，拼接参数                       
                var args = "siteIds=" + window.btoa(tar.attr("data-siteIds")) + "&excludeCategoryId=" + window.btoa(tar.attr("data-excludeCategoryId")) + "&dataUrl=" + window.btoa(tar.attr("data-url")) + "&keyword=" + encodeURI(encodeURI($.trim($("#wx-search-ipt").val())));
                //核心代码，拼接参数 end
                tar.attr("href", defHref + '#' + args);
            });

            $("#wx-search-ipt").keyup(function(e) {
                if (e.keyCode == 13) {
                    if ($("#wx-search-ipt").val() == "" || $("#wx-search-ipt").val() == null) {
                        $("#wx-search-ipt").val("");
                    } else {
                        tar.trigger("click");
                        window.open(tar.attr("href"));
                    }

                }
            });
        }
    }

    function msingleSearch(tar) {
        if (tar && tar.length != 0) {
            var defHref = tar.attr("href");
            tar.on("click", function(e) {
                if ($(".xd-search-text").val() == "" || $(".xd-search-text").val() == null) {
                    $(".xd-search-text").val("");
                }
                //核心代码，拼接参数                       
                var args = "siteIds=" + window.btoa(tar.attr("data-siteIds")) + "&excludeCategoryId=" + window.btoa(tar.attr("data-excludeCategoryId")) + "&dataUrl=" + window.btoa(tar.attr("data-url")) + "&keyword=" + encodeURI(encodeURI($.trim($(".xd-search-text").val())));
                //核心代码，拼接参数 end
                tar.attr("href", defHref + '#' + args);
            });

        }
    }

    function bread() {
        var now = $(".kc-bread-now").attr("data-id");
        // var nowChild = $(".xny-gsjj-title span").attr("data-id");
   
        for (var i = 0; i < $(".xny-bread li").length; i++) {
            if ($(".xny-bread li").eq(i).attr("data-id") == now || $(".xny-bread li").eq(i).attr("data-id") == nowP1 || $(".xny-bread li").eq(i).attr("data-id") == nowP2) {
                $(".xny-bread li").eq(i).find("a").addClass("active")
            }
            // if ($(".xny-bread li").eq(i).attr("data-id") == nowChild) {
            //     $(".xny-bread li").eq(i).find("a").addClass("active")
            // }
           
        }
        
       


        var swiperBread = new Swiper(".mxny-bread .swiper-container", {
            slidesPerView: "auto",
            spaceBetween: 0,
            initialSlide: $(".mxny-bread .swiper-container .swiper-slide.active").attr("data-num"),
            pagination: {
                el: ".mxny-bread .swiper-pagination",
                clickable: true,
            },
        });
    }

    function footer() {
        $(".xny-return").on("click", function() {
            $("html,body").animate({
                scrollTop: 0
            }, 1000)
        });

        $(".xny-footer-select-main").change(function() {
            var linksurl = $(this).val();
            if (linksurl != "") {
                window.open(linksurl, "_blank")
            }
        })
        if ($(".mxny-footerNav")) {
            $(".mxny-footerNav-item").each(function() {
                var that = $(this)
                $(this).find(".mxny-footerNav-item-title").click(function() {
                    if ($(this).siblings("ul").is(':hidden')) {
                        $(this).siblings("ul").show();
                    } else {
                        $(this).siblings("ul").hide();
                    }
                })
            })
        }
    }


    function mheader() {
        $(".xd-catlog").off().on("click", function() {
            // if ($(".xd-nav-sel").length != 0) {
            //     if ($(".xd-nav-sel").attr("data-code") != "index") {
            //         $(".xd-nav-sel").parent().parent().prev().trigger("click");
            //     }
            // } else {
            //     $(".xd-open-index").addClass("xd-nav-sel");
            // }

            if ($(".xd-catlog").hasClass("xd-catlog-close")) {
                $(".xd-open").hide();
                $(this).removeClass("xd-catlog-close");
            } else {
                $(this).addClass("xd-catlog-close");
                $(".xd-open").show();
                $(".xd-search-open").hide();
                $(".xd-search-text").val("");
                $(".xd-search").removeClass("xd-search-close");
            }
        });

        $(".xd-open-parent").on("click", function() {
            $('.xd-open-index').find("a").removeClass("xd-nav-sel");
            $(".xd-open-item ul").not($(this).next()).hide();
            $(".xd-open-parent").not($(this)).removeClass("xd-open-parent-up");
            $(this).next().toggle();
            $(this).toggleClass("xd-open-parent-up");
        });
        $(".xd-search").off().on("click", function() {
            if ($(".xd-search").hasClass("xd-search-close")) {
                $(".xd-search-open").hide();
                $(this).removeClass("xd-search-close");
                $(".xd-search-text").val("");
            } else {
                $(this).addClass("xd-search-close");
                $(".xd-search-open").show();
                $(".xd-open").hide();
                $(".xd-catlog").removeClass("xd-catlog-close");
            }
        });
    }


    function honor() {
        $(".xny-honor-main-item-tab1 .swiper-slide").first().addClass("active");
        var thumbsSwiper = new Swiper('.xny-honor-main-item-tab1 .swiper-container', {
            spaceBetween: 10,
            slidesPerView: "auto",
            observer: true,
            observeParents: true,
            navigation: {
                nextEl: '.xny-honor-main-item-tab1 .swiper-button-next',
                prevEl: '.xny-honor-main-item-tab1 .swiper-button-prev',
            }
        })
        var gallerySwiper = new Swiper('.xny-honor-main-item-list1', {
            spaceBetween: 10,
            slidesPerView: 1,
            observer: true,
            observeParents: true,
            thumbs: {
                swiper: thumbsSwiper,
            }
        })





        var swiperhonor2 = new Swiper(".xny-honor-main-item-tab2 .swiper-container", {
            slidesPerView: "auto",
            spaceBetween: 18,
            navigation: {
                nextEl: '.xny-honor-main-item-tab2 .swiper-button-next',
                prevEl: '.xny-honor-main-item-tab2 .swiper-button-prev',
            },
            on: {
                init: function(swiper) {
                    if (this.slides.length <= 1) {

                    }
                }
            }
        });

    }

    function tab(nav, item) {
        nav.first().addClass("active");
        item.hide();
        item.first().show();
        nav.on("click", function() {
            $(this).addClass('active').siblings().removeClass('active');
            item.eq($(this).index()).show().siblings().hide();
        })
    }

    function tabA(nav, item) {
        item.hide();
        item.first().show();
        nav.on("click", function() {
            $(".xny-honor-main-item-tab .swiper-slide-active").addClass("activeNo")
            $(this).addClass('active').siblings().removeClass('active');
            item.eq($(this).index()).show().siblings().hide();
        })

    }

    function hjzr() {
        var swiperhjzr = new Swiper(".xny-ehs-block3-container .swiper-container", {
            slidesPerView: 1,
            spaceBetween: 20,
            pagination: {
                el: ".xny-ehs-block3-container .swiper-pagination",
                clickable: true,
            },
            navigation: {
                nextEl: '.xny-ehs-block3-container .swiper-button-next',
                prevEl: '.xny-ehs-block3-container .swiper-button-prev',
            },
            breakpoints: {
                750: {
                    slidesPerView: 2,
                }
            }
        });

    }


    function indexFast() {
        var indexFast = new Swiper(".xny-indexFast-container", {
            slidesPerView: "auto",
            spaceBetween: 20,
            pagination: {
                el: ".xny-indexFast .swiper-pagination",
                clickable: true,
            },
            on: {
                init: function(swiper) {
                    if (this.slides.length <= 1) {
                        $(".xny-indexFast .swiper-pagination").hide();
                    }
                }
            }
        });
    }



    function school() {
        var swiperschool = new Swiper(".xny-school-block3-main .swiper-container", {
            slidesPerView: 1,
            spaceBetween: 20,
            pagination: {
                el: ".xny-school-block3-main .swiper-pagination",
                clickable: true,
            },
            navigation: {
                nextEl: '.xny-school-block3-main .swiper-button-next',
                prevEl: '.xny-school-block3-main .swiper-button-prev',
            },
            on: {
                init: function(swiper) {
                    if (this.slides.length <= 1) {
                        $(".xny-school-block3-main .swiper-pagination").hide();
                        $(".xny-school-block3-main .swiper-button-next").hide();
                        $(".xny-school-block3-main .swiper-button-prev").hide();
                        $(".xny-school-block3-main .swiper-slide").css({ "left": "50%", "transform": "translateX(-50%)" })
                    }
                }
            },
            breakpoints: {
                800: {
                    slidesPerView: 3,
                }
            }
        });
        $(".xny-picList-mask-close").on("click", function() {
            $(".xny-picList-mask").hide();
        })

        var len = $(".xny-school-block3-main .swiper-slide-parent");
        for (var i = 0; i < len.length; i++) {
            len.eq(i).find(".xny-school-block3-main-pic").on("click", function() {
                var html = $(this).siblings(".xny-school-block3-son").html();
                $(".xny-school-block3-picList").find(".swiper-wrapper").html(html);
                $(".xny-picList-mask").show();
                var swiperschoolPic = new Swiper(".xny-school-block3-picList .swiper-container", {
                    slidesPerView: 1,
                    effect: 'fade',
                    fadeEffect: {
                        crossFade: true,
                    },
                    pagination: {
                        el: ".xny-school-block3-picList .swiper-pagination",
                        clickable: true,
                        type: 'fraction'
                    },
                    navigation: {
                        nextEl: '.xny-picList-mask-bg .swiper-button-next',
                        prevEl: '.xny-picList-mask-bg .swiper-button-prev',
                    },
                    on: {
                        init: function(swiper) {
                            if (this.slides.length <= 1) {
                                $('.xny-picList-mask-bg .swiper-button-next').hide();
                                $('.xny-picList-mask-bg .swiper-button-prev').hide();
                            } else {
                                $('.xny-picList-mask-bg .swiper-button-next').show();
                                $('.xny-picList-mask-bg .swiper-button-prev').show();
                            }
                        }
                    }
                });
            })
        }
    }


    function yjbg() {
        $(".xny-yjbg-tab-container .swiper-slide").first().addClass("active");
        var galleryThumbs = new Swiper('.xny-yjbg-tab-container', {
            freeMode: true,
            watchSlidesVisibility: true,
            watchSlidesProgress: true,
            slidesPerView: "auto",
        });
        $('.xny-yjbg-tab .swiper-button-prev').click(function() {
            galleryThumbs.slidePrev();
        })
        $('.xny-yjbg-tab .swiper-button-next').click(function() {
            galleryThumbs.slideNext();
        })

        $(".xny-yjbg-tab-container .swiper-slide").on("click", function() {
            var _index = $(this).index()

            if (_index == 0) {
                $(".xny-yjbg-main-item").show();
            } else {
                $(".xny-yjbg-tab-container .swiper-slide").removeClass("active")
                $(".xny-yjbg-tab-container .swiper-slide").eq(_index).addClass("active")
                $(".xny-yjbg-main-item").hide().eq(_index).show();
            }

        })
    }

    function detail() {
        var galleryThumbsDetail = new Swiper('.wx-detail-pic .gallery-thumbs', {
            spaceBetween: 10,
            slidesPerView: 5,
        });
        var galleryTopDetail = new Swiper('.wx-detail-pic .gallery-top', {
            navigation: {
                nextEl: '.wx-detail-pic .swiper-button-next',
                prevEl: '.wx-detail-pic .swiper-button-prev',
            },
            thumbs: {
                swiper: galleryThumbsDetail
            },
            pagination: {
                el: '.swiper-pagination-detail',
                type: 'fraction'
            },
            on: {
                init: function(swiper) {
                    if (this.slides.length <= 0) {
                        $(".wx-detail-pic").hide();
                    }
                }
            }

        });
    }

    function fzlc() {
        var swiperfzlc = new Swiper(".xny-fzlc-tab ", {
            direction: 'vertical',
            slidesPerView: 10,
            navigation: {
                nextEl: '.xny-fzlc-tab-main .swiper-button-next',
                prevEl: '.xny-fzlc-tab-main .swiper-button-prev',
            },
            on: {
                init: function(swiper) {
                    if (this.slides.length <= 10) {
                        $(".xny-fzlc-tab-main .swiper-button-next").hide();
                        $(".xny-fzlc-tab-main .swiper-button-prev").hide();
                    }
                },
                slideChange: function() {

                },
            },


        });

        $(".mxny-fzlc-tabMain-container .swiper-slide").first().addClass("active");

        var swiperfzlcmob = new Swiper(".mxny-fzlc-tabMain-container", {
            slidesPerView: "auto",
            navigation: {
                nextEl: '.mxny-fzlc-tabMain .swiper-button-next',
                prevEl: '.mxny-fzlc-tabMain .swiper-button-prev',
            },
        });
        $(".mxny-fzlc-tabMain-container .swiper-slide").on("click", function() {
            var _index = $(this).index()
            $(".mxny-fzlc-tabMain-container .swiper-slide").removeClass("active")
            $(".mxny-fzlc-tabMain-container .swiper-slide").eq(_index).addClass("active")
            $(".mxny-fzlc-content-item").hide().eq(_index).show();
        })

    }


    function ehsPic() {
        for (var i = 0; i < $(".mxny-ehs-block2-item").length; i++) {
            $(".mxny-ehs-block2-item").eq(i).find(".mxny-ehs-block2-item-arr-d").on("click", function() {
                $(this).siblings(".mxny-ehs-block2-item-arr-u").show("slow");
                $(this).hide("slow");
                $(this).siblings(".mxny-ehs-block2-item-desc").show("slow");
                $(this).parent().css("height", "350px")
            })
            $(".mxny-ehs-block2-item").eq(i).find(".mxny-ehs-block2-item-arr-u").on("click", function() {
                $(this).hide("slow");
                $(this).siblings(".mxny-ehs-block2-item-arr-d").show("slow");
                $(this).siblings(".mxny-ehs-block2-item-desc").hide("slow");
                $(this).parent().css("height", "120px")
            })
        }
    }


    more();
    searchBtn();
    indexBanner();
    singleSearch($(".xny-searchBox-btn"));
    msingleSearch($("#submitbuttom1"));
    bread();
    indexVideo();
    footer();
    mheader();
    honor();
    tab($(".xny-honor-tab li"), $(".xny-honor-main-item"));
    tab($(".xny-info-tab li"), $(".xny-info-main-item"));
    tabA($(".xny-honor-main-item-tab1 .swiper-slide"), $(".xny-honor-main-item-list1 .xny-honor-main-item-list-item"));
    tab($(".xny-newsList-tab li"), $(".xny-gsgz-block"));
    hjzr();
    school();
    yjbg();
    detail();
    fzlc();
    tab($(".xny-fzlc-tab .swiper-slide"), $(".xny-fzlc-main-item"));
    indexFast();
    ehsPic();
})