window.onload = function () {
    // 左侧固定导航样式
    var show_sidebar = document.getElementById("show_sidebar")
    var sidebar_li = show_sidebar.getElementsByTagName("a")
    for(var k = 0;k < sidebar_li.length ; k++){
        sidebar_li[k].index = k;
        sidebar_li[k].onmouseover = function(){
            for(var b = 0; b < sidebar_li.length ; b++){
                sidebar_li[b].classList.remove("li_mouseover")
            } 
            sidebar_li[this.index].classList.add("li_mouseover")
        }
        sidebar_li[k].onmouseout = function(){
            for(var b = 0; b < sidebar_li.length ; b++){
                sidebar_li[b].classList.remove("li_mouseover")
            } 
        }
        sidebar_li[k].onclick = function(){
            for(var b = 0; b < sidebar_li.length ; b++){
                sidebar_li[b].classList.remove("li_click")
            } 
            sidebar_li[this.index].classList.add("li_click")
        }
    }

    // 公司宣传视频
    var company_video = document.getElementById("company_video")
    company_video.style.height = window.screen.height - 170 + "px";
    
    // 视差滚动
    $.stellar({
        horizontalScrolling: false,
        responsive: true
    });

    // 个人风采效果
    var photo = document.getElementById("person_photo");
    var photo_single =  photo.getElementsByTagName("li")
    var content_single = document.getElementsByClassName("personage")
    for(var i = 0;i < photo_single.length ; i++){
        photo_single[i].index = i;
        photo_single[i].onmouseover = function(){
            for(var a = 0; a < photo_single.length ; a++){
                photo_single[a].classList.remove("li_hover")
                content_single[a].style.display="none";
            } 
            photo_single[this.index].classList.add("li_hover")
            content_single[this.index].style.display = "block";
        }
    }

    // 视频轮播
    var video_banner = document.getElementById("video_banner");
    var video_box = video_banner.getElementsByClassName("video_box")[0]
    var video_single = video_banner.getElementsByTagName("li");
    var timer=null;
    var speed=-2;
    video_box.innerHTML+=video_box.innerHTML;
    video_box.style.width=(video_single[0].offsetWidth+25)*video_single.length+"px"
    function autoPlay(){  
        timer=setInterval(function(){
            video_box.style.left=video_box.offsetLeft+speed+"px";
            if(video_box.offsetLeft<-video_box.offsetWidth/2){     
                video_box.style.left="0px";       
            }else if(video_box.offsetLeft>0){
                video_box.style.left=-video_box.offsetWidth/2+"px";
            }
        },14);
    }
    autoPlay();
    video_box.onmouseover=function(){
        clearInterval(timer);
    };
    video_box.onmouseout=function(){
        autoPlay();
    }

    // // 侧边二维码
    // 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 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()
        show_scroll()
    }

    // 滚轮  左导航样式
    function show_scroll(){
        let scrollTop = document.documentElement.scrollTop || document.body.scrollTop  
        let scroll_one = document.getElementById("scroll_one").offsetTop - 90
        let scroll_two = document.getElementById("scroll_two").offsetTop - 90  
        let scroll_three = document.getElementById("scroll_three").offsetTop - 90  
        let scroll_four = document.getElementById("scroll_four").offsetTop - 90  
        let show_sidebar = document.getElementById("show_sidebar")
        let sidebar_li = show_sidebar.getElementsByTagName("a")
        let show_top = show_sidebar.getElementsByTagName("div")[0]
        for(var k = 0;k < sidebar_li.length ; k++){
            sidebar_li[k].classList.remove("li_click")
            show_top.style.background="#808080";
            switch(true){
                case scrollTop<scroll_one:
                show_top.style.background="#24b298";
                break;
                case scrollTop>=scroll_one && scrollTop<scroll_two:
                sidebar_li[0].classList.add("li_click");
                break;
                case scrollTop>=scroll_two && scrollTop<scroll_three:
                sidebar_li[1].classList.add("li_click");
                break;
                case scrollTop>=scroll_three && scrollTop<scroll_four:
                sidebar_li[2].classList.add("li_click");
                break;
                case scrollTop>=scroll_four:
                sidebar_li[3].classList.add("li_click");
                break;
            }
        }
    }
    show_scroll()
    // 滚动样式
}