var CarouselOne = '.main-image';
var CarouselTwo = '.thumbnails';
var owlCarouselOne = $(CarouselOne).owlCarousel({
items: 1,
dots: false,
mouseDrag: false,
touchDrag: true
});
var owlCarouselTwo = $(CarouselTwo).owlCarousel({
items: 5,
margin: 10,
dots: false,
mouseDrag: false,
touchDrag: false
});
carouselSyncCurrentClass();
owlCarouselOne.on('changed.owl.carousel', function() {
carouselSyncCurrentClass();
});
owlCarouselTwo.on('changed.owl.carousel', function(event) {
carouselSyncCurrentClass();
});
owlCarouselTwo.find('.item').hover(function() {
var itemIndex = $(this).parent().index();
owlCarouselOne.trigger('to.owl.carousel', itemIndex);
carouselSyncCurrentClass();
});
function carouselSyncCurrentClass() {
setTimeout(function() {
var CarouselOneActiveIndex = $('.main-image .owl-item.active').index();
$('.thumbnails .owl-item').removeClass('current');
var currentItem = $('.thumbnails .owl-item:nth-child(' + (CarouselOneActiveIndex + 1) + ')');
currentItem.addClass('current');
if(!currentItem.hasClass('active')) {
if(currentItem.prevAll('.active').length > 0) {
owlCarouselTwo.trigger('next.owl.carousel');
}
if(currentItem.nextAll('.active').length) {
owlCarouselTwo.trigger('prev.owl.carousel');
}
}
}, 500);
}