var scrollPos = 0,
    oldScroll = 0,
    newScroll = 0,
    mobile = $(window).width() > 767 ? 0 : 1;

$(window).on('scroll', _.debounce(function() {
    bannerAnim()
}, 50));
$(window).on('load', function() {
    setTimeout(function() { $('html,body').animate({ scrollTop: 301 }, 800) }, 1000)
});
$(document).ready(function() {
    bannerAnim()
    if ($(window).height() < 768) {
        $('.banner,.scrollFx').css({ height: $(window).height() });
    }
});
var scrollUpOnce = 1

function bannerAnim() {
    var scrlTp = $(document).scrollTop();
    // console.log(1);
    newScroll = $(document).scrollTop();
    if (scrlTp <= 300) { // && once == 1
        
        // console.log(2);
        if (mobile) {
            $('.scrollFx').attr('class', 'scrollFx noscroll');
        } else {
            if (oldScroll < newScroll) {
                // console.log(2.1);
                $('.scrollFx').attr('class', 'scrollFx noscroll');
            } else {
                // console.log(2.2);
                stopBannerSlider();
                resetBannerSlider()
                setTimeout(function() { $('.scrollFx').attr('class', 'scrollFx noscroll') }, 1000);
            }
        }

    } else if (scrlTp > 300 && scrlTp < 1001) {
        
        // console.log(3);
        if (mobile) {
            $('.scrollFx').attr('class', 'scrollFx scrolled');
        } else {
            $('.scrollFx').attr('class', 'scrollFx scrolled');
            if (oldScroll < newScroll) { // && once == 1
                // console.log(3.1);
                startBannerCarousel();
            } else if (oldScroll > newScroll) { // && scrollUpOnce == 1
                // console.log(3.2);
                startBannerSlider();
                // scrollUpOnce = 2;
            }
        }
        // console.log(1);
    } else if (scrlTp > 1000) {
        
        // console.log(4);
        if (!mobile) {
            stopBannerSlider();
        }
        // scrollUpOnce = 1;
        // console.log(3);
    }
    oldScroll = newScroll;
}