
(function($) {



    $(window).scroll(function(){
      if ($(window).scrollTop() >= 300) {
          $('header#masthead').addClass('fixed-header');
      }
      else {
          $('header#masthead').removeClass('fixed-header');
      }
  });
  



    function responsiveIframe() {
        var videoSelectors = [
            'iframe[src*="player.vimeo.com"]',
            'iframe[src*="youtube.com"]',
            'iframe[src*="youtube-nocookie.com"]',
            'iframe[src*="kickstarter.com"][src*="video.html"]',
            'iframe[src*="screenr.com"]',
            'iframe[src*="blip.tv"]',
            'iframe[src*="dailymotion.com"]',
            'iframe[src*="viddler.com"]',
            'iframe[src*="qik.com"]',
            'iframe[src*="revision3.com"]',
            'iframe[src*="hulu.com"]',
            'iframe[src*="funnyordie.com"]',
            'iframe[src*="flickr.com"]',
            'embed[src*="v.wordpress.com"]',
            'iframe[src*="videopress.com"]',
            'embed[src*="videopress.com"]'
            // add more selectors here
        ];
        var allVideos = videoSelectors.join(',');
        jQuery(allVideos).wrap('<span class="media-holder" />');
    }

    // Responsive Iframes
    responsiveIframe();

    jQuery('.products').each(function(){
      jQuery(this).children("li.product").find("img").wrap('<div class="product-img-wrap"><div class="product-img"></div></div>');
 
  });
//   $(".product").each( function() {
//     //Get the links
//     var links = $(this).children(".button").html();
//     //Remove the links from the .links div
//     $(this).children(".button").html("");
//     //Append the links to the .submitted div
//     $(this).children(".product-img").append(links);
// });

if($(".main-wrap").hasClass("over-img")){
    $(".button").each(function(){
        $(this).appendTo( $(this).prevAll('.woocommerce-LoopProduct-link').find(".product-img-wrap") );
    });
}


if (jQuery(window).width() > 1024) {

    $('.belowprice .product_type_simple.add_to_cart_button').on('click', function () {
      var cart = $('.main-cart-icon');
      var imgtodrag = $(this).parent('li.product').find(".product-img").eq(0);
      if (imgtodrag) {
          var imgclone = imgtodrag.clone()
              .offset({
              top: imgtodrag.offset().top+100,
              left: imgtodrag.offset().left
          })
              .css({
              'opacity': '1',
                  'position': 'absolute',
                  'height': '100px',
                  'top':'300px !important',
                  'width': '100px',
                  'border-radius': '50%',
                  'overflow': 'hidden',
                  'z-index': '99999'
          })
              .appendTo($('body'))
              .animate({
              'top': cart.offset().top + 10,
                  'left': cart.offset().left + 10,
                  'width': 60,
                  'height': 60,
          }, 1000, 'easeInOutExpo');
          


          imgclone.animate({
              'width': 0,
                  'height': 0
          }, function () {
              $(this).detach()
          });
      }
  });


  $('.over-img .product_type_simple.add_to_cart_button').on('click', function () {
    var cart = $('.main-cart-icon');
    var imgtodrag = $(this).prev(".product-img").eq(0);
    if (imgtodrag) {
        var imgclone = imgtodrag.clone()
            .offset({
            top: imgtodrag.offset().top+100,
            left: imgtodrag.offset().left
        })
            .css({
            'opacity': '1',
                'position': 'absolute',
                'height': '100px',
                'top':'300px !important',
                'width': '100px',
                'border-radius': '50%',
                'overflow': 'hidden',
                'z-index': '99999'
        })
            .appendTo($('body'))
            .animate({
            'top': cart.offset().top + 10,
                'left': cart.offset().left + 10,
                'width': 60,
                'height': 60,
        }, 1000, 'easeInOutExpo');
        


        imgclone.animate({
            'width': 0,
                'height': 0
        }, function () {
            $(this).detach()
        });
    }
});
}

})(jQuery);

if (jQuery(window).width() < 1024) {
const  focusableElements =
    'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
const modal = document.querySelector('#mobile-menu-wrap'); // select the modal by it's id

const firstFocusableElement = modal.querySelectorAll(focusableElements)[0]; // get first element to be focused inside modal
const focusableContent = modal.querySelectorAll(focusableElements);
const lastFocusableElement = focusableContent[focusableContent.length - 1]; // get last element to be focused inside modal


document.addEventListener('keydown', function(e) {
  let isTabPressed = e.key === 'Tab' || e.keyCode === 9;

  if (!isTabPressed) {
    return;
  }

  if (e.shiftKey) { // if shift key pressed for shift + tab combination
    if (document.activeElement === firstFocusableElement) {
      lastFocusableElement.focus(); // add focus for the last focusable element
      e.preventDefault();
    }
  } else { // if tab key is pressed
    if (document.activeElement === lastFocusableElement) { // if focused has reached to last focusable element then focus first focusable element after pressing tab
      firstFocusableElement.focus(); // add focus for the first focusable element
      e.preventDefault();
    }
  }
});

firstFocusableElement.focus();
}