window.onload = function(){
    // 刷新回到顶部
    // setTimeout(() => window.scrollTo(0,0), 14)
    // 鼠标滑动显示对应hash
    function mouse_scroll( now_dom , now_hash ,last_dom){
        var _dom = document.getElementById(now_dom);
        var __dom= document.getElementById(last_dom);
        let scrollTop = document.documentElement.scrollTop || document.body.scrollTop 
        let clientHeight = document.documentElement.clientHeight || document.body.clientHeight 
        let height = _dom.offsetTop - scrollTop
        if (scrollTop > _dom.offsetTop && scrollTop < __dom.offsetTop){
            window.location.hash = now_hash
        }
    }

    // 导航点击 
    var nav = document.getElementsByClassName("nav")[0];
    var click_a = nav.getElementsByTagName("a");
    for(let i = 0 ; i < click_a.length ; i++){
        click_a[i].index = i;
        click_a[i].onclick = function(){
            for(let a = 0 ; a < click_a.length ; a++){
                click_a[a].classList.remove("choosed")
            }
            click_a[this.index].classList.add("choosed")
        }
    }

    // 固定导航的显示隐藏
    var scroll = function(){
        let nav_height = document.getElementById("top_nav")
        let scrollTop = document.body.scrollTop || document.documentElement.scrollTop
        if(scrollTop > 0){
            nav_height.classList.add('header_scroll')
        }else{
            nav_height.classList.remove('header_scroll')
            window.location.hash="#top"
        }
    }
    scroll()
    window.onscroll = function(){
        scroll()
        
    }
    // window.onscroll = function(){
    //     // 滚动条滚动 导航样式
    //     let nav = document.getElementsByClassName("nav")[0];
    //     let click_a = nav.getElementsByTagName("a");
    //     for(let i = 0 ; i < click_a.length ; i++){
    //         click_a[i].classList.remove("choosed")
    //         switch(window.location.hash){
    //             case '#top':
    //             click_a[0].classList.add("choosed")
    //             break;
    //             case '#to_company':
    //             click_a[1].classList.add("choosed")
    //             break;
    //             case '#to_department':
    //             click_a[2].classList.add("choosed")
    //             break;
    //             case '#to_cours':
    //             click_a[3].classList.add("choosed")
    //             break;
    //             case '#to_product':
    //             click_a[4].classList.add("choosed")
    //             break;
    //         }
    //     }
    //     scroll()
    //     switch(window.location.hash){
    //         case '#top':
    //         mouse_scroll('introduce','#to_company','department')
    //         break;
    //         case '#to_company':
    //         mouse_scroll('department','#to_department','cours')
    //         break;
    //         case '#to_department':
    //         mouse_scroll('cours','#to_cours','product_service')
    //         break;
    //         case '#to_cours':
    //         mouse_scroll('product_service','#to_product','footer')
    //         break;
    //     }
    // }

    // 侧边二维码
    var qr_code = document.getElementsByClassName("qr_code")[0];
    var code_img = this.document.getElementsByClassName("code_img")[0];
    qr_code.onmouseover = function () {
        code_img.style.opacity = 1;
        code_img.style.animation = "rightLeft .8s  ease-in-out forwards"
    }
    qr_code.onmouseout = function () {
        code_img.style.opacity = 0;
        code_img.style.animation = ""
    }

    // 返回顶部
    var go_top = document.getElementsByClassName("go_top")[0];
    go_top.onclick = function backTop () {
        clearInterval(timer);  
        var timer = setInterval(function() {  
            let scrollHeight = document.documentElement.scrollTop || document.body.scrollTop;  
            let now = scrollHeight;  
            let speed = (2 - now) / 15;                               
            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);  
            if (scrollHeight === 0) {                          
                clearInterval(timer);                             
            }  
            document.documentElement.scrollTop = scrollHeight + speed;    
            document.body.scrollTop = scrollHeight + speed;      
        }, 14); 
        window.onmousewheel = function(){
            clearInterval(timer);
        }
        go_top.onmouseout = function(){
            clearInterval(timer)
        } 
    }

    // 公司介绍品牌切换
    // var first = document.getElementsByClassName("first_introduce")[0];
    // var second = document.getElementsByClassName("second_introduce")[0];
    // second.onclick = function () {
    //     this.style.right = "30px";
    //     this.style.animation = "smallBig .6s  ease forwards";
    //     this.style.zIndex = "5";
    //     first.style.left = "-30px";
    //     first.style.zIndex = "4";
    //     first.style.animation = "bigSmall .6s  ease forwards";
    // }
    // first.onclick = function () {
    //     this.style.left = 0;
    //     this.style.animation = "toInit2 .6s  ease forwards";
    //     this.style.zIndex = "5";
    //     second.style.right = 0;
    //     second.style.zIndex = "4";
    //     second.style.animation = "toInit .6s  ease forwards";
    // }
}