window.onload = function () {
    function bindEvent() {
        //删除手机导航默认属性；
        $('.main-nav .mobile a').click(function(){
            event = event || window.event;
            if(event.preventDefault){
                event.preventDefault();
            }else{
                event.returnValue = false;
            }
        })
        //手机一级菜单;
        $('.main-nav .mobile').on('click',function(){
            var index = $(".main-nav li").index(this);
            console.log(index);
            console.log($('.mobileSub ul .nav-main-item').eq(index).find('.side-nav-sub-items').children().length);
            var length = $('.mobileSub ul .nav-main-item').eq(index).find('.side-nav-sub-items').children().length;
            if(length <= 0){
                location.href = $(this).find('a').attr('href');
                return false;
            }
            //return false;
            $('.main-nav').css({"width":"35%","float":"left"})
            $('.main-nav li').removeClass('item-active')
            $(this).addClass('item-active')
            $('.mobileSub').show();
            $('.mobileSub ul .nav-main-item').removeClass('show')
            $('.mobileSub ul .nav-main-item').eq(index).addClass('show')
            return false;
        })
        //显示关闭  手机导航栏
        var isshow = false;
        $('.collapsed').click(function(){
            //console.log(3234234);
            //alert(11);
            isshow = !isshow;
            $('body').addClass('main-mobile');
            if(isshow){
                $('html,body').css({'height':'100%','overflow':'hidden'})
                $(this).children().css('opacity',0)
                $(this).css({'background':"url("+GV.STATIC+"simpleboot/images/closed.png) no-repeat center center / .64rem .64rem"})
                $('.collapse').show();
                $('.mobileSub').show();
            }else{
                $('html,body').css({'height':'100%','overflow':'visible'})
                $(this).children().css('opacity',1);
                $(this).removeAttr('style')
                $('.collapse').hide();
                $('.mobileSub').hide();
            }
        })
    }

    function removeEvent(){
        $('.mobileSub').hide();
        $('.main-nav').attr({'style':' '})
        $('.main-nav .mobile a').unbind('click')
        $('.main-nav .mobile').unbind('click')
        $('.collapsed').unbind('click')
    }

    window.addEventListener("resize",function(e){
        var el = document.getElementsByTagName('body')[0];
        var wid = el.clientWidth;
        if(wid<=750){
            var size = wid/1080*100;
            document.getElementsByTagName('html')[0].style.fontSize=size+'px'
            bindEvent();
        }else{
            document.getElementsByTagName('html')[0].style='';
            removeEvent();
        }
    });
    var el = document.getElementsByTagName('body')[0];
    var wid = el.clientWidth
    if(wid<=750){
        var size = wid/1080*100;
        document.getElementsByTagName('html')[0].style.fontSize=size+'px'
        bindEvent();
    }else{
        document.getElementsByTagName('html')[0].style='';
        removeEvent();
    }
};
