jQuery(document).ready(function ($) {
	var sps_myScript = function () {
		if ($('.sp-pcp-container').length > 0) {
			function SwiperSlide(selector, options) {
				if (
					parseInt(sppcp.pcp_swiper_js) === 1 &&
					typeof PCPSwiper !== 'undefined'
				) {
					return new PCPSwiper(selector, options);
				} else {
					return new Swiper(selector, options);
				}
			}
			$('.sp-pcp-container').each(function () {
				var pcp_container = $(this),
					pcp_container_id = pcp_container.attr('id'),
					PCP_Wrapper_ID = '#' + pcp_container_id,
					pc_sid = $(PCP_Wrapper_ID).data('sid'), // The Shortcode ID.
					pcpCarousel = $(
						'#' + pcp_container_id + ' .sp-pcp-carousel'
					),
					pcpAccordion = $(
						'#' + pcp_container_id + ' .sp-pcp-collapse'
					),
					pcpfilter = $(
						'#' + pcp_container_id + '.pcp-filter-wrapper'
					),
					ajaxurl = sppcp.ajaxurl,
					nonce = sppcp.nonce,
					pcpCarouselDir = pcpCarousel.attr('dir'),
					pcpCarouselLayout = pcpCarousel.attr('layout'),
					pcpSwiper,
					pcpCarouselData = pcpCarousel.data('carousel');
				if (pcpCarouselLayout === 'thumbnails_slider') {
					pcpCarouselData = $(
						'#' +
							pcp_container_id +
							' .sp-pcp-carousel.thumbnail-slider-bottom'
					).data('carousel');
				}
				if (pcpCarousel.length > 0) {
					var mobile_land = parseInt(
							pcpCarouselData.responsive.mobile_landscape
						),
						tablet_size = parseInt(
							pcpCarouselData.responsive.tablet
						),
						desktop_size = parseInt(
							pcpCarouselData.responsive.desktop
						),
						lg_desktop_size = parseInt(
							pcpCarouselData.responsive.lg_desktop
						);
				}
				// Product shop page css.
				$(PCP_Wrapper_ID)
					.parents(
						'.woocommerce ul.products, .woocommerce-page ul.products, .dt-css-grid'
					)
					.css('display', 'block');
				// Carousel Init function.
				function pcp_carousel_init() {
					// Carousel ticker mode.
					if (
						pcpCarouselLayout == 'carousel_layout' &&
						pcpCarouselData.mode == 'ticker'
					) {
						item = pcpCarousel.find(
							'.swiper-wrapper .swiper-slide'
						).length;
						pcpSwiper = pcpCarousel
							.find('.swiper-wrapper')
							.bxSlider({
								mode: 'horizontal',
								moveSlides: 1,
								slideMargin: pcpCarouselData.spaceBetween,
								infiniteLoop: pcpCarouselData.loop,
								slideWidth: pcpCarouselData.ticker_width,
								minSlides: pcpCarouselData.slidesPerView.mobile,
								maxSlides:
									pcpCarouselData.slidesPerView.lg_desktop,
								speed: pcpCarouselData.ticker_speed * item,
								ticker: true,
								tickerHover: pcpCarouselData.stop_onHover,
								autoDirection: pcpCarouselDir,
							});
					}

					// Carousel Swiper for Standard & Center mode.
					if (
						(pcpCarouselLayout == 'carousel_layout' &&
							(pcpCarouselData.mode == 'standard' ||
								pcpCarouselData.mode == 'center' ||
								pcpCarouselData.mode == 'multi-rows')) ||
						pcpCarouselLayout == 'slider_layout'
					) {
						var carousel_items = $('#' + pcp_container_id).find(
							'.swiper-slide:not(.swiper-slide-duplicate)'
						).length;
						var dragScrollSize =
							$(
								'#' + pcp_container_id + ' .sp-pcp-carousel'
							).width() / carousel_items;
						var type = {};
						if (pcpCarouselData.bullet_types === 'fraction') {
							type = {
								type: 'fraction',
							};
						}
						if (
							pcpCarouselData.effect == 'fade' ||
							pcpCarouselData.effect == 'cube' ||
							pcpCarouselData.effect == 'flip'
						) {
							if ($(window).width() > lg_desktop_size) {
								slidePerView =
									pcpCarouselData.slidesPerView.lg_desktop;
							} else if ($(window).width() > desktop_size) {
								slidePerView =
									pcpCarouselData.slidesPerView.desktop;
							} else if ($(window).width() > tablet_size) {
								slidePerView =
									pcpCarouselData.slidesPerView.tablet;
							} else if ($(window).width() > 0) {
								slidePerView =
									pcpCarouselData.slidesPerView
										.mobile_landscape;
							}
							$(
								PCP_Wrapper_ID +
									' .sp-pcp-carousel .swiper-wrapper > .sp-smart-pro-item'
							)
								.css('width', 100 / slidePerView + '%')
								.removeClass('swiper-slide');
							var fade_items = $(
								PCP_Wrapper_ID +
									' .sp-pcp-carousel .swiper-wrapper > .sp-smart-pro-item'
							);
							var style =
								pcpCarouselDir == 'rtl'
									? 'marginLeft'
									: 'marginRight';
							for (
								var i = 0;
								i < fade_items.length;
								i += slidePerView
							) {
								fade_items
									.slice(i, i + slidePerView)
									.wrapAll(
										'<div class="swiper-slide"></div>'
									);
								fade_items.eq(i - 1).css(style, 0);
							}
							carousel_items = $('#' + pcp_container_id).find(
								'.swiper-slide:not(.swiper-slide-duplicate)'
							).length;
							dragScrollSize =
								$(
									'#' + pcp_container_id + ' .sp-pcp-carousel'
								).width() / carousel_items;
							pcpSwiper = new PCPSwiper(
								'#' + pcp_container_id + ' .sp-pcp-carousel',
								{
									speed: pcpCarouselData.speed,
									slidesPerView: 1,
									spaceBetween: pcpCarouselData.spaceBetween,
									loop:
										pcpCarouselData.slidesRow.lg_desktop >
											'1' ||
										pcpCarouselData.slidesRow.desktop >
											'1' ||
										pcpCarouselData.slidesRow.tablet >
											'1' ||
										pcpCarouselData.slidesRow
											.mobile_landscape > '1' ||
										pcpCarouselData.slidesRow.mobile > '1'
											? false
											: pcpCarouselData.loop,
									effect: pcpCarouselData.effect,
									slidesPerGroup:
										pcpCarouselData.slideToScroll.mobile,
									preloadImages: false,
									observer: true,
									runCallbacksOnInit: false,
									initialSlide: 0,
									grid: {
										rows: pcpCarouselData.slidesRow.mobile,
										fill: 'row',
									},
									autoHeight:
										pcpCarouselData.slidesRow.lg_desktop >
											'1' ||
										pcpCarouselData.slidesRow.desktop >
											'1' ||
										pcpCarouselData.slidesRow.tablet >
											'1' ||
										pcpCarouselData.slidesRow
											.mobile_landscape > '1' ||
										pcpCarouselData.slidesRow.mobile > '1'
											? false
											: pcpCarouselData.autoHeight,
									simulateTouch:
										pcpCarouselData.simulateTouch,
									allowTouchMove:
										pcpCarouselData.allowTouchMove,
									mousewheel:
										pcpCarouselData.slider_mouse_wheel,
									freeMode: pcpCarouselData.slider_free_mode,
									centeredSlides: pcpCarouselData.center_mode,
									lazy: pcpCarouselData.lazy
										? {
												loadPrevNext: true,
											}
										: false,
									pagination:
										pcpCarouselData.pagination == true &&
										pcpCarouselData.bullet_types !==
											'scrollbar'
											? {
													el:
														'#' +
														pcp_container_id +
														' .pcp-pagination',
													clickable: true,
													dynamicBullets:
														pcpCarouselData.dynamicBullets,
													renderBullet:
														pcpCarouselData.bullet_types ===
														'number'
															? function (
																	index,
																	className
																) {
																	return (
																		'<span class="' +
																		className +
																		'">' +
																		(index +
																			1) +
																		'</span>'
																	);
																}
															: null,
													...type,
													renderFraction:
														pcpCarouselData.bullet_types ===
														'fraction'
															? function (
																	currentClass,
																	totalClass
																) {
																	return (
																		'<div class="pcp-swiper-pagination-fraction"><span class="' +
																		currentClass +
																		'"></span>' +
																		' / ' +
																		'<span class="' +
																		totalClass +
																		'"></span></div>'
																	);
																}
															: null,
												}
											: false,
									autoplay: pcpCarouselData.autoplay
										? {
												delay: pcpCarouselData.autoplay_speed,
												pauseOnMouseEnter:
													pcpCarouselData.stop_onHover,
												disableOnInteraction: false,
											}
										: false,
									navigation:
										pcpCarouselData.navigation == true
											? {
													nextEl:
														'#' +
														pcp_container_id +
														' .pcp-button-next',
													prevEl:
														'#' +
														pcp_container_id +
														' .pcp-button-prev',
												}
											: false,
									fadeEffect: {
										crossFade: true,
									},
									a11y: {
										enabled: pcpCarouselData.enabled,
										prevSlideMessage:
											pcpCarouselData.prevSlideMessage,
										nextSlideMessage:
											pcpCarouselData.nextSlideMessage,
										firstSlideMessage:
											pcpCarouselData.firstSlideMessage,
										lastSlideMessage:
											pcpCarouselData.lastSlideMessage,
										paginationBulletMessage:
											pcpCarouselData.paginationBulletMessage,
									},
									keyboard: {
										enabled:
											pcpCarouselData.keyboard === 'true'
												? true
												: false,
									},
									scrollbar:
										pcpCarouselData.bullet_types ===
										'scrollbar'
											? {
													el:
														'#' +
														pcp_container_id +
														' .pcp-pagination-scrollbar',
													draggable: true,
													dragSize: dragScrollSize,
												}
											: false,
								}
							);
						} else {
							pcpSwiper = new PCPSwiper(
								'#' + pcp_container_id + ' .sp-pcp-carousel',
								{
									speed: pcpCarouselData.speed,
									slidesPerView:
										pcpCarouselData.slidesPerView.mobile,
									spaceBetween: pcpCarouselData.spaceBetween,
									loop:
										pcpCarouselData.slidesRow.lg_desktop >
											'1' ||
										pcpCarouselData.slidesRow.desktop >
											'1' ||
										pcpCarouselData.slidesRow.tablet >
											'1' ||
										pcpCarouselData.slidesRow
											.mobile_landscape > '1' ||
										pcpCarouselData.slidesRow.mobile > '1'
											? false
											: pcpCarouselData.loop,
									effect: pcpCarouselData.effect,
									slidesPerGroup:
										pcpCarouselData.slideToScroll.mobile,
									preloadImages: false,
									observer: true,
									runCallbacksOnInit: false,
									initialSlide: 0,
									autoHeight:
										pcpCarouselData.slidesRow.lg_desktop >
											'1' ||
										pcpCarouselData.slidesRow.desktop >
											'1' ||
										pcpCarouselData.slidesRow.tablet >
											'1' ||
										pcpCarouselData.slidesRow
											.mobile_landscape > '1' ||
										pcpCarouselData.slidesRow.mobile > '1'
											? false
											: pcpCarouselData.autoHeight,
									simulateTouch:
										pcpCarouselData.simulateTouch,
									allowTouchMove:
										pcpCarouselData.allowTouchMove,
									mousewheel:
										pcpCarouselData.slider_mouse_wheel,
									freeMode: pcpCarouselData.slider_free_mode,
									centeredSlides: pcpCarouselData.center_mode,
									lazy: pcpCarouselData.lazy
										? {
												loadPrevNext: true,
											}
										: false,
									grid: {
										rows: pcpCarouselData.slidesRow.mobile,
										fill: 'row',
									},
									pagination:
										pcpCarouselData.pagination == true &&
										pcpCarouselData.bullet_types !==
											'scrollbar'
											? {
													el:
														'#' +
														pcp_container_id +
														' .pcp-pagination',
													clickable: true,
													dynamicBullets:
														pcpCarouselData.dynamicBullets,
													renderBullet:
														pcpCarouselData.bullet_types ===
														'number'
															? function (
																	index,
																	className
																) {
																	return (
																		'<span class="' +
																		className +
																		'">' +
																		(index +
																			1) +
																		'</span>'
																	);
																}
															: null,
													...type,
													renderFraction:
														pcpCarouselData.bullet_types ===
														'fraction'
															? function (
																	currentClass,
																	totalClass
																) {
																	return (
																		'<div class="pcp-swiper-pagination-fraction"><span class="' +
																		currentClass +
																		'"></span>' +
																		' / ' +
																		'<span class="' +
																		totalClass +
																		'"></span></div>'
																	);
																}
															: null,
												}
											: false,
									autoplay: pcpCarouselData.autoplay
										? {
												delay: pcpCarouselData.autoplay_speed,
												pauseOnMouseEnter:
													pcpCarouselData.stop_onHover,
												disableOnInteraction: false,
											}
										: false,
									navigation:
										pcpCarouselData.navigation == true
											? {
													nextEl:
														'#' +
														pcp_container_id +
														' .pcp-button-next',
													prevEl:
														'#' +
														pcp_container_id +
														' .pcp-button-prev',
												}
											: false,
									breakpoints: {
										[mobile_land]: {
											slidesPerView:
												pcpCarouselData.slidesPerView
													.mobile_landscape,
											slidesPerGroup:
												pcpCarouselData.slideToScroll
													.mobile_landscape,
											grid: {
												rows: pcpCarouselData.slidesRow
													.mobile_landscape,
												fill: 'row',
											},
											navigation:
												pcpCarouselData.navigation_mobile ==
												true
													? {
															nextEl:
																'#' +
																pcp_container_id +
																' .pcp-button-next',
															prevEl:
																'#' +
																pcp_container_id +
																' .pcp-button-prev',
														}
													: false,
											pagination:
												pcpCarouselData.pagination_mobile ==
												true
													? {
															el:
																'#' +
																pcp_container_id +
																' .pcp-pagination',
															clickable: true,
															dynamicBullets:
																pcpCarouselData.dynamicBullets,
															renderBullet:
																function (
																	index,
																	className
																) {
																	if (
																		pcpCarouselData.bullet_types ==
																		'number'
																	) {
																		return (
																			'<span class="' +
																			className +
																			'">' +
																			(index +
																				1) +
																			'</span>'
																		);
																	} else {
																		return (
																			'<span class="' +
																			className +
																			'"></span>'
																		);
																	}
																},
														}
													: false,
										},
										[tablet_size]: {
											slidesPerView:
												pcpCarouselData.slidesPerView
													.tablet,
											slidesPerGroup:
												pcpCarouselData.slideToScroll
													.tablet,
											grid: {
												rows: pcpCarouselData.slidesRow
													.tablet,
												fill: 'row',
											},
										},
										[desktop_size]: {
											slidesPerView:
												pcpCarouselData.slidesPerView
													.desktop,
											slidesPerGroup:
												pcpCarouselData.slideToScroll
													.desktop,
											grid: {
												rows: pcpCarouselData.slidesRow
													.desktop,
												fill: 'row',
											},
										},
										[lg_desktop_size]: {
											slidesPerView:
												pcpCarouselData.slidesPerView
													.lg_desktop,
											slidesPerGroup:
												pcpCarouselData.slideToScroll
													.lg_desktop,
											grid: {
												rows: pcpCarouselData.slidesRow
													.lg_desktop,
												fill: 'row',
											},
										},
									},
									fadeEffect: {
										crossFade: true,
									},
									a11y: {
										enabled: pcpCarouselData.enabled,
										prevSlideMessage:
											pcpCarouselData.prevSlideMessage,
										nextSlideMessage:
											pcpCarouselData.nextSlideMessage,
										firstSlideMessage:
											pcpCarouselData.firstSlideMessage,
										lastSlideMessage:
											pcpCarouselData.lastSlideMessage,
										paginationBulletMessage:
											pcpCarouselData.paginationBulletMessage,
									},
									keyboard: {
										enabled:
											pcpCarouselData.keyboard === 'true'
												? true
												: false,
									},
									scrollbar:
										pcpCarouselData.bullet_types ===
										'scrollbar'
											? {
													el:
														'#' +
														pcp_container_id +
														' .pcp-pagination-scrollbar',
													draggable: true,
													dragSize: dragScrollSize,
												}
											: false,
								}
							);
						}

						// Remove the manual autoplay control since we're using pauseOnMouseEnter now
						$(window).on('resize', function () {
							pcpSwiper.update();
						});
						$(window).trigger('resize');
					}
					if (pcpCarouselLayout === 'thumbnails_slider') {
						const carousel_items = $('#' + pcp_container_id).find(
							'.swiper-slide:not(.swiper-slide-duplicate)'
						).length;
						const dragScrollSize =
							$(
								'#' + pcp_container_id + ' .sp-pcp-carousel'
							).width() / carousel_items;

						const type =
							pcpCarouselData.bullet_types === 'fraction'
								? { type: 'fraction' }
								: {};

						const galleryThumbs = new PCPSwiper(
							'#' +
								pcp_container_id +
								' .sp-pcp-carousel.thumbnail-slider-bottom',
							{
								speed: pcpCarouselData.speed,
								slidesPerGroup:
									pcpCarouselData.slideToScroll.mobile,
								slidesPerView:
									pcpCarouselData.slidesPerView.mobile,
								spaceBetween: pcpCarouselData.spaceBetween,
								loop:
									!(
										pcpCarouselData.slidesRow.lg_desktop >
											1 ||
										pcpCarouselData.slidesRow.desktop > 1 ||
										pcpCarouselData.slidesRow.tablet > 1 ||
										pcpCarouselData.slidesRow
											.mobile_landscape > 1 ||
										pcpCarouselData.slidesRow.mobile > 1
									) && pcpCarouselData.loop,
								preloadImages: false,
								observer: true,
								runCallbacksOnInit: false,
								initialSlide: 0,
								autoHeight:
									!(
										pcpCarouselData.slidesRow.lg_desktop >
											1 ||
										pcpCarouselData.slidesRow.desktop > 1 ||
										pcpCarouselData.slidesRow.tablet > 1 ||
										pcpCarouselData.slidesRow
											.mobile_landscape > 1 ||
										pcpCarouselData.slidesRow.mobile > 1
									) && pcpCarouselData.autoHeight,
								simulateTouch: pcpCarouselData.simulateTouch,
								allowTouchMove: pcpCarouselData.allowTouchMove,
								mousewheel: pcpCarouselData.slider_mouse_wheel
									? { forceToAxis: true }
									: false,
								freeMode: pcpCarouselData.slider_free_mode,
								lazy:
									typeof pcpCarouselData.lazy === 'object'
										? pcpCarouselData.lazy
										: { loadPrevNext: true },
								loopedSlides: 20,
								slideToClickedSlide: true,
								direction: pcpCarouselData.direction,

								pagination:
									pcpCarouselData.pagination &&
									pcpCarouselData.bullet_types !== 'scrollbar'
										? {
												el:
													'#' +
													pcp_container_id +
													' .pcp-pagination',
												clickable: true,
												dynamicBullets:
													pcpCarouselData.dynamicBullets,
												renderBullet:
													pcpCarouselData.bullet_types ===
													'number'
														? (index, className) =>
																`<span class="${className}">${index + 1}</span>`
														: '',
												...type,
												renderFraction:
													pcpCarouselData.bullet_types ===
													'fraction'
														? (
																currentClass,
																totalClass
															) =>
																`<div class="pcp-swiper-pagination-fraction"><span class="${currentClass}"></span> / <span class="${totalClass}"></span></div>`
														: '',
											}
										: false,

								autoplay: pcpCarouselData.autoplay
									? {
											delay: pcpCarouselData.autoplay_speed,
											disableOnInteraction: false,
										}
									: false,

								navigation: pcpCarouselData.navigation
									? {
											nextEl:
												'#' +
												pcp_container_id +
												' .pcp-button-next',
											prevEl:
												'#' +
												pcp_container_id +
												' .pcp-button-prev',
										}
									: false,

								breakpoints: {
									[mobile_land]: {
										slidesPerView:
											pcpCarouselData.slidesPerView
												.mobile_landscape,
										slidesPerGroup:
											pcpCarouselData.slideToScroll
												.mobile_landscape,
										navigation:
											pcpCarouselData.navigation_mobile
												? {
														nextEl:
															'#' +
															pcp_container_id +
															' .pcp-button-next',
														prevEl:
															'#' +
															pcp_container_id +
															' .pcp-button-prev',
													}
												: false,
										pagination:
											pcpCarouselData.pagination_mobile
												? {
														el:
															'#' +
															pcp_container_id +
															' .pcp-pagination',
														clickable: true,
														dynamicBullets:
															pcpCarouselData.dynamicBullets,
														renderBullet: (
															index,
															className
														) =>
															pcpCarouselData.bullet_types ===
															'number'
																? `<span class="${className}">${index + 1}</span>`
																: `<span class="${className}"></span>`,
													}
												: false,
									},
									[tablet_size]: {
										slidesPerView:
											pcpCarouselData.slidesPerView
												.tablet,
										slidesPerGroup:
											pcpCarouselData.slideToScroll
												.tablet,
									},
									[desktop_size]: {
										slidesPerView:
											pcpCarouselData.slidesPerView
												.desktop,
										slidesPerGroup:
											pcpCarouselData.slideToScroll
												.desktop,
									},
									[lg_desktop_size]: {
										slidesPerView:
											pcpCarouselData.slidesPerView
												.lg_desktop,
										slidesPerGroup:
											pcpCarouselData.slideToScroll
												.lg_desktop,
									},
								},

								a11y: {
									enabled: pcpCarouselData.enabled,
									prevSlideMessage:
										pcpCarouselData.prevSlideMessage,
									nextSlideMessage:
										pcpCarouselData.nextSlideMessage,
									firstSlideMessage:
										pcpCarouselData.firstSlideMessage,
									lastSlideMessage:
										pcpCarouselData.lastSlideMessage,
									paginationBulletMessage:
										pcpCarouselData.paginationBulletMessage,
								},

								keyboard: {
									enabled:
										pcpCarouselData.keyboard === 'true',
								},

								scrollbar: {
									el:
										'#' +
										pcp_container_id +
										' .pcp-pagination-scrollbar',
									draggable: true,
									dragSize: dragScrollSize,
								},
							}
						);

						const galleryMain = new PCPSwiper(
							'#' +
								pcp_container_id +
								' .sp-pcp-carousel.thumbnail-slider-top',
							{
								//	speed: pcpCarouselData.speed,
								// loop: !(
								// 	pcpCarouselData.slidesRow.lg_desktop > 1 ||
								// 	pcpCarouselData.slidesRow.desktop > 1 ||
								// 	pcpCarouselData.slidesRow.tablet > 1 ||
								// 	pcpCarouselData.slidesRow.mobile_landscape > 1 ||
								// 	pcpCarouselData.slidesRow.mobile > 1
								// ) && pcpCarouselData.loop,
								slidesPerView: 1,
								// effect: pcpCarouselData.effect,
								// loopedSlides: 20,
							}
						);

						// Connect both sliders
						galleryMain.controller.control = galleryThumbs;
						galleryThumbs.controller.control = galleryMain;

						// Stop autoplay if not enabled
						if (!pcpCarouselData.autoplay) {
							galleryThumbs.autoplay?.stop();
							galleryMain.autoplay?.stop();
						}

						// Pause autoplay on hover
						if (
							pcpCarouselData.stop_onHover &&
							pcpCarouselData.autoplay
						) {
							$(pcpCarousel).on({
								mouseenter: () => {
									galleryMain.autoplay.stop();
									galleryThumbs.autoplay.stop();
								},
								mouseleave: () => {
									galleryMain.autoplay.start();
									galleryThumbs.autoplay.start();
								},
							});
						}

						// Handle vertical max height sync
						setTimeout(() => {
							if (pcpCarouselData.direction === 'vertical') {
								let maxHeight = 0;
								$(
									'#' +
										pcp_container_id +
										' .thumbnail-slider-top .swiper-slide img'
								).each(function () {
									const h = $(this).innerHeight();
									if (h > maxHeight) maxHeight = h;
								});
								$(
									'#' +
										pcp_container_id +
										' .thumbnail-slider-top'
								).css('maxHeight', maxHeight);
								$(
									'#' +
										pcp_container_id +
										' .thumbnail-slider-bottom'
								).css('maxHeight', maxHeight);
							}
						}, 300);
					}
				}
				if (pcpCarousel.length > 0) {
					pcp_carousel_init();
				}
				if (
					$(
						'#' +
							pcp_container_id +
							'.sp-pcp-timeline-section.timeline_style_2'
					).length > 0
				) {
					var pcpTimeline = $(
						'#' +
							pcp_container_id +
							' .sps-timeline-swiper-container'
					);
					var pcpTimelineData = pcpTimeline.data('swiper');
					if (pcpTimeline.length > 0) {
						var mobile_land = parseInt(
								pcpTimelineData.responsive.mobile_landscape
							),
							tablet_size = parseInt(
								pcpTimelineData.responsive.tablet
							),
							desktop_size = parseInt(
								pcpTimelineData.responsive.desktop
							),
							lg_desktop_size = parseInt(
								pcpTimelineData.responsive.lg_desktop
							);
					}
					var pcpSwiperTimeline = new PCPSwiper(
						'#' +
							pcp_container_id +
							' .sps-timeline-swiper-container',
						{
							slidesPerView: pcpTimelineData.slidesPerView.mobile,
							grabCursor: true,
							speed: 500,
							direction: 'horizontal',
							spaceBetween: pcpTimelineData.spaceBetween,
							navigation: {
								nextEl:
									'#' +
									pcp_container_id +
									' .sps-timeline-button-next',
								prevEl:
									'#' +
									pcp_container_id +
									' .sps-timeline-button-prev',
							},
							pagination: {
								el:
									'#' +
									pcp_container_id +
									' .swiper-pagination',
								clickable: true,
							},
							breakpoints: {
								[mobile_land]: {
									slidesPerView:
										pcpTimelineData.slidesPerView
											.mobile_landscape,
								},
								[tablet_size]: {
									slidesPerView:
										pcpTimelineData.slidesPerView.tablet,
								},
								[desktop_size]: {
									slidesPerView:
										pcpTimelineData.slidesPerView.desktop,
								},
								[lg_desktop_size]: {
									slidesPerView:
										pcpTimelineData.slidesPerView
											.lg_desktop,
								},
							},
							on: {
								init: function () {
									pcp_lazyload();
								},
								slideChange: function () {
									pcp_lazyload();
								},
							},
						}
					);
				}

				$(
					'.sp-overlay.sp-pcp-post,.sp-pcp-content-box.sp-pcp-post',
					PCP_Wrapper_ID
				).on('mouseover', function () {
					$(this)
						.find('.sp-pcp-post-details.animated:not(.pcp_hover)')
						.addClass('pcp_hover');
				});
				// Start of Accordion scripts.
				if (pcpAccordion.length > 0) {
					var accordion_mode = pcp_container.data('mode');
					var active_accordion = 0;

					if (accordion_mode === 'all-close') {
						active_accordion = false;
					}
					// Collapsible layout.
					pcpAccordion.accordion({
						collapsible: true,
						header: '> div.sp-pcp-single-accordion > .pcp-collapse-header',
						heightStyle: 'content',
						active: active_accordion,
						icons: {
							header: 'fa fa-plus',
							activeHeader: 'fa fa-minus',
						},
						changestart: function (event, ui) {
							var clicked = $(this)
								.find('.ui-state-active')
								.attr('id');
							$('#' + clicked).load('/widgets/' + clicked);
						},
					});
					if (accordion_mode === 'multi-open') {
						pcpAccordion
							.find('.pcp-collapse-header')
							.next()
							.slideDown();
						pcpAccordion
							.find('.pcp-collapse-header .fa')
							.removeClass('fa-plus')
							.addClass('fa-minus');
					}
				}

				/**
				 *  Isotope Filter layout.
				 */
				if (pcpfilter.length > 0) {
					if (pcpfilter.data('grid') == 'masonry') {
						var layoutMode = 'masonry';
					} else {
						var layoutMode = 'fitRows';
					}
					var $grid = $('.sp-pcp-grid', PCP_Wrapper_ID).isotope({
						itemSelector: '.item',
						//layoutMode: 'fitRows'
						layoutMode: layoutMode,
					});
					$grid.imagesLoaded().progress(function () {
						$grid.isotope('layout');
					});

					// This function added for pcp-Lazyload.
					function pcp_lazyload() {
						$is_find = $('.sp-pcp-post-thumb-area img').hasClass(
							'pcp-lazyload'
						);
						if ($is_find) {
							$('img.pcp-lazyload')
								.sps_lazyload({
									effect: 'fadeIn',
									effectTime: 2000,
								})
								.removeClass('pcp-lazyload')
								.addClass('pcp-lazyloaded');
						}
						$grid.isotope('layout');
					}

					// Store filter for each group.
					var filters = {};
					$('.pcp-shuffle-filter .taxonomy-group', PCP_Wrapper_ID).on(
						'change',
						function (event) {
							var $select = $(event.currentTarget);
							// get group key
							var filterGroup = $select.attr('data-filter-group');
							// set filter for group
							filters[filterGroup] = event.target.value;
							// combine filters
							var filterValue = concatValues(filters);
							// set filter for Isotope
							$grid.isotope({ filter: filterValue });
							$grid.on('layoutComplete', function () {
								$(window).trigger('scroll');
							});
						}
					);

					$('.pcp-shuffle-filter', PCP_Wrapper_ID).on(
						'click',
						'.pcp-button',
						function (event) {
							var $button = $(event.currentTarget);
							// get group key
							var $taxonomyGroup =
								$button.parents('.taxonomy-group');
							var filterGroup =
								$taxonomyGroup.attr('data-filter-group');
							// taxonomy = $taxonomyGroup.attr('data-filter-group');
							// set filter for group
							filters[filterGroup] = $button.attr('data-filter');
							//  term_id = $button.attr('data-termid');
							// combine filters
							var filterValue = concatValues(filters);
							// set filter for Isotope
							$grid.isotope({ filter: filterValue });
							$grid.on('layoutComplete', function () {
								$(window).trigger('scroll');
							});
						}
					);
					// Change is-active class on buttons.
					$('.taxonomy-group', PCP_Wrapper_ID).each(
						function (i, taxonomyGroup) {
							var $taxonomyGroup = $(taxonomyGroup);
							var $find_active_button =
								$taxonomyGroup.find('.is-active');
							if ($find_active_button.length == 0) {
								$taxonomyGroup
									.find('button:nth-child(1)')
									.addClass('is-active')
									.click();
							}
							$taxonomyGroup.on(
								'click',
								'button',
								function (event) {
									$taxonomyGroup
										.find('.is-active')
										.removeClass('is-active');
									var $button = $(event.currentTarget);
									$button.addClass('is-active');
								}
							);
						}
					);
					// Flatten object by concatenation values.
					function concatValues(obj) {
						var value = '';
						for (var prop in obj) {
							value += obj[prop];
						}
						return value;
					}
				}

				function pcp_item_same_height() {
					var maxHeight = 0;
					$(PCP_Wrapper_ID + '.pcp_same_height .item').each(
						function () {
							if (
								$(this).find('.sp-pcp-post').height() >
								maxHeight
							) {
								maxHeight = $(this)
									.find('.sp-pcp-post')
									.height();
							}
						}
					);
					$(PCP_Wrapper_ID + '.pcp_same_height .sp-pcp-post').height(
						maxHeight
					);
				}
				if (
					$(PCP_Wrapper_ID + '.pcp_same_height').hasClass(
						'pcp-filter-wrapper'
					)
				) {
					pcp_item_same_height();
				}
				/**
				 * PCP Post Popup.
				 *
				 * Script start to enable Post Ajax Popup.
				 *
				 * @since 2.0.0
				 */
				// Post all Id list.
				function pcp_post_id_list() {
					var list = new Array();
					$(PCP_Wrapper_ID)
						.find('.sp-pcp-post')
						.each(function (index) {
							list.push($(this).data('id'));
						});
					return list;
				}

				// Return array key number of a value.
				function pcp_val2key(val, array) {
					for (var all_key in array) {
						if (array[all_key] == val) {
							return all_key;
						}
					}
					return false;
				}

				// Go to previous array key.
				function pcp_array_key_prev(all_key, pcp_id_length) {
					all_key--;
					if (all_key < 0) {
						all_key = pcp_id_length - 1;
					}
					return all_key;
				}

				// Go to next array key.
				function pcp_array_key_next(all_key, pcp_id_length) {
					all_key++;
					if (all_key > pcp_id_length - 1) {
						all_key = 0;
					}
					return all_key;
				}

				// Change Popup content on next prev button click.
				function ajax_popup_next_prev(id, shortcode_id, url) {
					$.ajax({
						type: 'POST',
						url: url,
						data: {
							post_id: id,
							scode_id: shortcode_id,
							nonce: nonce,
							action: 'pcp_post_popup_next_prev',
						},
						success: function (response) {
							var $data = $(response);
							var $newElements = $data.css({
								opacity: 0,
							});
							$('.popup_ajax_content').html($newElements);
							$newElements.animate({
								opacity: 1,
							});
						},
					});
				}

				// Popup modal on ajax.
				$(function () {
					var pcp_array_key;
					var pcp_id_list;
					var pcp_id_length;
					$(PCP_Wrapper_ID).on(
						'click',
						'.popup-modal',
						function (event) {
							event.preventDefault();
							event.stopPropagation();
							var that = $(this),
								active_id = that
									.parents('.sp-pcp-post')
									.data('id');
							pcp_id_list = pcp_post_id_list();
							pcp_array_key = pcp_val2key(active_id, pcp_id_list);
							pcp_id_length = pcp_id_list.length;
							$.ajax({
								type: 'POST',
								url: ajaxurl,
								data: {
									post_id: active_id,
									scode_id: pc_sid, // The shortcode ID, gets from the container.
									action: 'pcp_post_popup',
									nonce: nonce,
								},
								success: function (response) {
									var $data = $(response);
									var $newElements = $data.css({
										opacity: 0,
									});
									$.magnificPopup.open({
										type: 'inline',
										mainClass:
											'pcp-popup pcp-popup-' + pc_sid,
										showCloseBtn: false,
										closeBtnInshortcode_ide: false,
										enableEscapeall_key: true,
										closeOnBgClick: true,
										items: {
											src: $newElements,
										},
										callbacks: {
											open: function () {
												pcp_id_length =
													pcp_id_list.length;
												if (
													$(
														'.pcp-modal .sp-pcp-section'
													).length > 0
												) {
													sps_myScript();
												}
											},
										},
									});
									$newElements.animate({
										opacity: 1,
									});
								},
							});
						}
					);

					// Popup Next.
					$(document).on(
						'click',
						'.pcp-modal-' + pc_sid + ' .pcp-popup-button-next',
						function (event) {
							event.preventDefault();
							event.stopPropagation();
							pcp_array_key = pcp_array_key_next(
								pcp_array_key,
								pcp_id_length
							);
							ajax_popup_next_prev(
								pcp_id_list[pcp_array_key],
								pc_sid,
								ajaxurl
							);
						}
					);
					// Popup Prev.
					$(document).on(
						'click',
						'.pcp-modal-' + pc_sid + ' .pcp-popup-button-prev',
						function (event) {
							event.preventDefault();
							event.stopPropagation();
							pcp_array_key = pcp_array_key_prev(
								pcp_array_key,
								pcp_id_length
							);
							ajax_popup_next_prev(
								pcp_id_list[pcp_array_key],
								pc_sid,
								ajaxurl
							);
						}
					);
				});
				// Ajax Action for Live filter.
				var keyword = '',
					orderby = '',
					taxonomy = '',
					order = '',
					term_id = '',
					page = '',
					spsp_lang = $(PCP_Wrapper_ID).data('lang');
				current_post_id = $(PCP_Wrapper_ID).data('current_post_id');
				((author_id = ''),
					(custom_field_key = ''),
					(custom_field_value = ''),
					(pcp_hash_url = Array()),
					(pcp_last_filter = ''),
					(custom_fields_array = Array()),
					(is_pagination_url_change = true));
				function pcp_ajax_action(selected_term_list = null) {
					jQuery.ajax({
						url: ajaxurl,
						type: 'POST',
						data: {
							action: 'pcp_post_order',
							id: pc_sid,
							lang: spsp_lang,
							current_post_id,
							order: order,
							keyword: keyword,
							orderby: orderby,
							taxonomy: taxonomy,
							term_id: term_id,
							author_id: author_id,
							nonce: nonce,
							term_list: selected_term_list,
							custom_fields_array: custom_fields_array,
						},
						success: function (data) {
							var $data = $(data);
							var $newElements = $data;

							if ($(PCP_Wrapper_ID).hasClass('pcp-masonry')) {
								var $post_wrapper = $(
									'.sp-pcp-row',
									PCP_Wrapper_ID
								);
								$post_wrapper.masonry('destroy');
								$post_wrapper
									.html($newElements)
									.imagesLoaded(function () {
										$post_wrapper.masonry();
									});
							} else if (
								$(PCP_Wrapper_ID).hasClass('pcp-filter-wrapper')
							) {
								$(
									'.sp-pcp-row, .pcp-timeline-grid, .sp-pcp-collapse, .table-responsive tbody',
									PCP_Wrapper_ID
								).html($newElements);
								$grid
									.append($newElements)
									.isotope('appended', $newElements)
									.imagesLoaded(function () {
										$grid.isotope('layout');
									});
								pcp_item_same_height();
							} else if (pcpCarousel.length > 0) {
								if (pcpCarouselData.mode == 'ticker') {
									pcpSwiper.destroySlider();
									$('.swiper-wrapper', PCP_Wrapper_ID).html(
										$newElements
									);
									pcp_carousel_init();
									pcpSwiper.reloadSlider();
								} else {
									pcpSwiper.destroy(true, true);
									$('.swiper-wrapper', PCP_Wrapper_ID).html(
										$newElements
									);
									pcp_carousel_init();
								}
							} else {
								var $newElements = $data.css({
									opacity: 0,
								});
								$(
									'.sp-pcp-row, .pcp-timeline-grid, .sp-pcp-collapse, .table-responsive tbody',
									PCP_Wrapper_ID
								).html($newElements);
								if (pcpAccordion.length > 0) {
									pcpAccordion.accordion('refresh');
									if (accordion_mode === 'multi-open') {
										pcpAccordion
											.find('.pcp-collapse-header')
											.next()
											.slideDown();
										pcpAccordion
											.find('.pcp-collapse-header .fa')
											.removeClass('fa-plus')
											.addClass('fa-minus');
									}
								}
								var $newElements = $data.css({
									opacity: 1,
								});
							}
							pcp_lazyload();
						},
					});
				}
				// Pagination.
				function pcp_pagination_action(selected_term_list = null) {
					var LoadMoreText = $(
						'.sp-pcp-pagination-data',
						PCP_Wrapper_ID
					).data('loadmoretext');
					var EndingMessage = $(
						'.sp-pcp-pagination-data',
						PCP_Wrapper_ID
					).data('endingtext');
					jQuery.ajax({
						url: ajaxurl,
						type: 'POST',
						data: {
							action: 'post_pagination_bar_mobile',
							id: pc_sid,
							order: order,
							lang: spsp_lang,
							keyword: keyword,
							orderby: orderby,
							taxonomy: taxonomy,
							author_id: author_id,
							term_id: term_id,
							page: page,
							nonce: nonce,
							term_list: selected_term_list,
							custom_fields_array: custom_fields_array,
						},
						success: function (data) {
							var $data = $(data);
							var $newElements = $data;
							$(
								'.pcp-post-pagination.pcp-on-mobile:not(.no_ajax)',
								PCP_Wrapper_ID
							).html($newElements);
							if (
								Pagination_Type == 'infinite_scroll' ||
								Pagination_Type == 'ajax_load_more'
							) {
								$('.pcp-load-more', PCP_Wrapper_ID)
									.removeClass('finished')
									.removeClass('pcp-hide')
									.html(
										'<button class="pcp-load-more-button" pcp-processing="0">' +
											LoadMoreText +
											'</button>'
									);
								if (
									!$('.pcp-post-pagination a', PCP_Wrapper_ID)
										.length
								) {
									$('.pcp-load-more', PCP_Wrapper_ID)
										.show()
										.html(EndingMessage);
								}
							}
							if (Pagination_Type == 'infinite_scroll') {
								$('.pcp-load-more', PCP_Wrapper_ID).addClass(
									'pcp-hide'
								);
							}
						},
					});
					jQuery.ajax({
						url: ajaxurl,
						type: 'POST',
						data: {
							action: 'post_pagination_bar',
							id: pc_sid,
							order: order,
							lang: spsp_lang,
							keyword: keyword,
							orderby: orderby,
							taxonomy: taxonomy,
							author_id: author_id,
							term_id: term_id,
							page: page,
							nonce: nonce,
							term_list: selected_term_list,
							custom_fields_array: custom_fields_array,
						},
						success: function (data) {
							var $data = $(data);
							var $newElements = $data;
							$(
								'.pcp-post-pagination.pcp-on-desktop:not(.no_ajax)',
								PCP_Wrapper_ID
							).html($newElements);
							if (
								Pagination_Type == 'infinite_scroll' ||
								Pagination_Type == 'ajax_load_more'
							) {
								$('.pcp-load-more', PCP_Wrapper_ID)
									.removeClass('finished')
									.removeClass('pcp-hide')
									.html(
										'<button class="pcp-load-more-button" pcp-processing="0">' +
											LoadMoreText +
											'</button>'
									);
							}
							if (Pagination_Type == 'infinite_scroll') {
								$('.pcp-load-more', PCP_Wrapper_ID).addClass(
									'pcp-hide'
								);
							}
							if (
								!$('.pcp-post-pagination a', PCP_Wrapper_ID)
									.length
							) {
								$('.pcp-load-more', PCP_Wrapper_ID)
									.show()
									.html(EndingMessage);
							}
							pcp_lazyload();
						},
					});
				}
				// Live filter button reset on ajax call.
				function pcp_live_filter_reset(selected_term_list = null) {
					jQuery.ajax({
						url: ajaxurl,
						type: 'POST',
						data: {
							action: 'pcp_live_filter_reset',
							id: pc_sid,
							order: order,
							lang: spsp_lang,
							keyword: keyword,
							orderby: orderby,
							taxonomy: taxonomy,
							term_id: term_id,
							author_id: author_id,
							nonce: nonce,
							term_list: selected_term_list,
							last_filter: pcp_last_filter,
							custom_fields_array: custom_fields_array,
						},
						success: function (data) {
							var $data = $(data);
							var $newElements = $data.animate({
								opacity: 0.5,
							});
							$('.pcp-filter-bar', PCP_Wrapper_ID).html(
								$newElements
							);
							custom_field_filter_slider();
							$newElements.animate({
								opacity: 1,
							});
						},
					});
				}
				// Update Hash url array.
				function pcp_hash_update_arr(
					pcp_filter_keyword,
					filter_arr,
					key
				) {
					if (pcp_hash_url.length > 0) {
						pcp_hash_url.forEach(function (row) {
							if (
								$.inArray(
									pcp_filter_keyword,
									row.pcp_filter_keyword
								)
							) {
								row[key] = pcp_filter_keyword;
							} else {
								pcp_hash_url.push(filter_arr);
							}
						});
					} else {
						pcp_hash_url.push(filter_arr);
					}
					return pcp_hash_url;
				}
				// On normal pagination go to current shortcode.
				var url_hash = window.location.search;
				if (url_hash.indexOf('paged') >= 0) {
					var s_id = /paged(\d+)/.exec(url_hash)[1];
					var spscurrent_id = document.getElementById(
						'pcp_wrapper-' + s_id
					);
					spscurrent_id.scrollIntoView();
				}
				// Update url.
				var selected_term_list = Array();
				function pcp_update_url() {
					var p_search = window.location.search;
					if (p_search.indexOf('page_id') >= 0) {
						var pcp_page = /page_id\=(\d+)/.exec(p_search)[1];
						var pcp_url = '?sps&';
						var page_id = 'page_id=' + pcp_page + '&';
					} else {
						var pcp_url = '&';
						var page_id = '';
					}
					if (pcp_hash_url.length > 0) {
						$.map(pcp_hash_url, function (value, index) {
							$.map(value, function (value2, index2) {
								if (
									value2 == 'all' ||
									value2 == 'none' ||
									value2 == '' ||
									value2 == 'page'
								) {
									pcp_url += '';
								} else {
									pcp_url +=
										'pcp_' + index2 + '=' + value2 + '&';
								}
							});
						});
					}
					if (selected_term_list.length > 0) {
						var term_total_length = selected_term_list.length;
						$.map(selected_term_list, function (value, index) {
							if (value.term_id == 'all' || value.term_id == '') {
								pcp_url += '';
							} else {
								if (index == term_total_length - 1) {
									pcp_url +=
										'tx_' +
										value.taxonomy +
										'=' +
										value.term_id +
										'';
								} else {
									pcp_url +=
										'tx_' +
										value.taxonomy +
										'=' +
										value.term_id +
										'&';
								}
							}
						});
					}
					if (custom_fields_array.length > 0) {
						var meta_field_total_length =
							custom_fields_array.length;
						$.map(custom_fields_array, function (value, index) {
							if (
								value.custom_field_value == 'all' ||
								value.custom_field_value == ''
							) {
								pcp_url += '';
							} else {
								pcp_url +=
									'cf' +
									value.custom_field_key +
									'=' +
									value.custom_field_value +
									'&';
							}
						});
					}
					if (
						pcp_hash_url.length < 0 ||
						selected_term_list.length < 0
					) {
						pcp_url = '';
					}
					if (pcp_url.length > 1) {
						var slf = '';
						if (pcp_last_filter.length > 0) {
							var slf = '&slf=' + pcp_last_filter;
						}

						pcp_url =
							'?' + page_id + 'sps=' + pc_sid + slf + pcp_url;
						history.pushState(null, null, encodeURI(pcp_url));
					} else {
						var uri = window.location.toString();
						if (uri.indexOf('?') > 0) {
							var clean_uri = uri.substring(0, uri.indexOf('?'));
							window.history.replaceState(
								{},
								document.title,
								clean_uri
							);
						}
					}
				}
				function custom_field_filter_slider() {
					$(PCP_Wrapper_ID + ' .pcp-custom-field-filter-slider').each(
						function () {
							var _that = $(this);
							var _input = _that.find('.pcp-input');
							var custom_field_key = _input.attr('name');
							var _min = _input.data('min');
							var _crmin = _input.data('crmin');
							var _crmax = _input.data('crmax');
							var _max = _input.data('max');
							_that.find('.pcp-slider').slider({
								// orientation: "horizontal",
								range: true,
								min: _crmin,
								max: _crmax,
								values: [_min, _max],
								slide: function (event, ui) {
									_input.val(
										ui.values[0] + ' - ' + ui.values[1]
									);
								},
								stop: function (event, ui) {
									_input.data('max', ui.values[1]);

									custom_field_value =
										ui.values[0] + '|' + ui.values[1];
									custom_fields_array.push({
										custom_field_key,
										custom_field_value,
									});
									custom_fields_array.map(function (person) {
										if (
											person.custom_field_key ===
											custom_field_key
										) {
											person.custom_field_value =
												custom_field_value;
										}
									});
									custom_fields_array = $.grep(
										custom_fields_array,
										function (e, i) {
											return e.custom_field_value.length;
										}
									);
									custom_fields_array = custom_fields_array
										.map(JSON.stringify)
										.reverse() // convert to JSON string the array content, then reverse it (to check from end to beginning)
										.filter(function (item, index, arr) {
											return (
												arr.indexOf(item, index + 1) ===
												-1
											);
										}) // check if there is any occurrence of the item in whole array
										.reverse()
										.map(JSON.parse);
									pcp_update_url();
									pcp_last_filter = custom_field_key;
									pcp_ajax_action(selected_term_list);
									pcp_live_filter_reset(selected_term_list);
								},
							});
						}
					);
				}
				custom_field_filter_slider();
				// Ajax post search.
				$('input.pcp-search-field', PCP_Wrapper_ID).on(
					'keyup',
					function () {
						var that = $(this);
						keyword = that.val();
						pcp_last_filter = 'keyword';
						var pcp_search_arr = { keyword, keyword };
						pcp_live_filter_reset(selected_term_list);
						pcp_hash_update_arr(keyword, pcp_search_arr, 'keyword');
						pcp_update_url();
						pcp_ajax_action(selected_term_list);
						pcp_pagination_action();
						is_pagination_url_change = false;
						pcp_hash_update_arr('page', { page: '' }, 'page');
						pcp_update_url();
					}
				);

				// Post order by.
				$('.pcp-order-by', PCP_Wrapper_ID).on('change', function () {
					var that;
					$(this)
						.find('option:selected, input:radio:checked')
						.each(function () {
							that = $(this);
							orderby = that.val();
						});
					var orerbyarr = { orderby, orderby };
					pcp_hash_update_arr(orderby, orerbyarr, 'orderby');
					pcp_update_url();
					pcp_ajax_action();
					pcp_pagination_action();
					pcp_hash_update_arr('page', { page: '' }, 'page');
					pcp_update_url();
				});

				function pcp_filter_push(myarr, item) {
					var found = false;
					var i = 0;
					while (i < myarr.length) {
						if (myarr[i] === item) {
							// Do the logic (delete or replace)
							found = true;
							break;
						}
						i++;
					}
					// Add the item
					if (!found) myarr.push(item);
					return myarr;
				}

				// Pre Filter Init.
				var tax_list = Array();
				$('.pcp-filter-by', PCP_Wrapper_ID)
					.find('option:selected, input:radio:checked')
					.each(function () {
						term_id = $(this).val();
						taxonomy = $(this).data('taxonomy');
						var selected_tax_length = selected_term_list.length;
						if (selected_tax_length > 0) {
							var selected_tax =
								selected_term_list[selected_tax_length - 1][
									'taxonomy'
								];
							selected_term_list.map(function (person) {
								if (person.taxonomy === taxonomy) {
									person.term_id = term_id;
								}
							});
							// if ($.inArray(taxonomy, tax_list) == -1) {
							selected_term_list.push({
								taxonomy,
								term_id,
							});
							//  }
							if (
								selected_term_list[selected_tax_length - 1][
									'term_id'
								] == 'all' &&
								selected_tax === taxonomy
							) {
								tax_list = tax_list.filter(function (val) {
									return val !== taxonomy;
								});
							} else {
								tax_list = pcp_filter_push(tax_list, taxonomy);
							}
							selected_term_list = $.grep(
								selected_term_list,
								function (e, i) {
									return e.term_id != 'all';
								}
							);
						} else {
							selected_term_list.push({
								taxonomy,
								term_id,
							});
							selected_term_list = $.grep(
								selected_term_list,
								function (e, i) {
									return e.term_id != 'all';
								}
							);
							tax_list = Array(taxonomy);
						}
					});
				$('.pcp-author-filter', PCP_Wrapper_ID)
					.find('option:selected, input:radio:checked')
					.each(function () {
						that = $(this);
						author_id = that.val();
					});
				$('.pcp-order', PCP_Wrapper_ID)
					.find('option:selected, input:radio:checked')
					.each(function () {
						that = $(this);
						order = $(this).val();
					});
				$('.pcp-order-by', PCP_Wrapper_ID)
					.find('option:selected, input:radio:checked')
					.each(function () {
						that = $(this);
						orderby = that.val();
					});
				$('input.pcp-search-field', PCP_Wrapper_ID).each(function () {
					var that = $(this);
					keyword = that.val();
				});
				$('.pcp-filter-by-checkbox', PCP_Wrapper_ID).each(function () {
					var current_tax = $(this).data('taxonomy');
					var term_ids = '';
					$(this)
						.find(
							"input[name='" + current_tax + "']:checkbox:checked"
						)
						.each(function () {
							term_ids += $(this).val() + ',';
							taxonomy = $(this).data('taxonomy');
						});
					term_id = term_ids.replace(/,(?=\s*$)/, '');
					selected_term_list.map(function (person) {
						if (person.taxonomy === current_tax) {
							person.term_id = term_id;
						}
					});
					selected_term_list.push({
						taxonomy,
						term_id,
					});
				});
				selected_term_list = $.grep(
					selected_term_list,
					function (e, i) {
						return e.term_id.length;
					}
				);
				// Custom field filter.
				$('.pcp-custom-field-filter', PCP_Wrapper_ID).each(function () {
					$(this)
						.find('option:selected, input:radio:checked')
						.each(function () {
							custom_field_key = $(this).attr('name');
							custom_field_value = $(this).val();
							custom_fields_array.map(function (person) {
								if (
									person.custom_field_key === custom_field_key
								) {
									person.custom_field_value =
										custom_field_value;
								}
							});
							custom_fields_array = $.grep(
								custom_fields_array,
								function (e, i) {
									return (
										e.custom_field_value.length ||
										e.custom_field_value != 'all'
									);
								}
							);
							custom_fields_array.push({
								custom_field_key,
								custom_field_value,
							});
						});
				});
				selected_term_list = selected_term_list
					.map(JSON.stringify)
					.reverse() // convert to JSON string the array content, then reverse it (to check from end to beginning)
					.filter(function (item, index, arr) {
						return arr.indexOf(item, index + 1) === -1;
					}) // check if there is any occurence of the item in whole array
					.reverse()
					.map(JSON.parse);
				// Filter by checkbox.
				$(PCP_Wrapper_ID).on(
					'change',
					'.pcp-filter-by-checkbox',
					function (e) {
						e.stopPropagation();
						e.preventDefault();
						$('.pcp-filter-by-checkbox', PCP_Wrapper_ID).each(
							function () {
								var current_tax = $(this).data('taxonomy');
								var term_ids = '';
								$(this)
									.find(
										"input[name='" +
											current_tax +
											"']:checkbox:checked"
									)
									.each(function () {
										term_ids += $(this).val() + ',';
										taxonomy = $(this).data('taxonomy');
									});
								term_id = term_ids.replace(/,(?=\s*$)/, '');
								selected_term_list.map(function (person) {
									if (person.taxonomy === current_tax) {
										person.term_id = term_id;
									}
								});
								selected_term_list.push({
									taxonomy,
									term_id,
								});
							}
						);
						selected_term_list = $.grep(
							selected_term_list,
							function (e, i) {
								return e.term_id.length;
							}
						);
						selected_term_list = selected_term_list
							.map(JSON.stringify)
							.reverse() // convert to JSON string the array content, then reverse it (to check from end to beginning)
							.filter(function (item, index, arr) {
								return arr.indexOf(item, index + 1) === -1;
							}) // check if there is any occurence of the item in whole array
							.reverse()
							.map(JSON.parse);
						var term_ids = '';
						$(this)
							.find('input:checkbox:checked')
							.each(function () {
								term_ids += $(this).val() + ',';
								taxonomy = $(this).data('taxonomy');
							});
						taxonomy = $(this).data('taxonomy');
						term_id = term_ids.replace(/,(?=\s*$)/, '');
						if (term_id.length > 0) {
							pcp_last_filter = taxonomy;
						} else {
							pcp_last_filter = pcp_last_filter;
						}
						pcp_hash_update_arr('page', { page: '' }, 'page');
						pcp_update_url();
						pcp_live_filter_reset(selected_term_list);
						pcp_ajax_action(selected_term_list);
						pcp_pagination_action(selected_term_list);
					}
				);

				// Filter by custom field.
				$(PCP_Wrapper_ID).on(
					'change',
					'.pcp-custom-field-filter',
					function (e) {
						e.stopPropagation();
						e.preventDefault();
						$('.pcp-custom-field-filter', PCP_Wrapper_ID).each(
							function () {
								$(this)
									.find(
										'option:selected, input:radio:checked'
									)
									.each(function () {
										custom_field_key = $(this).attr('name');
										custom_field_value = $(this).val();
										custom_fields_array.map(
											function (person) {
												if (
													person.custom_field_key ===
													custom_field_key
												) {
													person.custom_field_value =
														custom_field_value;
												}
											}
										);
										custom_fields_array = $.grep(
											custom_fields_array,
											function (e, i) {
												return (
													e.custom_field_value
														.length ||
													e.custom_field_value !=
														'all'
												);
											}
										);
										custom_fields_array.push({
											custom_field_key,
											custom_field_value,
										});
									});
							}
						);
						pcp_last_filter = $(this)
							.find('option:selected, input:radio:checked')
							.attr('name');
						custom_fields_array = $.grep(
							custom_fields_array,
							function (e, i) {
								return e.custom_field_value != 'all';
							}
						);
						custom_fields_array = custom_fields_array
							.map(JSON.stringify)
							.reverse() // convert to JSON string the array content, then reverse it (to check from end to beginning)
							.filter(function (item, index, arr) {
								return arr.indexOf(item, index + 1) === -1;
							}) // check if there is any occurence of the item in whole array
							.reverse()
							.map(JSON.parse);
						pcp_ajax_action(selected_term_list);
						pcp_pagination_action(selected_term_list);
						pcp_live_filter_reset(selected_term_list);
						pcp_update_url();
					}
				);
				// Filter by checkbox custom field.
				$(PCP_Wrapper_ID).on(
					'change',
					'.pcp-custom-field-filter-checkbox',
					function (e) {
						e.stopPropagation();
						e.preventDefault();
						$(
							'.pcp-custom-field-filter-checkbox',
							PCP_Wrapper_ID
						).each(function () {
							var custom_field_key = $(this)
								.find('input:checkbox')
								.attr('name');
							var custom_field_value = '';
							$(this)
								.find(
									"input[name='" +
										custom_field_key +
										"']:checkbox:checked"
								)
								.each(function () {
									custom_field_key = $(this).attr('name');
									custom_field_value += $(this).val() + ',';
								});
							custom_field_value = custom_field_value.replace(
								/,(?=\s*$)/,
								''
							);
							custom_fields_array.push({
								custom_field_key,
								custom_field_value,
							});
							custom_fields_array.map(function (person) {
								if (
									person.custom_field_key === custom_field_key
								) {
									person.custom_field_value =
										custom_field_value;
								}
							});
							custom_fields_array = $.grep(
								custom_fields_array,
								function (e, i) {
									return (
										e.custom_field_value.length ||
										e.custom_field_value != 'all'
									);
								}
							);
						});
						pcp_last_filter = $(this)
							.find('input:checkbox:checked')
							.attr('name');
						custom_fields_array = custom_fields_array
							.map(JSON.stringify)
							.reverse() // convert to JSON string the array content, then reverse it (to check from end to beginning)
							.filter(function (item, index, arr) {
								return arr.indexOf(item, index + 1) === -1;
							}) // check if there is any occurrence of the item in whole array
							.reverse()
							.map(JSON.parse);
						pcp_ajax_action(selected_term_list);
						pcp_pagination_action(selected_term_list);
						pcp_live_filter_reset(selected_term_list);
						pcp_update_url();
					}
				);
				// Filter by taxonomy.
				$(PCP_Wrapper_ID).on('change', '.pcp-filter-by', function (e) {
					e.stopPropagation();
					e.preventDefault();
					$(this)
						.find('option:selected, input:radio:checked')
						.each(function () {
							term_id = $(this).val();
							taxonomy = $(this).data('taxonomy');
							var selected_tax_length = selected_term_list.length;
							if (selected_tax_length > 0) {
								var selected_tax =
									selected_term_list[selected_tax_length - 1][
										'taxonomy'
									];
								selected_term_list.map(function (person) {
									if (person.taxonomy === taxonomy) {
										person.term_id = term_id;
									}
								});
								// if ($.inArray(taxonomy, tax_list) == -1) {
								selected_term_list.push({
									taxonomy,
									term_id,
								});
								//  }
								if (
									selected_term_list[selected_tax_length - 1][
										'term_id'
									] == 'all' &&
									selected_tax === taxonomy
								) {
									tax_list = tax_list.filter(function (val) {
										return val !== taxonomy;
									});
								} else {
									tax_list = pcp_filter_push(
										tax_list,
										taxonomy
									);
								}
								selected_term_list = $.grep(
									selected_term_list,
									function (e, i) {
										return e.term_id != 'all';
									}
								);
							} else {
								selected_term_list.push({
									taxonomy,
									term_id,
								});
								tax_list = Array(taxonomy);
							}
						});
					if (term_id == 'all') {
						pcp_last_filter = pcp_last_filter;
					} else {
						pcp_last_filter = taxonomy;
					}
					selected_term_list = selected_term_list
						.map(JSON.stringify)
						.reverse()
						.filter(function (item, index, selected_term_list) {
							return (
								selected_term_list.indexOf(item, index + 1) ===
								-1
							);
						})
						.reverse()
						.map(JSON.parse);
					pcp_hash_update_arr('page', { page: '' }, 'page');
					pcp_update_url();
					// if ($('.pcp-filter-by', PCP_Wrapper_ID).length > 1) {
					pcp_live_filter_reset(selected_term_list);
					//}
					pcp_ajax_action(selected_term_list);
					pcp_pagination_action(selected_term_list);
				});
				// Author filter.
				$(PCP_Wrapper_ID).on(
					'change',
					'.pcp-author-filter',
					function (e) {
						var that;
						$(this)
							.find('option:selected, input:radio:checked')
							.each(function () {
								that = $(this);
								author_id = that.val();
							});
						var author_arr = { author_id, author_id };
						if (author_id == 'all') {
							pcp_last_filter = pcp_last_filter;
						} else {
							pcp_last_filter = 'author_id';
						}
						pcp_hash_update_arr(author_id, author_arr, 'author_id');
						pcp_update_url();
						pcp_live_filter_reset(selected_term_list);
						pcp_ajax_action();
						pcp_pagination_action();
					}
				);

				// Post order asc/dsc.
				$(PCP_Wrapper_ID).on('change', '.pcp-order', function (e) {
					var that;
					$(this)
						.find('option:selected, input:radio:checked')
						.each(function () {
							that = $(this);
							order = $(this).val();
						});
					var order_arr = { order, order };
					pcp_hash_update_arr(order, order_arr, 'order');
					pcp_update_url();
					pcp_ajax_action();
					pcp_pagination_action();
					pcp_hash_update_arr('page', { page: '' }, 'page');
					pcp_update_url();
				});
				/**
				 * Grid masonry.
				 */
				if ($(PCP_Wrapper_ID).hasClass('pcp-masonry')) {
					var $post_wrapper = $('.sp-pcp-row', PCP_Wrapper_ID);
					$post_wrapper.imagesLoaded(function () {
						$post_wrapper.masonry(/* {
				itemSelector: 'div[class*=sp-pcp-col-]',
				//fitWidth: true,
				percentPosition: true
			  } */);
					});
				}

				/**
				 * The Pagination effects.
				 *
				 * The effects for pagination to work for both mobile and other screens.
				 */
				var Pagination_Type = $(PCP_Wrapper_ID).data('pagination');
				if ($(window).width() <= 480) {
					var Pagination_Type =
						$(PCP_Wrapper_ID).data('pagination_mobile');
				}
				// Ajax number pagination
				if (Pagination_Type == 'ajax_pagination') {
					$(PCP_Wrapper_ID).on(
						'click',
						'.pcp-post-pagination a',
						function (e) {
							e.preventDefault();
							var that = $(this);
							var totalPage = $(
									'.pcp-post-pagination.pcp-on-desktop a:not(.pcp_next, .pcp_prev)',
									PCP_Wrapper_ID
								).length,
								currentPage = parseInt(
									$(
										'.pcp-post-pagination.pcp-on-desktop .active:not(.pcp_next, .pcp_prev)',
										PCP_Wrapper_ID
									).data('page')
								);
							if ($(window).width() <= 480) {
								var totalPage = $(
										'.pcp-post-pagination.pcp-on-mobile a:not(.pcp_next, .pcp_prev)',
										PCP_Wrapper_ID
									).length,
									currentPage = parseInt(
										$(
											'.pcp-post-pagination.pcp-on-mobile .active:not(.pcp_next, .pcp_prev)',
											PCP_Wrapper_ID
										).data('page')
									);
							}
							page = parseInt(that.data('page'));
							if (that.hasClass('pcp_next')) {
								if (totalPage > currentPage) {
									var page = currentPage + 1;
								} else {
									return;
								}
							}
							if (that.hasClass('pcp_prev')) {
								if (currentPage > 1) {
									var page = currentPage - 1;
								} else {
									return;
								}
							}
							var pcp_paged = { page, page };
							$.ajax({
								url: ajaxurl,
								type: 'post',
								data: {
									page: page,
									id: pc_sid,
									action: 'post_grid_ajax',
									order: order,
									lang: spsp_lang,
									keyword: keyword,
									orderby: orderby,
									taxonomy: taxonomy,
									term_id: term_id,
									author_id: author_id,
									term_list: selected_term_list,
									custom_fields_array: custom_fields_array,
									nonce: nonce,
								},
								error: function (response) {
									//  console.log(response)
								},
								success: function (response) {
									var $data = $(response);
									var $newElements = $data;
									if (
										$(PCP_Wrapper_ID).hasClass(
											'pcp-masonry'
										)
									) {
										var $post_wrapper = $(
											'.sp-pcp-row',
											PCP_Wrapper_ID
										);
										$post_wrapper.masonry('destroy');
										$post_wrapper
											.html($newElements)
											.imagesLoaded(function () {
												$post_wrapper.masonry();
											});
									} else if (
										$(PCP_Wrapper_ID).hasClass(
											'pcp-filter-wrapper'
										)
									) {
										$grid
											.html($newElements)
											.isotope('appended', $newElements)
											.imagesLoaded(function () {
												$grid.isotope('layout');
											});
										pcp_item_same_height();
									} else {
										$(
											'.sp-pcp-row, .pcp-timeline-grid, .sp-pcp-collapse, .table-responsive tbody',
											PCP_Wrapper_ID
										).html($newElements);
										if (pcpAccordion.length > 0) {
											pcpAccordion.accordion('refresh');
											if (
												accordion_mode === 'multi-open'
											) {
												pcpAccordion
													.find(
														'.pcp-collapse-header'
													)
													.next()
													.slideDown();
												pcpAccordion
													.find(
														'.pcp-collapse-header .fa'
													)
													.removeClass('fa-plus')
													.addClass('fa-minus');
											}
										}
										var $newElements = $data.css({
											opacity: 1,
										});
									}
									$(
										'.page-numbers',
										PCP_Wrapper_ID
									).removeClass('active');
									$('.page-numbers', PCP_Wrapper_ID).each(
										function () {
											// if (parseInt($('.pcp-post-pagination a').data('page')) === page) {
											$(
												'.pcp-post-pagination a[data-page=' +
													page +
													']',
												PCP_Wrapper_ID
											).addClass('active');
											// }
										}
									);
									$('.pcp_next', PCP_Wrapper_ID).removeClass(
										'active'
									);
									$('.pcp_prev', PCP_Wrapper_ID).removeClass(
										'active'
									);
									$(
										'.pcp-post-pagination a.active',
										PCP_Wrapper_ID
									).each(function () {
										if (
											parseInt($(this).data('page')) ===
											totalPage
										) {
											$(
												'.pcp_next',
												PCP_Wrapper_ID
											).addClass('active');
										}
										if (
											parseInt($(this).data('page')) === 1
										) {
											$(
												'.pcp_prev',
												PCP_Wrapper_ID
											).addClass('active');
										}
									});
									if (pcpAccordion.length > 0) {
										pcpAccordion.accordion('refresh');
										if (accordion_mode === 'multi-open') {
											pcpAccordion
												.find('.pcp-collapse-header')
												.next()
												.slideDown();
											pcpAccordion
												.find(
													'.pcp-collapse-header .fa'
												)
												.removeClass('fa-plus')
												.addClass('fa-minus');
										}
									}
									$newElements.animate({
										opacity: 1,
									});
									pcp_lazyload();
									// Ajax Number pagination go to current shortcode top.
									var url_hash = window.location.search;
									if (url_hash.indexOf('pcp_page') >= 0) {
										var current_screen_id =
											document.querySelector(
												PCP_Wrapper_ID
											);
										current_screen_id.scrollIntoView();
									}
								},
							});
							pcp_hash_update_arr(page, pcp_paged, 'page');
							pcp_update_url();
						}
					);
				}

				/**
				 * Ajax load on click and Infinite scroll.
				 */
				if (
					Pagination_Type == 'infinite_scroll' ||
					Pagination_Type == 'ajax_load_more'
				) {
					$(PCP_Wrapper_ID).each(function () {
						var EndingMessage = $(this)
							.find('.sp-pcp-pagination-data')
							.data('endingtext');
						var LoadMoreText = $(this)
							.find('.sp-pcp-pagination-data')
							.data('loadmoretext');
						if (
							!$(this)
								.find('.pcp-load-more')
								.hasClass('pcp-load-more-initialize')
						) {
							if (
								$('.pcp-post-pagination a', PCP_Wrapper_ID)
									.length
							) {
								$('.pcp-post-pagination', PCP_Wrapper_ID)
									.eq(0)
									.before(
										'<div class="pcp-load-more"><button class="pcp-load-more-button" pcp-processing="0">' +
											LoadMoreText +
											'</button></div>'
									);
							}
							if (Pagination_Type == 'infinite_scroll') {
								$('.pcp-load-more', PCP_Wrapper_ID).addClass(
									'pcp-hide'
								);
							}
							$('.pcp-post-pagination', PCP_Wrapper_ID).addClass(
								'pcp-hide'
							);
							$(
								'.sp-pcp-row div[class*=sp-pcp-col-]',
								PCP_Wrapper_ID
							).addClass('pcp-added');
							$(this)
								.find('.pcp-load-more')
								.addClass('pcp-load-more-initialize');
							$(this).on(
								'click',
								'.pcp-load-more button',
								function (e) {
									e.preventDefault();
									if (
										$(
											'.pcp-post-pagination a.active:not(.pcp_next, .pcp_prev)',
											PCP_Wrapper_ID
										).length
									) {
										$('.pcp-load-more button').attr(
											'pcp-processing',
											1
										);
										var current_page = parseInt(
											$(
												'.pcp-post-pagination a.active:not(.pcp_next, .pcp_prev)',
												PCP_Wrapper_ID
											).data('page')
										);
										current_page = current_page + 1;
										$(
											'.pcp-load-more',
											PCP_Wrapper_ID
										).hide();
										$(
											'.pcp-post-pagination',
											PCP_Wrapper_ID
										)
											.eq(0)
											.before(
												'<div class="pcp-infinite-scroll-loader"><svg width="44" height="44" viewBox="0 0 44 44" xmlns="http://www.w3.org/2000/svg" stroke="#444"><g fill="none" fill-rule="evenodd" stroke-width="2"><circle cx="22" cy="22" r="1"><animate attributeName="r" begin="0s" dur="1.8s" values="1; 20" calcMode="spline" keyTimes="0; 1" keySplines="0.165, 0.84, 0.44, 1" repeatCount="indefinite" /> <animate attributeName="stroke-opacity" begin="0s" dur="1.8s" values="1; 0" calcMode="spline" keyTimes="0; 1" keySplines="0.3, 0.61, 0.355, 1" repeatCount="indefinite" /> </circle> <circle cx="22" cy="22" r="1"> <animate attributeName="r" begin="-0.9s" dur="1.8s" values="1; 20" calcMode="spline" keyTimes="0; 1" keySplines="0.165, 0.84, 0.44, 1" repeatCount="indefinite" /> <animate attributeName="stroke-opacity" begin="-0.9s" dur="1.8s" values="1; 0" calcMode="spline" keyTimes="0; 1" keySplines="0.3, 0.61, 0.355, 1" repeatCount="indefinite"/></circle></g></svg></div>'
											);
										totalPage = $(
											'.pcp-post-pagination.pcp-on-desktop.infinite_scroll a:not(.pcp_next, .pcp_prev), .pcp-post-pagination.pcp-on-desktop.ajax_load_more a:not(.pcp_next, .pcp_prev)',
											PCP_Wrapper_ID
										).length;
										if ($(window).width() <= 480) {
											totalPage = $(
												'.pcp-post-pagination.pcp-on-mobile.infinite_scroll a:not(.pcp_next, .pcp_prev), .pcp-post-pagination.ajax_load_more.pcp-on-mobile  a:not(.pcp_next, .pcp_prev)',
												PCP_Wrapper_ID
											).length;
										}
										page = current_page;
										$.ajax({
											url: ajaxurl,
											type: 'post',
											data: {
												page: page,
												id: pc_sid,
												action: 'post_grid_ajax',
												order: order,
												lang: spsp_lang,
												keyword: keyword,
												orderby: orderby,
												taxonomy: taxonomy,
												term_id: term_id,
												author_id: author_id,
												term_list: selected_term_list,
												custom_fields_array:
													custom_fields_array,
												nonce: nonce,
											},
											error: function (response) {
												// console.log(response)
											},
											success: function (response) {
												var $data = $(response);
												var $newElements = $data;
												if (
													$(PCP_Wrapper_ID).hasClass(
														'pcp-masonry'
													)
												) {
													var $post_wrapper = $(
														'.sp-pcp-row',
														PCP_Wrapper_ID
													);
													$post_wrapper.masonry(
														'destroy'
													);
													$post_wrapper
														.append($newElements)
														.imagesLoaded(
															function () {
																$post_wrapper.masonry();
															}
														);
												} else if (
													$(PCP_Wrapper_ID).hasClass(
														'pcp-filter-wrapper'
													)
												) {
													$grid
														.append($newElements)
														.isotope(
															'appended',
															$newElements
														)
														.imagesLoaded(
															function () {
																$grid.isotope(
																	'layout'
																);
															}
														);
													pcp_item_same_height();
												} else {
													var $newElements =
														$data.css({
															opacity: 0,
														});
													$(
														'.sp-pcp-row, .pcp-timeline-grid, .sp-pcp-collapse, .table-responsive tbody',
														PCP_Wrapper_ID
													).append($newElements);
													if (
														pcpAccordion.length > 0
													) {
														pcpAccordion.accordion(
															'refresh'
														);
														if (
															accordion_mode ===
															'multi-open'
														) {
															pcpAccordion
																.find(
																	'.pcp-collapse-header'
																)
																.next()
																.slideDown();
															pcpAccordion
																.find(
																	'.pcp-collapse-header .fa'
																)
																.removeClass(
																	'fa-plus'
																)
																.addClass(
																	'fa-minus'
																);
														}
													}
													var $newElements =
														$data.css({
															opacity: 1,
														});
												}
												$(
													'.page-numbers',
													PCP_Wrapper_ID
												).removeClass('active');
												$(
													'.page-numbers',
													PCP_Wrapper_ID
												).each(function () {
													$(
														'.pcp-post-pagination a[data-page=' +
															page +
															']',
														PCP_Wrapper_ID
													).addClass('active');
												});
												$(
													'.pcp-infinite-scroll-loader',
													PCP_Wrapper_ID
												).remove();
												if (
													Pagination_Type ==
													'ajax_load_more'
												) {
													$('.pcp-load-more').show();
												}
												$('.pcp-load-more button').attr(
													'pcp-processing',
													0
												);
												$(
													'.sp-pcp-row div[class*=sp-pcp-col-]',
													PCP_Wrapper_ID
												)
													.not('.pcp-added')
													.addClass(
														'animated pcpFadeIn'
													)
													.one(
														'webkitAnimationEnd animationEnd',
														function () {
															$(this)
																.removeClass(
																	'animated pcpFadeIn'
																)
																.addClass(
																	'pcp-added'
																);
														}
													);
												if (totalPage == current_page) {
													$(
														'.pcp-load-more',
														PCP_Wrapper_ID
													)
														.addClass('finished')
														.removeClass(
															'pcp-hide'
														);
													$(
														'.pcp-load-more',
														PCP_Wrapper_ID
													)
														.show()
														.html(EndingMessage);
												}
												pcp_lazyload();
											},
										});
									} else {
										$('.pcp-load-more', PCP_Wrapper_ID)
											.addClass('finished')
											.removeClass('pcp-hide');
										$('.pcp-load-more', PCP_Wrapper_ID)
											.show()
											.html(EndingMessage);
									}
								}
							);
						}
						if (Pagination_Type == 'infinite_scroll') {
							bufferBefore = Math.abs(20);
							$(window).scroll(function () {
								if (
									$(
										'.sp-pcp-row, .sp-pcp-collapse, .pcp-timeline-grid, .table-responsive tbody',
										PCP_Wrapper_ID
									).length
								) {
									var TopAndContent =
										$(
											'.sp-pcp-row, .sp-pcp-collapse, .pcp-timeline-grid, .table-responsive tbody',
											PCP_Wrapper_ID
										).offset().top +
										$(
											'.sp-pcp-row, .sp-pcp-collapse, .pcp-timeline-grid, .table-responsive tbody',
											PCP_Wrapper_ID
										).outerHeight();
									var areaLeft =
										TopAndContent - $(window).scrollTop();
									if (
										areaLeft - bufferBefore <
										$(window).height()
									) {
										if (
											$(
												'.pcp-load-more button',
												PCP_Wrapper_ID
											).attr('pcp-processing') == 0
										) {
											$(
												'.pcp-load-more button',
												PCP_Wrapper_ID
											).trigger('click');
										}
									}
								}
							});
						}
					});
				}

				// Glossary layout scripts.
				if ($(`#${pcp_container_id}.sps-glossary-layout`).length > 0) {
					const $container = $(`#${pcp_container_id}`);
					const $glossaryGroups = $container.find(
						'.sps-glossary-items-group'
					);
					const $filterButtons = $container.find(
						'.sps-az-filter-button button'
					);
					const animationDuration = 400; // Animation duration in milliseconds

					// Show all posts by default
					$glossaryGroups.show();

					// Disable filter links with no associated posts
					$filterButtons.each(function () {
						let letter = $(this).data('letter');
						if (
							letter !== 'all' &&
							$container.find(
								`.sps-glossary-items-group.sps-gls-${letter}`
							).length === 0
						) {
							$(this)
								.addClass('sps-glossary-disabled')
								.attr(
									'title',
									'No posts available for this letter'
								)
								.attr('aria-disabled', 'true'); // Improve accessibility
						}
					});

					// Handle filter button clicks
					$filterButtons.on('click', function (event) {
						event.preventDefault();

						// Do not proceed if the button is disabled
						if ($(this).hasClass('sps-glossary-disabled')) return;

						// Update active class for the filter buttons
						$filterButtons.removeClass('active');
						$(this).addClass('active');

						// Filter posts based on the selected letter
						let letter = $(this).data('letter');
						filterPosts(letter);
					});

					/**
					 * Function to filter glossary posts based on the selected letter.
					 * @param {string} letter - The letter to filter posts by.
					 */
					function filterPosts(letter) {
						if (letter === 'all') {
							// Show all posts with a fade-in effect
							$glossaryGroups
								.stop(true, true)
								.fadeIn(animationDuration);
						} else {
							// Hide all groups directly and then fade in the matching group
							$glossaryGroups.hide();
							$container
								.find(
									`.sps-glossary-items-group.sps-gls-${letter}`
								)
								.stop(true, true)
								.fadeIn(animationDuration);
						}
					}
				}

				/* This code added for divi-builder ticker mode compatibility. */
				if (
					pcpCarousel.length > 0 &&
					pcpCarouselLayout == 'carousel_layout' &&
					pcpCarouselData.mode == 'ticker'
				) {
					$('.sp-pcp-carousel img').removeAttr('loading');
					$(window).on('load', function () {
						$('.sp-pcp-carousel').each(function () {
							var thisdfd = $(this);
							var thisCSS = thisdfd.attr('style');
							$(this).removeAttr('style');
							setTimeout(function () {
								thisdfd.attr('style', thisCSS);
							}, 0);
						});
					});
				}
				/* Preloader js */
				$(document).ready(function () {
					$('.pcp-preloader', PCP_Wrapper_ID).css({
						backgroundImage: 'none',
						visibility: 'hidden',
					});
				});
				// This function added for pcp-Lazyload.
				function pcp_lazyload() {
					$is_find = $('.sp-pcp-post-thumb-area img').hasClass(
						'pcp-lazyload'
					);
					if ($is_find) {
						$('img.pcp-lazyload')
							.sps_lazyload({
								effect: 'fadeIn',
								effectTime: 2000,
							})
							.removeClass('pcp-lazyload')
							.addClass('pcp-lazyloaded');
					}
				}
				pcp_lazyload();

				if ($('.pcp-copy-url', PCP_Wrapper_ID).length > 0) {
					$('.pcp-copy', PCP_Wrapper_ID).click(function (event) {
						event.preventDefault(); // Prevent default behavior (i.e., redirecting)

						var dataUrl = $(this).attr('data_url'); // Get the value of the 'data_url' attribute

						// Create a temporary input element
						var tempInput = $('<input>');
						$('body').append(tempInput);

						// Set the value of the input to the dataUrl
						tempInput.val(dataUrl);

						// Select the input content
						tempInput.select();

						// Copy the text
						document.execCommand('copy');

						// Remove the temporary input
						tempInput.remove();

						// Display the copy popup
						var copyPopup = $(this).find('.post-url-copy-popup');
						copyPopup.css({
							display: 'block',
							top: '-40px',
							left: '0px',
						});

						// Hide the popup after a short delay
						setTimeout(function () {
							copyPopup.css('display', 'none');
						}, 1000); // Adjust the delay as needed
					});
				}
			});
		}

		// Prevent default behavior for the .pcp-readmore-link-none class.
		$('body').on(
			'click',
			'.pcp-readmore-link-none, .pcp-title-link-none',
			function (e) {
				e.preventDefault();
				e.stopPropagation();
			}
		);
	};
	sps_myScript();
});
