// source --> https://puraluce.com/wp-content/themes/puraluce/js/script.js?ver=5.8 
  $(document).ready(function () {


      /* puraluce JS */
      $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
          event.preventDefault();
          event.stopPropagation();
          $(this).parent().siblings().removeClass('open');
          $(this).parent().toggleClass('open');
      });

      /* MENU APPEAR */
      /* MENU NAVIGAZIONE */

      $(".hamburger").click(function () {
          $('.navigazione__menu').toggleClass('navigazione__menu--show');
          $("html").toggleClass("scroll_fixed");
          $(".menu-full").toggleClass("navigazione__menu--appear");
      });

      /* menu mobile */

      var mql = window.matchMedia('(max-width: 990px)'); {

          $(".navigazione__menu .menu-item-has-children").click(function () {
              $(".navigazione__menu .menu-item-has-children .sub-menu").removeClass('sub-menu--show');
              $(".navigazione__menu .menu-item-has-children").removeClass('sub-menu--color');
              $(this).find('.sub-menu').toggleClass('sub-menu--show');
              $(this).addClass('sub-menu--color');
          });

      }


      /*
            =============================
      NORMAL PARALLAX PLUGIN SCROLL
            =============================*/

      var mql = window.matchMedia('(min-width: 990px)');

      /* IF - MOBILE */
      if (mql.matches) {

          $(window).enllax();

      }


      /* AOS ANIMATION SCROLL REVEAL INITIALIZE */
      /* AOS.init({
           once: true
       }) */


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

          if (scroll >= 50) {
              $(".navigazione").addClass("navigazione--scroll");
          } else {
              $(".navigazione").removeClass("navigazione--scroll");
          }
      });
	  
	    $(window).scroll(function () {
          var scroll = $(window).scrollTop();

          if (scroll >= 50) {
              $(".navigazione-top").addClass("navigazione-top--scroll");
          } else {
              $(".navigazione-top").removeClass("navigazione-top--scroll");
          }
      });


      /* MAGNIFIC POPUP */

      $('.image-link').magnificPopup({
          type: 'image',
          gallery: {
              // options for gallery
              enabled: true
          }
      });
	  
	  /* SWIPER JS HOME */

      var swiper = new Swiper('.swiper-container', {
          speed: 600,
           pagination: {
             el: '.swiper-pagination',
             clickable: true,
           },
           spaceBetween: 30,
           centeredSlides: true,
           autoplay: {
             delay: 3500,
          disableOnInteraction: false,
          },
           navigation: {
             nextEl: '.swiper-button-next',
             prevEl: '.swiper-button-prev',
           },
        });


		//Swiper Portfolio
        var swiper = new Swiper('.portfolio-canva', {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            direction: 'vertical',
            paginationType: 'fraction',
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
              },
            mousewheel: {
            releaseOnEdges: true,
            },
              keyboard: {
          enabled: true,
          onlyInViewport: false,
          },

        });



      /* CURSORE */

      var cursor = {
          delay: 2,
          _x: 0,
          _y: 0,
          endX: window.innerWidth / 2,
          endY: window.innerHeight / 2,
          cursorVisible: true,
          cursorEnlarged: false,
          $dot: document.querySelector(".cursor-dot"),
          $outline: document.querySelector(".cursor-dot-outline"),

          init: function () {
              // Set up element sizes
              this.dotSize = this.$dot.offsetWidth;
              this.outlineSize = this.$outline.offsetWidth;

              this.setupEventListeners();
              this.animateDotOutline();
          },

          //     updateCursor: function(e) {
          //         var self = this;

          //         console.log(e)

          //         // Show the cursor
          //         self.cursorVisible = true;
          //         self.toggleCursorVisibility();

          //         // Position the dot
          //         self.endX = e.pageX;
          //         self.endY = e.pageY;
          //         self.$dot.style.top = self.endY + 'px';
          //         self.$dot.style.left = self.endX + 'px';
          //     },

          setupEventListeners: function () {
              var self = this;

              // Anchor hovering
              document.querySelectorAll("a").forEach(function (el) {
                  el.addEventListener("mouseover", function () {
                      self.cursorEnlarged = true;
                      self.toggleCursorSize();
                  });
                  el.addEventListener("mouseout", function () {
                      self.cursorEnlarged = false;
                      self.toggleCursorSize();
                  });
              });

              // Click events
              document.addEventListener("mousedown", function () {
                  self.cursorEnlarged = true;
                  self.toggleCursorSize();
              });
              document.addEventListener("mouseup", function () {
                  self.cursorEnlarged = false;
                  self.toggleCursorSize();
              });

              document.addEventListener("mousemove", function (e) {
                  // Show the cursor
                  self.cursorVisible = true;
                  self.toggleCursorVisibility();

                  // Position the dot
                  self.endX = e.pageX;
                  self.endY = e.pageY;
                  self.$dot.style.top = self.endY + "px";
                  self.$dot.style.left = self.endX + "px";
              });

              // Hide/show cursor
              document.addEventListener("mouseenter", function (e) {
                  self.cursorVisible = true;
                  self.toggleCursorVisibility();
                  self.$dot.style.opacity = 1;
                  self.$outline.style.opacity = 1;
              });

              document.addEventListener("mouseleave", function (e) {
                  self.cursorVisible = true;
                  self.toggleCursorVisibility();
                  self.$dot.style.opacity = 0;
                  self.$outline.style.opacity = 0;
              });
          },

          animateDotOutline: function () {
              var self = this;

              self._x += (self.endX - self._x) / self.delay;
              self._y += (self.endY - self._y) / self.delay;
              self.$outline.style.top = self._y + "px";
              self.$outline.style.left = self._x + "px";

              requestAnimationFrame(this.animateDotOutline.bind(self));
          },

          toggleCursorSize: function () {
              var self = this;

              if (self.cursorEnlarged) {
                  self.$dot.style.transform = "translate(-50%, -50%) scale(0.75)";
                  self.$outline.style.transform = "translate(-50%, -50%) scale(0)";
              } else {
                  self.$dot.style.transform = "translate(-50%, -50%) scale(1)";
                  self.$outline.style.transform = "translate(-50%, -50%) scale(1)";
              }
          },

          toggleCursorVisibility: function () {
              var self = this;

              if (self.cursorVisible) {
                  self.$dot.style.opacity = 1;
                  self.$outline.style.opacity = 1;
              } else {
                  self.$dot.style.opacity = 0;
                  self.$outline.style.opacity = 0;
              }
          }
      };

      cursor.init();



      /*document ready function */
  });