;
(function($) {
    "use strict";

    //Mobile Menu
    $("#primary-menu").slicknav({
        allowParentLinks: true,
        prependTo: '#mobile',
        label: 'Menu',
    });
    
    var sf = $('#primary-menu').superfish({
        delay: 500, // one second delay on mouseout
        animation: { opacity: 'show', height: 'show' }, // fade-in and slide-down animation
        speed: 'fast', // faster animation speed
    });
    

    //Mobile Menu
    $("#header-top").slicknav({
        allowParentLinks: true,
        prependTo: '#topheader',
        label: 'Top Menu',
    });
    
    var sf = $('#header-top').superfish({
        delay: 500, // one second delay on mouseout
        animation: { opacity: 'show', height: 'show' }, // fade-in and slide-down animation
        speed: 'fast', // faster animation speed
    });

    // Header Search
    if ($(".search-open").length) {
        $(".search-open").on("click", function(e) {
            e.preventDefault();
            $(".header-search-popup").toggleClass("active");
        });
    }

    // Sticky Menu Premium
    $(window).on('scroll', function() {
        var scroll = $(window).scrollTop();
        if (scroll < 100) {
            $("#sticky-header").removeClass("sticky-bar");
        } else {
            $("#sticky-header").addClass("sticky-bar");
        }
    });


    // Theme Preloader
    $(window).on("load", function() {
        if ($(".preloader-area").length) {
            $(".preloader-area").fadeOut();
        }
    });

    // Post Slider
    function newshit_rtl(){
        if ($('body').hasClass("rtl")) {
           return true;
        } else {
           return false;
        }
    }
    
    // Bottom to top 
    $(window).on('scroll', function() {
        if ($(this).scrollTop() > 300) {
            $('#back-top').fadeIn();
        } else {
            $('#back-top').fadeOut();
        }
    });

    $('#back-top').on('click', function() {
        $("html, body").animate({
            scrollTop: 0
        }, 1000);
        return false;
    });

    // PopUp Video
    if( $(".mfp-iframe").length ){
        $('.mfp-iframe').magnificPopup({
            type: 'iframe',
            mainClass: 'mfp-fade',
            removalDelay: 160,
            preloader: false,
            fixedContentPos: false
        });
    }
    // Post Gallerly
    if ($('.post-gallery').length) {
        $('.post-gallery').slick({
            dots: false,
            infinite: true,
            speed: 700,
            cssEase: 'linear',
            autoplay: true,
            autoplaySpeed: 2000,
            arrows: true,
            rtl: newshit_rtl(),
            prevArrow: '<i class="slick-arrow slick-prev fas fa-angle-left"></i>',
            nextArrow: '<i class="slick-arrow slick-next fas fa-angle-right"></i>',
        });
    }
    
    // Theme Dark And Light Mode Options
    const darkSwitch = document.querySelector('#darkswitch');

    const htmlElement = document.querySelector('html');

    function setThemeMode(mode) {
      htmlElement.setAttribute('data-theme-mode', mode);
    }

    function loadThemeMode() {
      const storedTheme = localStorage.getItem('themeMode');
      if (storedTheme) {
          setThemeMode(storedTheme);
          if (darkSwitch) {
            darkSwitch.checked = storedTheme === 'dark';
          }
      } else {
          setThemeMode(defaultTheme);
          if (darkSwitch) {
            darkSwitch.checked = defaultTheme === 'dark';
          }
      }
    }

    if (darkSwitch) {
      darkSwitch.addEventListener('click', function () {
        if (darkSwitch.checked) {
          setThemeMode('dark');
        } else {
          setThemeMode('light');
        }
      });
    }

    // Get the value of the theme mode from the hidden input field.
    const themeMode = document.querySelector('input[name="theme_mode"]').value;

    // Set the theme mode.
    setThemeMode(themeMode);
    

    // WooCommerce product Popup
    var $rtl = $('body').hasClass("rtl") ? true : false;
    if ($('.woo-spimg').length) {
        $('.woo-spimg').magnificPopup({
            delegate: 'a',
            type: 'image',
            mainClass: 'mfp-zoom-out', // this class is for CSS animation below
            gallery: { enabled: true },
            zoom: {
                enabled: true,
                duration: 300,
                easing: 'ease-in-out',
                opener: function(openerElement) {
                    return openerElement.is('img') ? openerElement : openerElement.find('img');
                }
            }
        });
    }
    // WooCommerce Big Image
    if ($('.woo-product-big-img').length) {
        $('.woo-product-big-img').slick({
            slidesToShow: 1,
            slidesToScroll: 1,
            arrows: false,
            fade: true,
            asNavFor: '.woo-product-small-img',
            rtl: $rtl,
        });
    }

    // WooCommerce Small Image
    if ($('.woo-product-small-img').length) {
        $('.woo-product-small-img').slick({
            slidesToShow: 4,
            slidesToScroll: 1,
            asNavFor: '.woo-product-big-img',
            dots: true,
            arrows: false,
            focusOnSelect: true,
            centerMode: true,
            centerPadding: '60px',
            rtl: $rtl,
        });
    }
    // Grid View and List View
    if ($('#newshit-shop-view-mode li').length) {
        $('#newshit-shop-view-mode li').on('click', function() {
            $('body').removeClass('newshit-product-grid-view').removeClass('newshit-product-list-view');

            if ($(this).hasClass('newshit-shop-list')) {
                $('body').addClass('newshit-product-list-view');
                Cookies.set('newshit-shop-view', 'list');
            } else {
                $('body').addClass('newshit-product-grid-view');
                Cookies.remove('newshit-shop-view');
            }
            return false;
        });
    }

    // News Ticker
    if ($('.newshit-news-ticker').length) {
        $('.newshit-news-ticker').AcmeTicker({
            type:'marquee',
            direction: 'left',
            speed: 0.09,
        });
    }

    // Post Gallerly
    if ($('.banner-post-slide').length) {
        $('.banner-post-slide').slick({
            dots: false,
            infinite: true,
            speed: 700,
            cssEase: 'linear',
            autoplay: true,
            autoplaySpeed: 2000,
            arrows: true,
            rtl: newshit_rtl(),
            prevArrow: $('.custom-slider-prev'),
            nextArrow: $('.custom-slider-next'),
        });
    }

    if ( $('.featured-section').length ){
        $('.featured-section').slick({
            dots: false,
            infinite: true,
            speed: 300,
            slidesToShow: 4,
            slidesToScroll: 4,
            rtl: newshit_rtl(),
            arrows: true,
            prevArrow: $('.featured-prev'),
            nextArrow: $('.featured-next'),
            responsive: [
              {
                breakpoint: 1200,
                settings: {
                  slidesToShow: 3,
                  slidesToScroll: 3,
                }
              },
              {
                breakpoint: 769,
                settings: {
                  slidesToShow: 2,
                  slidesToScroll: 2
                }
              },
              {
                breakpoint: 480,
                settings: {
                  slidesToShow: 1,
                  slidesToScroll: 1
                }
              }
            ]
        });
    }

    if ( $('.most-liked-section').length ){
        $('.most-liked-section').slick({
            dots: false,
            infinite: true,
            speed: 300,
            slidesToShow: 4,
            slidesToScroll: 4,
            rtl: newshit_rtl(),
            arrows: true,
            prevArrow: $('.most-prev'),
            nextArrow: $('.most-next'),
            responsive: [
              {
                breakpoint: 1200,
                settings: {
                  slidesToShow: 3,
                  slidesToScroll: 3,
                }
              },
              {
                breakpoint: 769,
                settings: {
                  slidesToShow: 2,
                  slidesToScroll: 2
                }
              },
              {
                breakpoint: 480,
                settings: {
                  slidesToShow: 1,
                  slidesToScroll: 1
                }
              }
            ]
        });
    }

    if ($('.category-menu-wrapper ul li').length) {
        $('.category-menu-wrapper ul li').on('click', function() {
            $('.category-menu-wrapper ul li').removeClass('active');
            $(this).addClass('active');
            var selector = $(this).attr('data-filter');
            $('.newshit-caregory-post-list').isotope({
                filter: selector,
            });
        });
        $('.newshit-masonry').isotope({
            itemSelector: '.newshit-category-item',
        });
        
    }

}(jQuery))