(function(){
    const sticky_elem = document.querySelector('.navbar').closest('.lt-block');
    
    window.addEventListener('scroll', function(){
        const top = this.scrollY;
        
        if(top > 0) {
            sticky_elem.classList.add('fixed');
        } else {
         	sticky_elem.classList.remove('fixed');
        }
    });
    
    window.dispatchEvent(new Event('scroll'));
    
    document.querySelectorAll('.review-block').forEach(function(block){
        block.querySelector('.video-play').addEventListener('click', function(){
            
        const video = document.createElement('video'),
              source = document.createElement("source"),
              video_wrapper = this.closest('.videoWrapper'),
        	  video_url = block.dataset.src;
            
        video.setAttribute('controls', '');
        video.setAttribute('controlslist', 'nodownload');
        video.setAttribute('playsinline', '');
        video.setAttribute('autoplay', '');

        source.type = "video/mp4",
        source.src = video_url;
            
        document.querySelectorAll('video').forEach(function(video){
            if(!video.paused) {
             	video.pause();   
            }
        });    
        
        video.appendChild(source);
        video_wrapper.removeAttribute("style");
        video_wrapper.appendChild(video);
            
        delete block.dataset.src;
        this.remove();
        });
    });
    
    document.querySelectorAll('.more-reviews .f-btn').forEach(function(button){
        button.addEventListener('click', function(e){
            const hidden_reviews = Array.prototype.slice.call(document.querySelectorAll('.reviews .hidden')),
                  limit = 2;
            
            for(let i = 0; i < hidden_reviews.length; i++) {
                
               hidden_reviews[i].classList.remove('hidden');
                
                if((i + 1) === limit) break;
            }
            
            if(document.querySelectorAll('.reviews .hidden').length === 0) {
            	document.querySelectorAll('.more-reviews .f-btn').forEach(el => el.parentElement.remove());
            }
        });
    });
    
    document.querySelectorAll('.navbar-toggle, .navbar-close').forEach(function(elem){
        elem.addEventListener('click', function(e){
            e.stopPropagation();
            e.target.closest('.navbar').querySelector('.navbar-collapse').classList.toggle('opened');
        });
    });
})();