// $(function () {
// //     switchTop();
// // })
/**
 * 所有引入的头部，执行初始化标签操作
 * 根据 id为top_div，下的a标签中的href的值和地址栏中的值，判断并切换头部的标签
 */
$(document).ready(function () {
    switchTop();
});

function switchTop() {
    var pathname = window.location.pathname
    var aBean = $("#top_div a[href='" + pathname + "']");
    if (aBean.length > 0) {
        var aParentBean = $("#top_div a[href='" + pathname + "']").parent()
        var aTop = aParentBean.parent().parent();
        if (isNotEmpty(aTop.attr("type"))) {
            aParentBean = aTop;
        }
        $("#top_div .active").removeClass("active")
        aParentBean.addClass("active")
    }
}

$(function () {
    $(".fl-layout .article-list:last").css({"border-bottom": "none"});

    /*pc导航*/
    $(".header-nav ul > li").on("mouseenter", function () {
        if ($(this).children().hasClass("data-show")) {
            $(this).children("a").addClass("active");
            $(this).find(".data-show").stop().slideDown(200);
        }
    });
    $(".header-nav ul > li").on("mouseleave", function () {
        if ($(this).children().hasClass("data-show")) {
            $(this).children("a").removeClass("active");
            $(this).find(".data-show").stop().slideUp(200);
        }
    });
    /*导航结束*/
    //$(".tab-ul-index li:last").css({"margin":0,"float":"right"});

    /*响应式手机js*/
//	底部top按钮，点击返回顶部
    $(document).on('touchend', '.toTop', function () {
        $('body,html').animate({scrollTop: 0}, 300);
    })
    $('.navList').click(function () {
        if ($('.smallUl').css('display') == 'none') {
            $('.smallUl').slideDown();
            $(this).find('.span1').css({"transform": "rotate(-45deg)", "margin-top": 10});
            $(this).find(".span2").css({"opacity": 0});
            $(this).find('.span3').css({"transform": "rotate(45deg)", "margin-top": -21});
        } else {
            $('.smallUl').slideUp();
            $(this).find('.span1').css({"transform": "rotate(0deg)", "margin-top": 0});
            $(this).find(".span2").css({"opacity": 1});
            $(this).find('.span3').css({"transform": "rotate(0deg)", "margin-top": 0});
        }
        if ($(".search-app-wrap").css("display") == "block") {
            $(".search-app-wrap").hide(0);
            $(".search-app").removeClass("active");
        }
    });

    $(".search-app").click(function () {
        if ($(".search-app-wrap").css("display") == "none") {
            $(".search-app-wrap").stop().slideDown(200);
            $(this).addClass("active");
        } else {
            $(".search-app-wrap").stop().slideUp(200);
            $(this).removeClass("active");
        }
        if ($(".smallUl").css("display") == "block") {
            $(".smallUl").hide(0);
            $(".navList").find('.span1').css({"transform": "rotate(0deg)", "margin-top": 0});
            $(".navList").find(".span2").css({"opacity": 1});
            $(".navList").find('.span3').css({"transform": "rotate(0deg)", "margin-top": 0});
        }
    });


    $(".smallUl>li").click(function () {
        if ($(this).find(".data-show").css("display") == "none") {
            $(this).find("a span").addClass("active");
            $(this).siblings().find("a span").removeClass("active");
            $(this).find(".data-show").slideDown(200);
            $(this).siblings().find(".data-show").slideUp(200);
        } else {
            $(this).find(".data-show").slideUp(200);
            $(this).find("a span").removeClass("active");
        }
    });
    for (var i = 0; i < $(".smallUl>li").length; i++) {
        if ($(".smallUl>li").eq(i).find("li").length > 0) {
            $(".smallUl>li").eq(i).children("a").append('<span><img src="' + local_host + '/images/public/selet-arrow_app.png"></span>');
        }
    }
    // function run() {
    //     //$(".phone-nav .text").css({"width":parseInt($(".phone-nav .container").width()-$(".navList").width()-$(".phone-nav .sub").width()-$(".phone-nav .en").width()-30)});
    //     if($(window).width()<=1200){
    //         $(".header .navList span").last().css({"margin":0,"border":"none"});
    //         $(".smallUl").css({"top":$(".phone-nav").outerHeight()});
    //         $(".tab-ul-index").css({"width":$(".tab-ul-index li").length*$(".tab-ul-index li").outerWidth(true)});
    //         $(".item-div .tab-box").css({"overflow-x":"auto","overflow-y":"hidden"});
    //     }else{
    //         $(".tab-ul-index").css({"width":"100%"});
    //         $(".item-div .tab-box").css({"overflow-x":"inherit","overflow-y":"inherit"});
    //     }
    //     $(".advance-search-bot").css({"min-height":$(window).height()-$(".header").height()-$(".footer").height()-$(".phone-nav").height()-100});
    //     $(".main>.container").css({"min-height":$(window).height()-$(".footer").height()-$(".phone-nav").height()});
    //     $(".archcon .tab-ul").each(function(){
    //         $(this).find("dd").css({"width":Math.floor($(this).width()/$(this).find("dd").length-2),"margin-left":"1px","margin-right":"1px"});
    //     });
    //
    //     if(window.innerWidth<=991){
    //         var left=$(".second-level-l").prop("outerHTML");
    //         $(".second-level-r").prev(".second-level-l").hide();
    //         $(".second-level-r").next().append(left);
    //         $(".second-level-r").next("div").show();
    //         setTimeout(function(){
    //             $(".search_year").change(function(){
    //                 var yearId = $(this).val();
    //                 $(this).parent().siblings(".form-group").find("."+yearId).show().siblings().hide();
    //                 //给Action赋值
    //                 $(this).parents(".left_search").attr("action",$(this).parent().siblings(".form-group").find("."+yearId).val());
    //             })
    //         },200)
    //         if($(".second-level-r").next().find(".second-level-l").length>1){
    //             $(".second-level-r").next().append(left);
    //             $(".second-level-r").next().find(".second-level-l").eq(0).show().siblings().remove();
    //         }
    //     }else{
    //         $(".second-level-r").prev(".second-level-l").show();
    //         $(".second-level-r").next("div").hide();
    //         $(".search_year").change(function(){
    //             var yearId = $(this).val();
    //             $(this).parent().siblings(".form-group").find("."+yearId).show().siblings().hide();
    //             //给Action赋值
    //             $(this).parents(".left_search").attr("action",$(this).parent().siblings(".form-group").find("."+yearId).val());
    //         })
    //     }
    //     /*search*/
    //     if($(window).width()<=767){
    //         if($(".inputText.paddingLeftNone").siblings(".form-control-1-box").find("select").css("display")=="none"){
    //             $(".search-wrap .inputText.paddingLeftNone").css({"width":"100%","margin":"0"});
    //         }else{
    //             $(".search-wrap .inputText.paddingLeftNone").css({"width":"71%","margin":"0 0 0 2%"});
    //         }
    //     }else{
    //         if($(".inputText.paddingLeftNone").siblings(".form-control-1-box").find("select").css("display")=="none"){
    //             $(".search-wrap .inputText.paddingLeftNone").css({"width":"482px","margin":"0 30px 0 0"});
    //         }else{
    //             $(".search-wrap .inputText.paddingLeftNone").css({"width":"365px","margin":"0 30px 0 0"});
    //         }
    //     }
    //
    // }
    // function detectZoom (){
    //     var ratio = 0,
    //         screen = window.screen,
    //         ua = navigator.userAgent.toLowerCase();
    //
    //     if (window.devicePixelRatio !== undefined) {
    //         ratio = window.devicePixelRatio;
    //     }
    //     else if (~ua.indexOf('msie')) {
    //         if (screen.deviceXDPI && screen.logicalXDPI) {
    //             ratio = screen.deviceXDPI / screen.logicalXDPI;
    //         }
    //     }
    //     else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
    //         ratio = window.outerWidth / window.innerWidth;
    //     }
    //
    //     if (ratio){
    //         ratio = Math.round(ratio * 100);
    //     }
    //
    //     return ratio;
    //
    // };
    // $(window).load(function () {
    //     run();
    // });
    // $(window).resize(function () {
    //     run();
    //     if(detectZoom() != 100){
    //         run();
    //     }
    // });


    /*手机文章详情页右下角目录*/
    function getFullText() {
        var html = '', arr = $('.article-app .navTitle');
        for (var i = 0; i < arr.length; i++) {
            html += '<li>' + arr.eq(i).prop("outerHTML") + '</li>';
        }
        $(".iphone-wrapper").append(html);
    }

    getFullText();
    var topArr = [];
    for (var i = 0; i < $(".article-app .navTitle").length; i++) {
        topArr.push($(".article-app .navTitle").eq(i).offset().top);
    }
    $(".iphone-wrapper li").each(function (i) {
        $(this).click(function () {
            $(this).addClass("ac").siblings().removeClass("ac");
            var _this = $(this), index = _this.index();
            if ($('.article-app .navTitle').eq(index).parent(".group").css("display") == "none") {
                $('.article-app .navTitle').eq(index).parent(".group").show();
            }
            var top = $('.article-app .navTitle').eq(index).offset().top;
            $('html,body').animate({scrollTop: top}, 300);
        })
    });
    // 手机右下角目录高度
    $(".article-menu-bot").css({"height": $(window).height() - $(".article-menu>h3").height()});
    $(".article-btn").click(function () {
        if ($(".article-menu").css("z-index") == "-1") {
            $(".article-menu").addClass("ac1");
            var wrapper = document.querySelector('.article-menu-bot');
            var scroll = new BScroll(wrapper, {
                click: true
            });
        } else {
            $(".article-menu").removeClass("ac1");
        }
    });


    // 手机上到全文第一条显示右下角目录
    if ($("#htmlContent2>.full-text").length > 0) {
        $(window).scroll(function () {
            var htmlT = $("#htmlContent2>.full-text").offset().top;
            if ($(window).scrollTop() >= htmlT) {
                $(".article-btn").addClass("ac");
            } else {
                $(".article-btn").removeClass("ac");
            }
        })
    }

//    全文中点击标题展开相应标题内容
    $(document).on('click', '.main figcaption', function (e) {
        var _this = $(this);
        if (_this.hasClass('grayBgColor')) {
            _this.removeClass('grayBgColor').parent().removeClass('grayBorder');
            _this.next().hide();
        } else {
            _this.addClass('grayBgColor').parent().addClass('grayBorder');
            _this.next().show();
        }
    });
    $(".open-articleEn").click(function () {
        if ($(this).next(".articleEn").css("display") == "none") {
            $(this).next(".articleEn").slideDown(200);
            $(this).find("span").addClass("icon-jian").removeClass("icon-jia");
        } else {
            $(this).next(".articleEn").slideUp(200);
            $(this).find("span").addClass("icon-jia").removeClass("icon-jian");
        }
    })
// 移动端滑动
    if ($(".mescroll").length > 0) {
        var wrapper = document.querySelector('.mescroll');
        var scroll = new BScroll(wrapper);
    }

})


