$(function(){
	$(window).on('resize', function(){
	    if(lastScreenWidth > 0)
	    {   
	        // if main carousel should switch view...
	        if((lastScreenWidth < 576 && window.innerWidth >= 576) || (lastScreenWidth >= 576 && window.innerWidth < 576))
	        {
	            initMainBanner();
	        }
	    }

	    lastScreenWidth = window.innerWidth;
	});

	initMainBanner();
});

function initMainBanner()
{
    if($('.mainbanner').length>0)
    {
        if($('.mainbanner .owl-carousel').hasClass('owl-loaded'))
        {
            $('.mainbanner .owl-carousel').owlCarousel('destroy');
        }

        let size = window.innerWidth < 576 ? 'mobile' : 'desktop';

        $('.mainbanner .owl-carousel a').each(function(){
            let img = $(this).children('img');
            img.attr('src', null);
            img.attr('data-src', $(this).data(size+'-image'));
            img.attr('data-src-retina', $(this).data(size+'-image'));
        });

        $('.owl-carousel').owlCarousel({
            loop:true,
            items:1,
            margin:10,
            //nav:true,
            lazyLoad: true,
            lazyLoadEager: 1,
            autoplay:true,
            autoplayTimeout:3000,
            autoplayHoverPause:true,
            //animateOut: 'slideOutDown',
            //animateIn: 'flipInX',
            //smartSpeed:450,
            dots:true,
        });
    }
}