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();
    //点击停掉其他播放事件
    $("#videoBox li video").controls=false;
    var sss=$("#videoBox li video");
    function aa(){
        for(var i=0;i<sss.length;i++){
            if(sss[i].paused===true){
            }else{
                clearInterval(timer);
                return ;               
            }
        } 
    }
    $("#videoBox li").bind("click","video",function(){  
        $(this).children(".switch").css("background-image","url(images/switch1.jpg)")
        let url = this.getElementsByTagName("video")[0]
        if(url.paused == true){
            url.play();
            for(let i =0;i<$(this).siblings().find("video").length;i++){
                $(this).siblings().find("video")[i].pause()
            }
            $(this).siblings().find("div").css("background-image","url(images/switch.jpg)")
        }else{
            $(this).find("div").css("background-image","url(images/switch.jpg)")
            url.pause()
        }
    })
    $("#videoBox li").mouseover(function(){
        for(let i =0;i<$("#videoBox li").length;i++){
            $(this).find(".switch").show();
        }
    });
    video_box.onmouseover=function(){
        clearInterval(timer);
    }; 
    video_box.onmouseout=function(){
        autoPlay();
        aa();
        $("#videoBox li .switch").hide()
    }
    window.onscroll = function(){
        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 -240
        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()
    // 滚动样式
}