jQuery( document ).ready( function($){
   "use strict";

   
   /**-------------------------------------------------
     *Fixed Header
     *----------------------------------------------------**/
    $(window).on('scroll', function () {

      /**Fixed header**/
      if ($(window).scrollTop() > 250) {
      $('.navbar-sticky').addClass('sticky fade_down_effect');
      } else {
      $('.navbar-sticky').removeClass('sticky fade_down_effect');
      }
});


  /* ----------------------------------------------------------- */
  /*  Menu
  /* ----------------------------------------------------------- */
   $('.dropdown > a').on('click', function(e) {
      e.preventDefault();
      if($(window).width() > 991)
      {
         location.href = this.href; 
      } 
      var dropdown = $(this).parent('.dropdown');
      dropdown.find('>.dropdown-menu').slideToggle('show');
      $(this).toggleClass('opened');
      return false;
    });

    $('.digiqole-elementskit-menu').each(function(){
        $(this).parents('.navbar').addClass('digiqole-elementskit-menu-container');
    });

    /*==========================================================
                    39. scroll bar
        ======================================================================*/

    //     if ($(".video-tab-scrollbar").length > 0) {
    //      $(".video-tab-scrollbar").mCustomScrollbar({
    //          mouseWheel: true,
    //          scrollButtons: {
    //              enable: true
    //          }
    //      });
    //  }

   
   /* ----------------------------------------------------------- */
   /*  tooltip
   /* ----------------------------------------------------------- */
   $(document).ready(function () {
      $('[data-toggle="tooltip"]').tooltip();
   });

    /*==========================================================
                   search popup
        ======================================================================*/
        if ($('.xs-modal-popup').length > 0) {
            $('.xs-modal-popup').magnificPopup({
                type: 'inline',
                fixedContentPos: false,
                fixedBgPos: true,
                overflowY: 'auto',
                closeBtnInside: false,
                callbacks: {
                    beforeOpen: function beforeOpen() {
                        this.st.mainClass = "my-mfp-slide-bottom xs-promo-popup";
                    }
                }
            });
        }

    /* ----------------------------------------------------------- */
   /*  Video popup
   /* ----------------------------------------------------------- */

  if ($('.ts-play-btn').length > 0) {
   $('.ts-play-btn').magnificPopup({
       type: 'iframe',
       mainClass: 'mfp-with-zoom',
       zoom: {
           enabled: true, // By default it's false, so don't forget to enable it

           duration: 300, // duration of the effect, in milliseconds
           easing: 'ease-in-out', // CSS transition easing function

           opener: function (openerElement) {
               return openerElement.is('img') ? openerElement : openerElement.find('img');
           }
       }
   });
}

  if ($('.play-btn').length > 0) {
   $('.play-btn').magnificPopup({
       type: 'iframe',
       mainClass: 'mfp-with-zoom',
       zoom: {
           enabled: true, // By default it's false, so don't forget to enable it

           duration: 300, // duration of the effect, in milliseconds
           easing: 'ease-in-out', // CSS transition easing function

           opener: function (openerElement) {
               return openerElement.is('img') ? openerElement : openerElement.find('img');
           }
       }
   });
}


   /* ----------------------------------------------------------- */
   /*  Back to top
   /* ----------------------------------------------------------- */

   $(window).on('scroll', function () {
    if ($(window).scrollTop() > $(window).height()) {
       $(".BackTo").fadeIn('slow');
    } else {
       $(".BackTo").fadeOut('slow');
    }

    });
    $("body, html").on("click", ".BackTo", function (e) {
        e.preventDefault();
        $('html, body').animate({
          scrollTop: 0
        }, 800);
    });

    $(".popular-grid-slider").owlCarousel(
           {
            items: 3,
            dots: false,
            loop: true,
            nav: true,
            margin: 30,
            navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
            responsive: {
                // breakpoint from 0 up
                0: {
                    items: 1,
                },
                // breakpoint from 480 up
                480: {
                    items: 2,
                },
                // breakpoint from 768 up
                768: {
                    items: 2,
                },
                // breakpoint from 768 up
                1200: {
                    items: 3,
                }
            }
        }
    );

    $(".category-feature-slider").owlCarousel(
           {
            items: 1,
            dots: false,
            loop: false,
            nav: true,
            margin: 30,
            navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
        }
    );

    /*==========================================================
                     scroll bar
        ======================================================================*/

        $('.video-tab-list .post-tab-list li').on('click',function(){
            $('.video-index').html($(this).data('index'));
        });

        if ($(".video-tab-scrollbar").length > 0) {

         $(".video-tab-scrollbar").mCustomScrollbar({
             mouseWheel: true,
             scrollButtons: {
                 enable: true
             }
         });
         
     }

    

      /*==========================================================
                     Post grid ajax load
        ======================================================================*/
  
   $('.digiqole-post-grid-loadmore').on('click',function(event){
      event.preventDefault();
      
      var $that = $(this);
      var ajaxjsondata = $that.data('json_grid_meta');
      var digiqole_json_data = Object (ajaxjsondata);
     
      var contentwrap = $('.grid-loadmore-content'), // item contentwrap
          postperpage = parseInt(digiqole_json_data.posts_per_page), // post per page number
          showallposts = parseInt(digiqole_json_data.total_post); // total posts count

          var items = contentwrap.find('.grid-item'),
          totalpostnumber = parseInt(items.length),
          paged =  parseInt( totalpostnumber / postperpage ) + 1; // paged number
         
         $.ajax({
            url: digiqole_ajax.ajax_url,
            type: 'POST',
            data: {action: 'digiqole_post_ajax_loading',ajax_json_data: ajaxjsondata,paged:paged},
            beforeSend: function(){
               
                $('<i class="fa fa-spinner fa-spin" style="margin-left:10px"></i>').appendTo( "#digiqole-post-grid-loadmore" ).fadeIn(100);
            },
            complete:function(){
                $('.digiqole-post-grid-loadmore .fa-spinner ').remove();
            }
         })
        
         .done(function(data) {
           
               var $pstitems = $(data);
               $('.grid-loadmore-content').append( $pstitems );
               var newLenght  = contentwrap.find('.grid-item').length;
            
               if(showallposts <= newLenght){
                  $('.digiqole-post-grid-loadmore').fadeOut(300,function(){
                     $('.digiqole-post-grid-loadmore').remove();
                  });
               }
         
         })

         .fail(function() {
            $('.digiqole-post-grid-loadmore').remove(); 
         });
	
    });
    
          /*==========================================================
                    review rating circle
        ======================================================================*/
        $(function() {
            $('.review-chart').easyPieChart({
              scaleColor: "",
              lineWidth: 5,
              lineCap: 'butt',
              barColor: '#1abc9c',
              trackColor:	"rgba(34,34,34, .4)",
              size: 70,
              animate: 70
            });
          });

         /*==========================================================
                   reading progressbar
        ======================================================================*/  
       
        window.onscroll = function() { reading_progressbar() };

         function reading_progressbar() {
               var digiqole_winScroll = document.body.scrollTop || document.documentElement.scrollTop;
               var digiqole_height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
               var digiqole_scrolled = (digiqole_winScroll / digiqole_height) * 100;
               if (document.getElementById("readingProgressbar")) {
                document.getElementById("readingProgressbar").style.width = digiqole_scrolled + "%";
            }
         }
       
        reading_progress_bar_post();
  
         function reading_progress_bar_post() {
           
            var progressWrap = $('.digiqole_progress_container');
            
       
            if ( progressWrap.length > 0 ) {
                var didScroll = false,
                    windowWrap = $(window),

                    contentWrap = $('.entry-content'),
                    contentHeight = contentWrap.height(),
                    windowHeight = windowWrap.height() * .85;
      
                $(window).scroll(function() {
                    didScroll = true;
                });
      
                $(window).on('resize', function(){
                    windowHeight = windowWrap.height() * .85;
                    progressReading();
                });
      
                setInterval(function() {
                    if ( didScroll ) {
                        didScroll = false;
                        progressReading();
                    }
                }, 150);
      
                var progressReading = function() {
      
                    var windowScroll = windowWrap.scrollTop(),
                        contentOffset = contentWrap.offset().top,
                        contentScroll = ( windowHeight - contentOffset ) + windowScroll,
                        progress = 0;
      
                    if ( windowHeight > contentHeight + contentOffset ) {
                        progressWrap.find('.progress-bar').width(0);
                    } else {
                        if ( contentScroll > contentHeight ) {
                            progress = 100;
                        } else if ( contentScroll > 0 ) {
                            progress = ( contentScroll / contentHeight ) * 100 ;
                           
                        }
      
                        progressWrap.find('.progress-bar').width(progress + '%');
                    }
                }
            }
        }

        // Sticky sidebar

      if(digiqole_ajax.blog_sticky_sidebar == 'yes' && $('#sidebar').length>0){
               
        var top = $('#sidebar').offset().top - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
        var footTop = null;
        if($('.newsletter-area').length>0){
             footTop = $('.newsletter-area').offset().top - parseFloat($('.newsletter-area').css('marginTop').replace(/auto/, 0));
        } else if($('.ts-footer').length>0){
            footTop = $('.ts-footer').offset().top - parseFloat($('.ts-footer').css('marginTop').replace(/auto/, 0));
       }
        else{
            footTop = $('.copy-right').offset().top - parseFloat($('.copy-right').css('marginTop').replace(/auto/, 0));  
        }
       

        var maxY = footTop - $('#sidebar').outerHeight();

        $(window).scroll(function(evt) {
           var y = $(this).scrollTop();

           if($(window).width() > 991)
           {
            if (y > top) {

                if (y < maxY) {
                      $('#sidebar').addClass('fixed').removeAttr('style');
                } else {
                      
  
                      $('#sidebar').removeClass('fixed').css({
                        
                         top: (maxY - top) + 'px',
                         position: 'relative',
                      });
                }
             } else {
  
              $('#sidebar').removeClass('fixed');
             }
           }
         
        });

  }


} );

  