
var goTop=document.querySelector('.aside');
var left=document.querySelector('.left')
var right=document.querySelector('.right')

var pageOne=document.querySelector('.firstPage')
var pageSecond=document.querySelector('.nextPage')

var videolist = document.querySelectorAll('.video');
var playControl=document.querySelectorAll('.play')

var pageNo=1;

var imgArr=['./images/01.png','./images/04.png','./images/02.png','./images/03.png'];
console.log(pageOne)
left.onclick=function(){
    if(pageNo>1){
        pageNo--;
        console.log(pageNo)
        left.src=imgArr[0]
        right.src=imgArr[1]
        pageOne.style.display='block'
        pageSecond.style.display='none'
    }
}
right.onclick=function(){
    if(pageNo<2){
        pageNo++;
        console.log(pageNo)
        left.src=imgArr[3]
        right.src=imgArr[2]
        pageOne.style.display='none'
        pageSecond.style.display='block'
    }
}


// 给play事件绑定暂停函数
;[].forEach.call(videolist, function(i){
    i.addEventListener('play', pauseAll.bind(i))
    // console.log(isIE())
    if(isIE()){
        
        for (var a=0;a<playControl.length;a++){                                
            // console.log(playControl[a]) 
            playControl[a].style.opacity=1
            
        }
        // playControl[i].style.opacity=0  
    }else{
        
        playControl.forEach(function(item,index){
            if(i==index){
                item.style.opacity=0
            }
            else {          
                item.style.opacity=1
            }
        })
    }  

});


if(isIE()){
    for (var n=0;n<playControl.length;n++){
       (function(n){
        playControl[n].onclick=function(){
            for (var x=0;x<playControl.length;x++){
                playControl[x].style.opacity=1
            }
            
            if (videolist[n].paused) {
                videolist[n].play();
                playControl[n].style.opacity=0
               
            } else {
                videolist[n].pause();
                
                playControl[n].style.opacity=1
            }
        }})(n)
    }
    
}else{
    playControl.forEach(function(item,index){
    
        item.onclick=function(){
           
            playControl.forEach(function(item,index){
                item.style.opacity=1
            })
            if (videolist[index].paused) {
                videolist[index].play();
                item.style.opacity=0
               
            } else {
                videolist[index].pause();
                
                item.style.opacity=1
            }
        }
    })
    
}

function isIE() {
    if(!!window.ActiveXObject || "ActiveXObject" in window){
      return true;
    }else{
      return false;
　　}
}
function pauseAll() {
    var self = this;
    ;[].forEach.call(videolist, function(i) {
        // 将 videos 中其他的 video 全部暂停
        i !== self && i.pause();

        // i !== self && i.load();
    });
   
};

window.onload = function () {
    
   
    window.onscroll = function () {
        
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;

        // 判断是否出现返回顶部
        if(scrollTop>50){
            goTop.classList.add('show')
        }else{
            goTop.classList.remove('show')
        }
    }
   
}
