// jQuery(document).ready(myfunction);
// jQuery(window).resize(myfunction);
// function myfunction() {

//   jQuery('#home_banner .banner_outer').css('padding-top', jQuery('#main_header').height()+'px');
//   jQuery('#overlay_menu .overlay_wrapper').css('padding-top', jQuery('#main_header').height()+'px');
//   jQuery('#home_banner .banner_outer').css('height', jQuery(window).height()+'px');
//   jQuery('#home_banner').css('height', jQuery(window).height()+'px');

// }

jQuery(document).ready(function ($) {

  //Block this person from filling in forms (First Name: Priyesh, Last Name: prakash, Company Name: Harmonic Funds Services, Email Address: Priyeshcandoit@gmail.com, Phone Number: 2267004855 )
  let blackList = ['Priyesh', 'prakash', 'Prakash', 'Priyeshcandoit@gmail.com', '2267004855', 'Dipen', 'Hirpara', 'Socratic Solutions', 'dipenhirpara4@gmail.com', 'dipenhirpara4@gmail.com'];
  let expr = new RegExp(blackList.join('|'));
  let formInputs = document.querySelectorAll('input');

  for (let i = 0; i < formInputs.length; i++) {
    formInputs[i].onkeyup = function () {
      if (this.value.search(expr) !== -1) {
        this.value = '';
      }
    }
  }

  //Blocking Formstack forms by ip
  function blockFormSubmission(userIP) {
    // Define your own set of banned IP addresses
    var blockedIPs = ['192.167.0.0', '10.0.0.1'];
    // Check if the user's IP address is on the banned list
    if (blockedIPs.includes(userIP)) {
      return false;
    } else {
      return true;
    }
  }

  // Function for obtaining the user's IP address
  function getUserIP() {
    // Function for obtaining the user's IP address
    $.get('https://api64.ipify.org?format=json', function (data) {
      const userIP = data.ip;
      //console.log(`userIP: ${userIP}`);
      blockFormSubmission( userIP );
    });
  }

  // Form submission handler
  $(document).on('submit', '.fsForm', function () {
    // Get the user's IP address before submitting the form
    getUserIP();
    // console.log(`getUserIP(): ${getUserIP()}`);
    return false; // Override the default behavior of the form
  });

  //Catecory Page
  if ($('.blog_section').length) {
    $entry_title = $('.blog_section .et_pb_salvattore_content article .entry-title')
    $entry_title.matchHeight(
      {
        byRow: true,
        property: 'height',
        // target: null,
        remove: false
      }
    );

    $post_content_inner_p = $('.blog_section .et_pb_salvattore_content article .post-content .post-content-inner p')
    $post_content_inner_p.matchHeight(
      {
        byRow: true,
        property: 'height',
        // target: null,
        remove: false
      }
    );

    $('#section-blog .recent-content h4').matchHeight(
      {
        byRow: false,
        property: 'height',
        // target: null,
        remove: false
      }
    );
  }

  if ($('.single-managed-it-services-section').length) {
    $blog_list_title = $('.single-managed-it-services-section .it-services-title h3');
    $blog_list_description = $('.single-managed-it-services-section .it-services-description p');

    $blog_list_title.matchHeight({
        byRow: true,
        property: 'height',
        remove: false
    });

    $blog_list_description.matchHeight({
        byRow: true,
        property: 'height',
        remove: false
    });
}

  //.author-info after the title
  if (jQuery('.page-content h2:first-of-type').length) {
    jQuery('.page-content h2:first-of-type').insertBefore('.page-content .author-info');
  }
  /*	let $h2_first = $('.page-content .author-info').next('h2');
    $('.page-content .author-info').before($h2_first);*/

  //Social Share
  if ($('a.share-btn, a.share').length) {
    $('a.share-btn, a.share').on('click', function (e) {
      e.preventDefault();
      $(this).toggleClass('active');
      $('.share-print').toggleClass('active');
      $(this).closest(div.battons).find(div.heateor_sss_sharing_container).toggleClass('active');
    })
  }

  /* Fix fsForm tab submit problem */
  //Fix enter forms
  form_enter_fix();
  function form_enter_fix() {
    $('.hero-form .fsForm input, .hero-form .fsForm select').keypress(function (e) {
      let thisForm = $(this).closest('.fsForm');
      let thisSubmit = thisForm.find('.fsSubmitButton');
      if (e.which == 13) {
        thisSubmit.click();
        return false;
      }
    });
  }

  //Wrapp table p.table
  $('#main-content .content-wrap.blog_content table').wrapAll("<p class='table'></p>");

  function author_replice() {
    let $single = $('.single');
    let $page = $('.page');

    if ($single.length || $page.length) {
      let $author = $('.author-start-content');

      // if(('#main-content .content-wrap > h2:first-of-type').length) {
      //   $author.insertBefore($(this));
      // } else {
      $author.insertBefore($('#main-content .content-wrap > p:first-of-type'));
      // }
    }
  }

  author_replice();

  if ($('#service_section').length) {
    $service_text_h3 = $('#service_section .service_text h3')
    $service_text_h3.matchHeight(
      {
        byRow: true,
        property: 'height',
        // target: null,
        remove: false
      }
    );

    $service_text_p = $("#service_section .service_text p");
    $service_text_p.matchHeight(
      {
        byRow: true,
        property: 'height',
        // target: null,
        remove: false
      }
    );

    $(window).resize(function () {
      $service_text_h3.matchHeight(
        {
          byRow: true,
          property: 'height',
          // target: null,
          remove: false
        }
      );
    });
  }


  if ($('#casestudy-page').length) {
    $case_studies_caption = $('#casestudy-page .text-wrap .caption')
    $case_studies_caption.matchHeight(
      {
        byRow: true,
        property: 'height',
        // target: null,
        remove: false
      }
    );

    $case_studies_p = $('#casestudy-page .text-wrap p')
    $case_studies_p.matchHeight(
      {
        byRow: false,
        property: 'height',
        // target: null,
        remove: false
      }
    );
  }

  let w_width = $(window).width();

  //if (w_width > 767) {
  //scroling_header();
  //}

  //Sidebar floating
  let $single = $('.single');
  let $page = $('.page');
  let $category = $('.category-blog');
  let $subpageTemplate = $('.page-template-subpage-template');
  let $sidebarContent = $('#sidebar-content');

  //if ($single.length || $subpageTemplate.length || $sidebarContent.length) {
  // init controller
  //	let controller = new ScrollMagic.Controller();
  //	let wwheight = $(window).height();
  //	let $blog_content = $('#main-content .content-wrap');
  //	var contHeight = $blog_content.height();
  //	/*console.log('contHeight: ' + contHeight);
  //	console.log('wwheight: ' + wwheight);*/

  //	$(function () { // wait for document ready
  //		// build scene
  //		let scene = new ScrollMagic.Scene({
  //			triggerElement: "#sidebar-content",
  //			duration: contHeight - 0.9 * wwheight,
  //			triggerHook: 'onLeave',
  //			offset: -140
  //		})
  //			.setPin('#sidebar-content')
  //			// .addIndicators({name: "Start"})
  //			.addTo(controller);
  //	});
  //}

  //if ($page.length && !$('.page-id-8983').length && !$subpageTemplate.length && $sidebarContent.length) {
  // init controller
  //	let controller = new ScrollMagic.Controller();
  //	let wwheight = $(window).height();
  //	let $blog_content = $('#content_page .content_wrap');
  //	let contHeight = $blog_content.height();

  //	/*console.log('contHeight: ' + contHeight);
  //	console.log('wwheight: ' + wwheight);*/

  //	$(function () { // wait for document ready
  //		// build scene
  //		let scene = new ScrollMagic.Scene({
  //			triggerElement: "#sidebar-content",
  //			duration: contHeight - 0.8 * wwheight,
  //			triggerHook: 'onLeave',
  //			offset: -140
  //		})
  //			.setPin('#sidebar-content')
  //			// .addIndicators({name: "Start"})
  //			.addTo(controller);
  //	});
  //}

  /* Subpage template sidebar floating */

  // if($subpageTemplate.length) {
  //   // init controller
  //   let controller = new ScrollMagic.Controller();
  //   let wwheight = $( window ).height();
  //   let $blog_content = $('#main-content .base-container');
  //   var contHeight = $blog_content.height();
  //   console.log('contHeight: ' + contHeight);
  //   console.log('wwheight: ' + wwheight);

  //   $( function () { // wait for document ready
  //     // build scene
  //     let scene = new ScrollMagic.Scene( {
  //       triggerElement: ".sidebar-col .sidebar-wrap",
  //       duration: contHeight-0.9*wwheight,
  //       triggerHook: 'onLeave',
  //       offset: -140
  //     } )
  //       .setPin( '.sidebar-col .sidebar-wrap' )
  //       // .addIndicators({name: "Start"})
  //       .addTo( controller );
  //   } );
  // }

  //function sidebar_category_blog_floting() {
  //	if ($(window).width < 991) {
  //		return false
  //	} else {
  //		if ($category.length || $sidebarContent.length) {
  //			// init controller
  //			let controller = new ScrollMagic.Controller();
  //			let wwheight = $(window).height();
  //			let $blog_content = $('#category_page .container_blog');
  //			let contHeight = $blog_content.height();
  //			console.log('contHeight: ' + contHeight);
  //			console.log('wwheight: ' + wwheight);

  //			let duration_p = contHeight - wwheight;

  //			if (duration_p < 0) {
  //				duration_p = wwheight;
  //			}

  //			$(function () { // wait for document ready
  //				// build scene
  //				let scene = new ScrollMagic.Scene({
  //					triggerElement: "#sidebar-content",
  //					duration: duration_p,
  //					triggerHook: 'onLeave',
  //					offset: -140
  //				})
  //					.setPin('#sidebar-content')
  //					// .addIndicators({name: "Start"})
  //					.addTo(controller);
  //			});
  //		}
  //	}
  //}

  //sidebar_category_blog_floting();

  $(window).resize(function () {
    if ($(window).width < 991) {
      $(".main").data("sidebar_category_blog_floting").destroy();
    }
  });

  // jQuery('header#header.updated .header-menu').meanmenu();
  // jQuery('header#header.updated #header-menu > li.menu-item:not(:last-child)').after('<li class="slash">/</li>');


  //2023
  $('.header-jan2023 .meanmenu-content').meanmenu({
    meanMenuContainer: '.meanmenu-trigger',
    meanMenuOpen: '<div class="slide-menu_btn-wrap"><div class="slide-menu_trigger"><span></span><span></span><span></span><span></span><div>MENU</div></div></div>',
    meanMenuClose: '<div class="slide-menu_btn-wrap"><div class="slide-menu_trigger"><span></span><span></span><span></span><span></span><div>MENU</div></div></div>',
  });

  $('.slide-menu_close,.slide-menu_trigger').on('click', function () {
    $('body').toggleClass('slide-menu_opened');
    $('.slide-menu_trigger').toggleClass('closed');
  })

  // Hide Header on on scroll down
  let didScroll;
  let lastScrollTop = 0;
  let delta = 5;
  let navbarEl = $('.header-jan2023 .main-header');
  let navbarHeight = $('.header-jan2023 .main-header').outerHeight();

  $(window).scroll(function (event) {
    didScroll = true;
  });

  setInterval(function () {
    if (didScroll) {
      hasScrolled();
      didScroll = false;
    }
  }, 250);

  // console.log($(this).scrollTop())
  if ($(this).scrollTop()) $(navbarEl).removeClass('nav-up').addClass('nav-down');
  if ($(this).scrollTop() <= navbarHeight) $(navbarEl).removeClass('nav-up nav-down');


  function hasScrolled() {
    let st = $(this).scrollTop();

    // Make sure they scroll more than delta
    if (Math.abs(lastScrollTop - st) <= delta)
      return;
    // If they scrolled down and are past the navbar, add class .nav-up.
    // This is necessary so you never see what is "behind" the navbar.
    if (st > lastScrollTop && st > navbarHeight && $('.meanmenu-reveal.meanclose').length == 0) {
      // Scroll Down
      $(navbarEl).removeClass('nav-down').addClass('nav-up');
    } else {
      // Scroll Up
      if (st + $(window).height() < $(document).height()) {
        $(navbarEl).removeClass('nav-up').addClass('nav-down');
      }
      if (st <= navbarHeight) {
        $(navbarEl).removeClass('nav-up nav-down')
      }
    }

    lastScrollTop = st;
  }

  hasScrolled();

  // $('.header-jan2023 + div').css('padding-top', Math.round(navbarHeight));

  $(window).resize(function () {
    let navbarH = $(navbarEl).outerHeight();
    $('.header-jan2023 + div').css('padding-top', Math.round(navbarH));
  });
  //2023  end

  //
  if ($('.single-blog').length) {
    $single_blog_post_title = $('body.single .single-blog-post-title, body.page .single-blog-post-title')
    $single_blog_post_title.matchHeight(
      {
        byRow: true,
        property: 'height',
        // target: null,
        remove: false
      }
    );
  }


  // Rank Math Faq Accordion
  let faqWrap = jQuery('#rank-math-rich-snippet-wrapper #rank-math-faq .rank-math-list');

  if (faqWrap.length > 0) {
    faqWrap.find('.rank-math-list-item').each(function (i, el) {
      let faq = jQuery(this);
      let faqTitle = faq.find('.rank-math-question');
      let faqContent = faq.find('.rank-math-answer');
      if (i === 0) {
        faqContent.slideDown();
        faqTitle.addClass('active');
      } else {
        faqContent.slideUp();
        faqTitle.removeClass('active');
      }
      faq.click(function () {
        faqContent.slideDown(200);
        faqTitle.addClass('active');
        jQuery(this).siblings('.rank-math-list-item').find('.rank-math-answer').slideUp(200);
        jQuery(this).siblings('.rank-math-list-item').find('.rank-math-question').removeClass('active');
      });
    });
  }
  // End Rank Math Faq Accordion

  // Wrap the iframe with a center tag
  jQuery('#inner_content.single-content-standart-2023 .single-content-left-col iframe').each(function () {
    /*if (jQuery(this).parent('p')) {
      jQuery(this).wrap('<center></center>');
    }*/
    jQuery(this).wrap('<center></center>');

  });
  // End Wrap the iframe with a center tag

  // Ol li more than 15
  let singleOl = jQuery('body:not(.page-id-9016) #inner_content.single-content-standart-2023 .single-content-left-col>ol, body:not(.page-id-9016) #inner_content.single-content-standart-2023 .single-content-left-col>ul');
  if (singleOl.length > 0) {
    singleOl.each(function (i, el) {
      let maxOl = jQuery(this);
      if (maxOl.children('li').length > 15) {
        maxOl.css('column-count', '2');
      }
    })
  }
  // End Ol li more than 15


  //Social Share
  if ($('a.share-btn, a.share').length) {
    $('a.share-btn, a.share').on('click', function (e) {
      e.preventDefault();
      $(this).toggleClass('active');
      //$(this).next(div.heateor_sss_sharing_container).toggleClass('active');
    })
  }
  //End Social Share
});

// jQuery(window).resize(function () {
//   let wr_width = jQuery(this).width();
//   if (wr_width > 767) {
//     scroling_header();
//   }
// });

// function scroling_header() {
//   let ww_width = jQuery(window).width();

//   if (ww_width < 767) {
//     return false;
//   } else {

//     var lastScrollTop = 0;
//     jQuery(window).scroll(function (event) {
//       let $topBar = jQuery('#main_header .topBar');
//       let $fullwidthMenu = jQuery('#main_header .header_wrap .fullwidth-menu');
//       let $headerSocialMedia = jQuery('#main_header .header_wrap .header_content .header_social_media');
//       let $mainHeader = jQuery('#main_header');

//       let st = jQuery(this).scrollTop();
//       if (st == 0 || lastScrollTop == 0) {

//         // $topBar.fadeIn();
//         // $fullwidthMenu.fadeIn();
//         // $headerSocialMedia.fadeIn();
//         $mainHeader.removeClass('active');

//         $topBar.show();
//         $fullwidthMenu.show();
//         $headerSocialMedia.show();
//       } else {
//         // $topBar.fadeOut();
//         // $fullwidthMenu.fadeOut();
//         // $headerSocialMedia.fadeOut();
//         $mainHeader.addClass('active');
//         $topBar.hide();
//         $fullwidthMenu.hide();
//         $headerSocialMedia.hide();
//       }

//       if (st > lastScrollTop) {

//         // $topBar.fadeOut();
//         // $fullwidthMenu.fadeOut();
//         // $headerSocialMedia.fadeOut();
//         $mainHeader.addClass('active');

//         $topBar.hide();
//         $fullwidthMenu.hide();
//         $headerSocialMedia.hide();
//       }
//       lastScrollTop = st;
//     })
//   }
// }


// hero height
// jQuery(document).ready(function () {
//   function setHeight() {
//     let windowSize = jQuery(window).width();
//     //let bannerTitleHeight = jQuery('#subpage-hero-section .hero-content .hero-title h1').innerHeight();
//     let bannerMenuHeight = jQuery('header .main-header .desktop-menu-row').innerHeight();
//     let bannerTitleHeight = jQuery('#subpage-hero-section .hero-content .hero-title').innerHeight();
//     let bannerDescHeight = jQuery('#subpage-hero-section .hero-content .hero-desc').innerHeight();
//     let hero = jQuery('#subpage-hero-section .hero-content');
//     let sumHeight = bannerTitleHeight + bannerDescHeight + bannerMenuHeight;



//     if (windowSize >= 981) {
//       hero.css('min-height', sumHeight);
//     } else {
//       hero.css('min-height', 'auto');
//     }
//   }
//   setHeight();
//   jQuery(window).resize(function () {
//     setHeight();
//   });
// });

/*
jQuery(document).ready(function ($) {
  // let bannerTitleHeight = $('#subpage-hero-section .hero-content .hero-title h1').height();
  // let hero = $('#subpage-hero-section .hero-content');

  $('#content_page a').each(function () {
    var a = new RegExp('/' + window.location.host + '/');
    if (!a.test(this.href)) {
      $(this).click(function (event) {
        event.preventDefault();
        event.stopPropagation();
        window.open(this.href, '_blank');
      });
    }
  });
});
*/

// jQuery(document).ready(function () {
//   jQuery(window).scroll(function() {
//     let headerHeight = jQuery('header#header.updated .main-header').height();
//     let win_width = jQuery(this).width();

//     if (jQuery(this).scrollTop() > headerHeight && win_width > 1250 ){
//       jQuery('header#header.updated .main-header .desktop-menu-row').addClass('sticky');
//     } else {
//       jQuery('header#header.updated .main-header .desktop-menu-row').removeClass("sticky");
//     }
//   });
// });

/*//<![CDATA All external links to load in a new tab
jQuery(document).ready(function ($) {
  $('#content_page a').each(function () {
    var a = new RegExp('/' + window.location.host + '/');
    if (!a.test(this.href)) {
      $(this).click(function (event) {
        event.preventDefault();
        event.stopPropagation();
        window.open(this.href, '_blank');
      });
    }
  });
});*/
//]]>

jQuery(document).ready(function ($) {
  /*$('.counter').counterUp({
    delay: 1,
    time: 50
  });*/

  $('.Default').click(function () {
    $(this).toggleClass('active');
  });

  jQuery('#toggle').click(function () {
    jQuery(this).toggleClass('active');
    jQuery('#overlay_menu').toggleClass('open');
  });
  $('body.postid-14994 .sidebar-info h3').replaceWith('<h3>Time For A New IT Company For Your Newmarket Business?</h3>');
  $('body.postid-14994 .sidebar-info h4').replaceWith("<h4>You've tried the rest, now get the best IT support in the Newmarket area.</h4>");
});