$(function () {
    $('.nav-more').on('click',function(e){
        e.preventDefault();
        if($(this).hasClass('show')){
            $('.nav-ul').find('li').not('.nav-show-tab').css({
                display:"none"
            });
            $(this).find('i').attr({
                class:"icon-nav-arrow"
            });
            $(this).removeClass('show')
        }else{

            $('.nav-ul').find('li').not('.nav-show-tab').css({
                display:"inline-block"
            });
            $(this).find('i').attr({
                class:"icon-nav-pack"
            });
            $(this).addClass('show')
        }
    });

//slide
    TouchSlide({
        slideCell: "#focus",
        titCell: ".hd ul", //开启自动分页 autoPage:true ，此时设置 titCell 为导航元素包裹层
        mainCell: ".bd ul",
        effect: "leftLoop",
        autoPlay: true,//自动播放
        autoPage: true //自动分页
    });


    // nav固定
    var _viewHeight = document.body.clientHeight;
    // console.log(_viewHeight);
    var _scrollHeight= $('.view').scrollTop();
    // console.log(_scrollHeight);

    var $navBox= $('.nav-box');
    if (_scrollHeight > _viewHeight){
        $navBox.addClass('nav-fix');
    }else {
        $navBox.removeClass('nav-fix');
    }

    function fixedBoxHeight(box, i) {
        i = i || 0;
        var tHeight = $(box).find('.bd')[0];
        if (!tHeight) {
            return;
        }
        var children = tHeight.children[i + 1].children;
        var len = children.length;
        var n = 0;
        var height = 0;
        var ele = null;

        for (n; n < len; n++) {
            ele = $(children[n]);
            height += parseInt(ele.height() + parseInt(ele.css('margin-top')) + parseInt(ele.css('margin-bottom')));
        }

        tHeight.parentNode.style.height = height + "px";
        if (i > 0) tHeight.parentNode.style.transition = "200ms";//添加动画效果
    }
//左循环切换
    TouchSlide({
        slideCell: "#leftTabBox",
        effect: "leftLoop",
        startFun: function (i) {
            fixedBoxHeight('#leftTabBox', i);
        }
    });
});

