
function stopBubble(e) {
	// 如果传入了事件对象，那么就是非ie浏览器  
	if (e && e.stopPropagation) {
		//因此它支持W3C的stopPropagation()方法  
		e.stopPropagation();
	} else {
		//否则我们使用ie的方法来取消事件冒泡  
		window.event.cancelBubble = true;
	}
}


/***** 首页-banner ****/
$(function() {
	var tap = 'ontouchstart' in document ? 'touchend' : 'click';

	// banner
  var banWebSwip = new Swiper('.hmban-web', {
  		speed: 1000,
	  	effect : 'fade',
		  fadeEffect: {
		    crossFade: true,
		  },
		  autoplay: {
		    delay: 13500,
		    disableOnInteraction: false
		  },
		  pagination:{
		    el: '.hmban-page.web',
		    bulletClass : 'bullet',
		    bulletActiveClass: 'active',
		    clickable :true,
		  },
		  observer:true,
    	observeParents:true,
    	on: {
    		init: function(){
          var swiper = this;
          var windw = parseInt($(window).width());
    			if(this.slides.length > 1){
    				$('.hmban-page.web').show();
    			}else{
    				$('.hmban-page.web').hide();
    			}

          if(windw > 991){
            if($(swiper.slides[0]).find('video').length){
              var videoId = $(swiper.slides[0]).find('.video-js').attr('id');
              var myPlayer = videojs(videoId);
              swiper.autoplay.stop();
              myPlayer.currentTime(0);
              myPlayer.play();
            } 
          }
    		},
        transitionStart: function(){
          var swiper = this;
          var activeIndex = swiper.activeIndex;
          var pervIndex = swiper.previousIndex;
          var windw = parseInt($(window).width());
          if(windw > 991){
            if($(swiper.slides[pervIndex]).find('video').length){
              var videoId = $(swiper.slides[activeIndex]).find('.video-js').attr('id');
              var myPlayer = videojs(videoId);
              myPlayer.pause();
              myPlayer.currentTime(0);
            }
            if($(swiper.slides[activeIndex]).find('video').length){
              var videoId = $(swiper.slides[activeIndex]).find('.video-js').attr('id');
              var myPlayer = videojs(videoId);
              swiper.autoplay.stop();
              myPlayer.currentTime(0);
              myPlayer.play();

              myPlayer.on('ended', function(){
                var isEnd = swiper.isEnd;
                setTimeout(function(){
                  if(isEnd){
                    swiper.slideTo(0,1000,true);
                  }else{
                    swiper.slideNext(); 
                  }
                  swiper.autoplay.start();
                },1000);
              });
            }
          }
        },
        observerUpdate: function(){
          var swiper = this;
          var activeIndex = swiper.activeIndex;
          var windw = parseInt($(window).width());
          if(windw < 992){
            for(var i = 0; i < swiper.slides.length; i++){
              if($(swiper.slides[i]).find('video').length){
                var videoId = $(swiper.slides[activeIndex]).find('.video-js').attr('id');
                var myPlayer = videojs(videoId);
                myPlayer.currentTime(0);
                myPlayer.pause();
              }
            }
          }
        }
    	}
  });

  $('.btn-open_video').on(tap, function(){
    $('.modal-video').modal('show');
  });

  // if($('#home_video').length){
  //   var myPlayer = videojs('home_video');
  //   myPlayer.on('ended', function(){
  //       var isEnd = banWebSwip.isEnd;
  //       setTimeout(function(){
  //           if(isEnd){
  //               banWebSwip.slideTo(0,1000,true);
  //           }else{
  //              banWebSwip.slideNext(); 
  //          }
  //           banWebSwip.autoplay.start();
  //       },1000);
  //   });
  // }

  var banAppSwip = new Swiper('.hmban-app', {
  		speed: 1000,
		  autoplay: {
		    delay: 5000,
		    disableOnInteraction: false
		  },
		  pagination:{
		    el: '.hmban-page.app',
		    bulletClass : 'bullet',
		    bulletActiveClass: 'active',
		    clickable :true,
		  },
		  observer:true,
    	observeParents:true,
    	on: {
    		init: function(){
    			if(this.slides.length > 1){
    				$('.hmban-page.app').show();
    			}else{
    				$('.hmban-page.app').hide();
    			}
    		}
    	}
  });

  // 产品中心
  var prdtSwip = new Swiper('.hmprdt-swip', {
  		speed: 300,
  		slidesPerView: 1,
    	spaceBetween: 50,
    	loop: true,
    	loopAdditionalSlides: 2,
  		observer:true,
    	observeParents:true,
    	navigation: {
		    nextEl: '.hmprdt-ctrl .ctrl.next',
		    prevEl: '.hmprdt-ctrl .ctrl.prev',
		  },
		  breakpoints: {
		  	991.98:{
		  		spaceBetween: 30
		  	}
		  },
    	on: {
    		init: function(){
    			var tit = $(this.slides[this.activeIndex]).find('a').attr('data-tit'),
    					icon = $(this.slides[this.activeIndex]).find('a').attr('data-icon'),
    					titEn = $(this.slides[this.activeIndex]).find('a').attr('data-titEn');
    			$('.hmprdt-titbox .icon').attr('src', icon);
    			$('.hmprdt-titbox .tit').html(tit + '<span class=\'en\'>'+ titEn +'</span>');
    		},
    		transitionStart: function(){
    			var tit = $(this.slides[this.activeIndex]).find('a').attr('data-tit'),
    					icon = $(this.slides[this.activeIndex]).find('a').attr('data-icon'),
    					titEn = $(this.slides[this.activeIndex]).find('a').attr('data-titEn');
    			$('.hmprdt-titbox .icon').attr('src', icon);
    			$('.hmprdt-titbox .tit').html(tit + '<span class=\'en\'>'+ titEn +'</span>');
    		}
    	}
  });
})