//首頁主視覺輪播圖
$(function () {
	var owl = $('.banner_01');
	if (owl.hasClass('owl-loaded')) {
		owl.owlCarousel('destroy'); // 如果已經初始化過，先銷毀
	}
	  owl.owlCarousel({
		margin: 10,
		nav: true,
		navText:false,
		loop: true,
		autoplay:true,
		autoplayHoverPause: true,
		autoWidth: false ,
		autoplayTimeout: 15000,
		items: 1,
		responsive: {
		  0: {
			items: 1
		  },
		  600: {
			items: 1
		  },
		  1000: {
			items: 1
		  }
		}
	  })
});
//首頁主廣告圖
$(function () {
	var owl = $('.banner_02');
	  owl.owlCarousel({
		margin: 10,
		nav: true,
		navText:false,
		loop: true,
		autoplay:true,
		autoplayHoverPause:true,
		autoplayTimeout:15000,
		responsive: {
		  0: {
			items: 1
		  },
		  600: {
			items: 1
		  },
		  1000: {
			items: 1
		  }
		}
	  })
});

//首頁跑馬燈
$(function () {
	var owl = $('.banner_03');
	  owl.owlCarousel({
		margin: 10,
		nav: true,
		navText:false,
		loop: true,
		autoplay:true,
		autoplayHoverPause:true,
		autoplayTimeout:6000,
		dots:false,
		responsive: {
		  0: {
			items: 1
		  },
		  600: {
			items: 1
		  },
		  1000: {
			items: 1
		  }
		}
	  })
});


//首頁ICON
$(function () {
	var owl = $('.banner_icon');
	owl.owlCarousel({
		margin: 10,
		nav: true,
		navText: false,
		loop: true,
		dots: false,
		autoplay: false,
		autoplayHoverPause: true,
		autoplayTimeout: 4000,
		responsive: {
			0: {
				items: 3
			},
			480: {
				items: 4
			},
			768: {
				items: 6
			},
			1000: {
				items: 8
			}
		}
	})
});


//首頁相關連結
$(function () {
	var owl = $('.index_link_list');
	  owl.owlCarousel({
		margin: 30,
		nav: true,
		navText: false,
		loop: true,
		dots: false,
		autoplay:true,
		autoplayHoverPause:true,
		autoplayTimeout:4000,
		responsive: {
		  0: {
			items: 2
		  },
		  480: {
			items: 3
		  },
		  768: {
			items: 4
		  },
		  1000: {
			items: 5
		  }
		}
	  })
});


//輪播圖左告按鈕加title
$(function () {
	$(".owl-prev").attr("title","上一則").attr("tabindex","0").attr("role","button");
	$(".owl-next").attr("title","下一則").attr("tabindex","0").attr("role","button");
});


//owl-carousel 加tabindex=-1
$(function () {
	$('.owl-carousel .cloned').find('a').attr('tabindex','-1');
});


//左右鍵盤操作
$(function () {
	var owl = $(".owl-carousel");

        $(document).on('keydown', function (e) {

            var $focusedElement = $(document.activeElement),
                singleOwl = $(".owl-carousel"),
                type = e.which == 39 ? 'next' : null,
                type = e.which == 37 ? 'prev' : type,
                type = e.which == 13 ? 'enter' : type;

            singleOwl.owlCarousel();

            // if the carousel is focused, use left and right arrow keys to navigate
            console.log($focusedElement.attr('class'));
            if ($focusedElement.attr('class') == "owl-carousel") {
                debugger;
                if (type == 'next') {
                    singleOwl.trigger('next.owl.carousel');
                } else if (type == 'prev') {
                    singleOwl.trigger('prev.owl.carousel');
                }

            } else if (type == 'enter') {
                if ($focusedElement.hasClass('owl-next')) {

                    singleOwl.trigger('next.owl.carousel');
                } else if ($focusedElement.hasClass('owl-prev')) {

                    singleOwl.trigger('prev.owl.carousel');
                }
            }
        });
});



