window.onload =function(){
    // 导航动画
    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')
        }
    }
    scroll()
    window.onscroll = function(){
    scroll()
    }

    // 导航条滚动加载样式
    function home_scroll(){
        let scrollTop = document.documentElement.scrollTop || document.body.scrollTop  
        let home_one = document.getElementById("top").offsetTop - 90
        let home_two = document.getElementById("introduce").offsetTop - 90
        let home_three = document.getElementById("department").offsetTop - 90
        let home_four = document.getElementById("cours").offsetTop - 90
        let home_five = document.getElementById("product_service").offsetTop - 90
        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(true){
                case scrollTop<home_two:
                click_a[0].classList.add("choosed")
                break;
                case scrollTop>=home_two && scrollTop<home_three:
                click_a[1].classList.add("choosed")
                break;
                case scrollTop>=home_three && scrollTop<home_four:
                click_a[2].classList.add("choosed")
                break;
                case scrollTop>=home_four && scrollTop<home_five:
                click_a[3].classList.add("choosed")
                break;
                case scrollTop>=home_five:
                click_a[4].classList.add("choosed")
                break;
            }
        }
    }
    home_scroll()
    window.onscroll = function(){
        home_scroll()
    }

    // 公司介绍品牌切换
    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";
    }
    
    
}