(function () {
	'use strict';

	var ajaxUrl = (window.rsmContentWidgets && window.rsmContentWidgets.ajaxUrl) || '/wp-admin/admin-ajax.php';

	function setSlide(root, index) {
		var slides = root.querySelectorAll('[data-rsmspark-cw-carousel-slide]');
		var dots = root.querySelectorAll('[data-rsmspark-cw-carousel-dot]');
		slides.forEach(function (slide) {
			var active = slide.getAttribute('data-rsmspark-cw-carousel-slide') === String(index);
			slide.classList.toggle('is-active', active);
		});
		dots.forEach(function (dot) {
			var active = dot.getAttribute('data-rsmspark-cw-carousel-dot') === String(index);
			dot.classList.toggle('is-active', active);
		});
		root.setAttribute('data-active-slide', String(index));
	}

	function initCarousel(root) {
		var slides = root.querySelectorAll('[data-rsmspark-cw-carousel-slide]');
		if (!slides.length) {
			return;
		}

		var timer = null;
		var reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

		function syncGroup(index, skipFrom) {
			var group = root.getAttribute('data-sync-group');
			if (!group) {
				return;
			}
			document.querySelectorAll('[data-rsmspark-cw-carousel][data-sync-group="' + group + '"]').forEach(function (other) {
				if (other === root || other === skipFrom) {
					return;
				}
				if (typeof other._rsmCwCarouselGoTo === 'function') {
					other._rsmCwCarouselGoTo(index, root);
				}
			});
		}

		function goToSlide(index, syncSource) {
			var normalized = ((index % slides.length) + slides.length) % slides.length;
			setSlide(root, normalized);
			if (!syncSource) {
				syncGroup(normalized, null);
			}
		}

		root._rsmCwCarouselGoTo = goToSlide;

		function go(delta) {
			var current = parseInt(root.getAttribute('data-active-slide'), 10) || 0;
			goToSlide(current + delta, null);
		}

		root.setAttribute('tabindex', '0');

		var prev = root.querySelector('[data-rsmspark-cw-carousel-prev]');
		var next = root.querySelector('[data-rsmspark-cw-carousel-next]');
		if (prev) {
			prev.addEventListener('click', function () { go(-1); });
		}
		if (next) {
			next.addEventListener('click', function () { go(1); });
		}

		root.querySelectorAll('[data-rsmspark-cw-carousel-dot]').forEach(function (dot) {
			dot.addEventListener('click', function () {
				var index = parseInt(dot.getAttribute('data-rsmspark-cw-carousel-dot'), 10) || 0;
				goToSlide(index, null);
			});
		});

		root.addEventListener('keydown', function (event) {
			if (event.key === 'ArrowLeft') {
				event.preventDefault();
				go(-1);
			} else if (event.key === 'ArrowRight') {
				event.preventDefault();
				go(1);
			}
		});

		if (root.getAttribute('data-autoplay') === '1' && !reducedMotion) {
			var speed = parseInt(root.getAttribute('data-autoplay-speed'), 10) || 5000;
			timer = window.setInterval(function () { go(1); }, speed);
			root.addEventListener('mouseenter', function () { window.clearInterval(timer); });
			root.addEventListener('mouseleave', function () {
				timer = window.setInterval(function () { go(1); }, speed);
			});
		}
	}

	function readHashSlug() {
		var hash = window.location.hash || '';
		if (!hash || hash.length < 2) {
			return '';
		}
		try {
			return decodeURIComponent(hash.slice(1));
		} catch (e) {
			return hash.slice(1);
		}
	}

	function setHashSlug(slug) {
		if (!slug) {
			return;
		}
		var next = '#' + slug;
		if (window.location.hash === next) {
			return;
		}
		if (window.history && window.history.replaceState) {
			var base = window.location.pathname + window.location.search;
			window.history.replaceState(null, '', base + next);
			return;
		}
		window.location.hash = slug;
	}

	function initTabs(root) {
		var tabs = root.querySelectorAll('[data-rsmspark-cw-tab]');
		var panels = root.querySelectorAll('[data-rsmspark-cw-panel]');
		var storagePrefix = 'rsmCwTabs:';

		function readStoredTabSlug() {
			if (root.getAttribute('data-rsmspark-cw-tabs-remember') !== '1') {
				return '';
			}
			var storageKey = root.getAttribute('data-rsmspark-cw-tabs-storage-key');
			if (!storageKey) {
				return '';
			}
			try {
				return localStorage.getItem(storagePrefix + storageKey) || '';
			} catch (e) {
				return '';
			}
		}

		function writeStoredTabSlug(slug) {
			if (root.getAttribute('data-rsmspark-cw-tabs-remember') !== '1' || !slug) {
				return;
			}
			var storageKey = root.getAttribute('data-rsmspark-cw-tabs-storage-key');
			if (!storageKey) {
				return;
			}
			try {
				localStorage.setItem(storagePrefix + storageKey, slug);
			} catch (e) {
				return;
			}
		}

		function tabSlugExists(slug) {
			for (var i = 0; i < tabs.length; i++) {
				if (tabs[i].getAttribute('data-rsmspark-cw-tab-slug') === slug) {
					return true;
				}
			}
			return false;
		}

		function activateTab(key, updateHash) {
			var activeSlug = '';
			tabs.forEach(function (tab) {
				var tabKey = tab.getAttribute('data-rsmspark-cw-tab-slug') || tab.getAttribute('data-rsmspark-cw-tab');
				var active = tabKey === key;
				tab.classList.toggle('is-active', active);
				tab.setAttribute('aria-selected', active ? 'true' : 'false');
				if (active) {
					activeSlug = tab.getAttribute('data-rsmspark-cw-tab-slug') || '';
				}
			});
			panels.forEach(function (panel) {
				var panelKey = panel.getAttribute('data-rsmspark-cw-panel-slug') || panel.getAttribute('data-rsmspark-cw-panel');
				var active = panelKey === key;
				panel.classList.toggle('is-active', active);
				if (active) {
					panel.removeAttribute('hidden');
				} else {
					panel.setAttribute('hidden', 'hidden');
				}
			});
			if (updateHash && activeSlug) {
				setHashSlug(activeSlug);
			}
			if (activeSlug) {
				writeStoredTabSlug(activeSlug);
			}
		}

		tabs.forEach(function (tab) {
			tab.addEventListener('click', function () {
				var key = tab.getAttribute('data-rsmspark-cw-tab-slug') || tab.getAttribute('data-rsmspark-cw-tab');
				activateTab(key, true);
			});
		});

		var hashSlug = readHashSlug();
		if (hashSlug && tabSlugExists(hashSlug)) {
			activateTab(hashSlug, false);
			return;
		}
		var storedSlug = readStoredTabSlug();
		if (storedSlug && tabSlugExists(storedSlug)) {
			activateTab(storedSlug, false);
		}
	}

	function initAccordion(root) {
		function openItem(item, updateHash) {
			if (!item) {
				return;
			}
			var panel = item.querySelector('.rsmspark-cw-accordion__panel');
			var trigger = item.querySelector('[data-rsmspark-cw-accordion-trigger]');
			root.querySelectorAll('.rsmspark-cw-accordion__panel').forEach(function (other) {
				other.classList.remove('is-open');
				other.setAttribute('hidden', 'hidden');
			});
			root.querySelectorAll('[data-rsmspark-cw-accordion-trigger]').forEach(function (otherTrigger) {
				otherTrigger.setAttribute('aria-expanded', 'false');
			});
			if (panel) {
				panel.classList.add('is-open');
				panel.removeAttribute('hidden');
			}
			if (trigger) {
				trigger.setAttribute('aria-expanded', 'true');
			}
			if (updateHash) {
				var slug = item.getAttribute('data-rsmspark-cw-accordion-slug');
				if (slug) {
					setHashSlug(slug);
				}
			}
		}

		root.querySelectorAll('[data-rsmspark-cw-accordion-trigger]').forEach(function (trigger) {
			trigger.addEventListener('click', function () {
				var item = trigger.closest('.rsmspark-cw-accordion__item');
				if (!item) {
					return;
				}
				var panel = item.querySelector('.rsmspark-cw-accordion__panel');
				if (panel && panel.classList.contains('is-open')) {
					root.querySelectorAll('.rsmspark-cw-accordion__panel').forEach(function (other) {
						other.classList.remove('is-open');
						other.setAttribute('hidden', 'hidden');
					});
					root.querySelectorAll('[data-rsmspark-cw-accordion-trigger]').forEach(function (otherTrigger) {
						otherTrigger.setAttribute('aria-expanded', 'false');
					});
					return;
				}
				openItem(item, true);
			});
		});

		var hashSlug = readHashSlug();
		if (!hashSlug) {
			return;
		}
		var items = root.querySelectorAll('[data-rsmspark-cw-accordion-slug]');
		for (var i = 0; i < items.length; i++) {
			if (items[i].getAttribute('data-rsmspark-cw-accordion-slug') === hashSlug) {
				openItem(items[i], false);
				break;
			}
		}
	}

	function initPricingFeatureTips(root) {
		root.querySelectorAll('.rsmspark-cw-pricing__feature-tip').forEach(function (button) {
			if (button.getAttribute('data-rsmspark-cw-tip-init') === '1') {
				return;
			}
			button.setAttribute('data-rsmspark-cw-tip-init', '1');

			var wrap = button.closest('.rsmspark-cw-pricing__feature-tip-wrap');
			if (!wrap) {
				return;
			}

			button.addEventListener('click', function (event) {
				event.preventDefault();
				event.stopPropagation();
				var isOpen = wrap.classList.toggle('is-open');
				button.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
			});
		});

		if (root.getAttribute('data-rsmspark-cw-pricing-tips-bound') === '1') {
			return;
		}
		root.setAttribute('data-rsmspark-cw-pricing-tips-bound', '1');

		document.addEventListener('click', function (event) {
			if (root.contains(event.target)) {
				return;
			}
			root.querySelectorAll('.rsmspark-cw-pricing__feature-tip-wrap.is-open').forEach(function (wrap) {
				wrap.classList.remove('is-open');
				var btn = wrap.querySelector('.rsmspark-cw-pricing__feature-tip');
				if (btn) {
					btn.setAttribute('aria-expanded', 'false');
				}
			});
		});
	}

	function initPricing(root) {
		initPricingFeatureTips(root);

		var buttons = root.querySelectorAll('[data-rsmspark-cw-pricing-period]');
		if (!buttons.length) {
			return;
		}

		buttons.forEach(function (button) {
			button.addEventListener('click', function () {
				var period = button.getAttribute('data-rsmspark-cw-pricing-period');
				buttons.forEach(function (item) {
					item.classList.toggle('is-active', item === button);
				});
				root.classList.remove('is-period-monthly', 'is-period-annual');
				if (period === 'annual') {
					root.classList.add('is-period-annual');
				} else {
					root.classList.add('is-period-monthly');
				}
			});
		});
	}

	function initTeam(root) {
		var modal = root.querySelector('[data-rsmspark-cw-team-modal]');
		if (!modal) {
			return;
		}
		var nameEl = modal.querySelector('[data-rsmspark-cw-team-modal-name]');
		var bioEl = modal.querySelector('[data-rsmspark-cw-team-modal-bio]');

		root.querySelectorAll('[data-rsmspark-cw-team-open]').forEach(function (button) {
			button.addEventListener('click', function () {
				if (nameEl) {
					nameEl.textContent = button.getAttribute('data-name') || '';
				}
				if (bioEl) {
					var bioTargetId = button.getAttribute('data-bio-target');
					var bioSource = bioTargetId ? document.getElementById(bioTargetId) : null;
					if (bioSource) {
						bioEl.innerHTML = bioSource.innerHTML;
					} else {
						bioEl.textContent = button.getAttribute('data-bio') || '';
					}
				}
				modal.removeAttribute('hidden');
			});
		});

		modal.querySelectorAll('[data-rsmspark-cw-team-close]').forEach(function (button) {
			button.addEventListener('click', function () {
				modal.setAttribute('hidden', 'hidden');
			});
		});
	}

	function initHeroParallax(root) {
		if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
			return;
		}

		var targets = root.querySelectorAll('.rsmspark-cw-hero__layer--parallax');
		if (!targets.length) {
			targets = root.querySelectorAll('.rsmspark-cw-hero__bg');
		}

		if (!targets.length) {
			return;
		}

		var onScroll = function () {
			var rect = root.getBoundingClientRect();
			var offset = Math.max(-40, Math.min(40, (window.innerHeight - rect.top) * 0.08));
			targets.forEach(function (el) {
				el.style.transform = 'translate3d(0,' + offset + 'px,0)';
			});
		};

		onScroll();
		window.addEventListener('scroll', onScroll, { passive: true });
		window.addEventListener('resize', onScroll);
	}

	function animateCounter(el, target) {
		var duration = 1400;
		var startTime = null;

		function step(timestamp) {
			if (!startTime) {
				startTime = timestamp;
			}
			var progress = Math.min((timestamp - startTime) / duration, 1);
			el.textContent = String(Math.round(target * progress));
			if (progress < 1) {
				window.requestAnimationFrame(step);
			}
		}

		window.requestAnimationFrame(step);
	}

	function piePath(cx, cy, r, percent) {
		if (percent <= 0) {
			return 'M ' + cx + ',' + cy;
		}
		if (percent >= 100) {
			return 'M ' + cx + ',' + cy + ' m -' + r + ',0 a ' + r + ',' + r + ' 0 1,1 ' + (2 * r) + ',0 a ' + r + ',' + r + ' 0 1,1 -' + (2 * r) + ',0';
		}
		var angle = (percent / 100) * 360;
		var rad = (angle - 90) * Math.PI / 180;
		var x = cx + r * Math.cos(rad);
		var y = cy + r * Math.sin(rad);
		var large = angle > 180 ? 1 : 0;
		return 'M ' + cx + ',' + cy + ' L ' + cx + ',' + (cy - r) + ' A ' + r + ',' + r + ' 0 ' + large + ',1 ' + x + ',' + y + ' Z';
	}

	function ringCircumference(ring) {
		var r = parseFloat(ring.getAttribute('r'));
		if (isNaN(r)) {
			r = 54;
		}
		return 2 * Math.PI * r;
	}

	function setRingState(ring, percent) {
		var c = ringCircumference(ring);
		ring.style.strokeDasharray = String(c);
		ring.style.strokeDashoffset = String(c * (1 - percent / 100));
	}

	function setPieState(path, percent) {
		var r = parseFloat(path.getAttribute('data-rsmspark-cw-pie-r'));
		if (isNaN(r)) {
			r = 54;
		}
		path.setAttribute('d', piePath(60, 60, r, percent));
	}

	function animateRing(ring, targetPercent) {
		var c = ringCircumference(ring);
		var targetOffset = c * (1 - targetPercent / 100);
		ring.style.strokeDasharray = String(c);
		ring.style.strokeDashoffset = String(c);
		window.requestAnimationFrame(function () {
			ring.style.strokeDashoffset = String(targetOffset);
		});
	}

	function animatePie(path, targetPercent) {
		var r = parseFloat(path.getAttribute('data-rsmspark-cw-pie-r'));
		if (isNaN(r)) {
			r = 54;
		}
		var duration = 1400;
		var startTime = null;

		function step(timestamp) {
			if (!startTime) {
				startTime = timestamp;
			}
			var progress = Math.min((timestamp - startTime) / duration, 1);
			path.setAttribute('d', piePath(60, 60, r, targetPercent * progress));
			if (progress < 1) {
				window.requestAnimationFrame(step);
			}
		}

		path.setAttribute('d', piePath(60, 60, r, 0));
		window.requestAnimationFrame(step);
	}

	function initStats(root) {
		var animate = root.hasAttribute('data-rsmspark-cw-stats');
		var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

		root.querySelectorAll('[data-rsmspark-cw-ring]').forEach(function (ring) {
			var percent = parseFloat(ring.getAttribute('data-rsmspark-cw-ring'));
			if (isNaN(percent)) {
				percent = 0;
			}
			if (!animate || reduced) {
				setRingState(ring, percent);
			} else {
				ring.style.strokeDasharray = String(ringCircumference(ring));
				ring.style.strokeDashoffset = String(ringCircumference(ring));
			}
		});

		root.querySelectorAll('[data-rsmspark-cw-pie]').forEach(function (path) {
			var percent = parseFloat(path.getAttribute('data-rsmspark-cw-pie'));
			if (isNaN(percent)) {
				percent = 0;
			}
			if (!animate || reduced) {
				setPieState(path, percent);
			} else {
				path.setAttribute('d', piePath(60, 60, parseFloat(path.getAttribute('data-rsmspark-cw-pie-r')) || 54, 0));
			}
		});

		if (!animate || reduced) {
			if (reduced) {
				root.querySelectorAll('[data-rsmspark-cw-counter]').forEach(function (el) {
					el.removeAttribute('data-rsmspark-cw-counter');
				});
			}
			return;
		}

		var counters = root.querySelectorAll('[data-rsmspark-cw-counter]');
		var rings = root.querySelectorAll('[data-rsmspark-cw-ring]');
		var pies = root.querySelectorAll('[data-rsmspark-cw-pie]');
		if (!counters.length && !rings.length && !pies.length) {
			return;
		}

		var observer = new window.IntersectionObserver(function (entries) {
			entries.forEach(function (entry) {
				if (!entry.isIntersecting) {
					return;
				}
				var scope = entry.target;
				scope.querySelectorAll('[data-rsmspark-cw-counter]').forEach(function (el) {
					if (el.getAttribute('data-rsmspark-cw-counter-done') === '1') {
						return;
					}
					el.setAttribute('data-rsmspark-cw-counter-done', '1');
					var target = parseFloat(el.getAttribute('data-rsmspark-cw-counter'));
					if (!isNaN(target)) {
						animateCounter(el, target);
					}
				});
				scope.querySelectorAll('[data-rsmspark-cw-ring]').forEach(function (ring) {
					if (ring.getAttribute('data-rsmspark-cw-ring-done') === '1') {
						return;
					}
					ring.setAttribute('data-rsmspark-cw-ring-done', '1');
					var percent = parseFloat(ring.getAttribute('data-rsmspark-cw-ring'));
					if (!isNaN(percent)) {
						animateRing(ring, percent);
					}
				});
				scope.querySelectorAll('[data-rsmspark-cw-pie]').forEach(function (path) {
					if (path.getAttribute('data-rsmspark-cw-pie-done') === '1') {
						return;
					}
					path.setAttribute('data-rsmspark-cw-pie-done', '1');
					var percent = parseFloat(path.getAttribute('data-rsmspark-cw-pie'));
					if (!isNaN(percent)) {
						animatePie(path, percent);
					}
				});
				observer.unobserve(scope);
			});
		}, { threshold: 0.35 });

		observer.observe(root);
	}

	function initProgressBars(root) {
		var layout = root.getAttribute('data-rsmspark-cw-progress-layout') || 'bars';
		var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

		function filledStepCount(percent, stepCount) {
			var p = parseFloat(percent);
			if (isNaN(p)) {
				p = 0;
			}
			p = Math.max(0, Math.min(100, p));
			var count = parseInt(stepCount, 10);
			if (isNaN(count) || count < 2) {
				count = 5;
			}
			return Math.min(count, Math.max(0, Math.ceil((p / 100) * count)));
		}

		function applySteps(stepsEl, animate) {
			var percent = stepsEl.getAttribute('data-rsmspark-cw-progress');
			var stepCount = stepsEl.getAttribute('data-rsmspark-cw-step-count');
			var filled = filledStepCount(percent, stepCount);
			var segments = stepsEl.querySelectorAll('.rsmspark-cw-progress-bars__step');

			segments.forEach(function (segment, index) {
				if (index < filled) {
					if (animate && !reduced) {
						window.setTimeout(function () {
							segment.classList.add('is-filled');
						}, index * 80);
					} else {
						segment.classList.add('is-filled');
					}
				} else {
					segment.classList.remove('is-filled');
				}
			});
		}

		function applyBarFills(scope, animate) {
			scope.querySelectorAll('[data-rsmspark-cw-progress]').forEach(function (fill) {
				if (fill.closest('[data-rsmspark-cw-progress-steps]')) {
					return;
				}
				if (!animate || reduced) {
					fill.style.width = fill.getAttribute('data-rsmspark-cw-progress') + '%';
					return;
				}
				fill.style.width = '0%';
				window.requestAnimationFrame(function () {
					fill.style.width = fill.getAttribute('data-rsmspark-cw-progress') + '%';
				});
			});
		}

		function runAnimation(scope) {
			if (layout === 'step') {
				scope.querySelectorAll('[data-rsmspark-cw-progress-steps]').forEach(function (stepsEl) {
					applySteps(stepsEl, true);
				});
			} else if (layout === 'radial') {
				scope.querySelectorAll('[data-rsmspark-cw-progress-ring]').forEach(function (ring) {
					if (ring.getAttribute('data-rsmspark-cw-progress-ring-done') === '1') {
						return;
					}
					ring.setAttribute('data-rsmspark-cw-progress-ring-done', '1');
					var percent = parseFloat(ring.getAttribute('data-rsmspark-cw-progress-ring'));
					if (!isNaN(percent)) {
						animateRing(ring, percent);
					}
				});
			} else {
				applyBarFills(scope, true);
			}
		}

		function runImmediate(scope) {
			if (layout === 'step') {
				scope.querySelectorAll('[data-rsmspark-cw-progress-steps]').forEach(function (stepsEl) {
					applySteps(stepsEl, false);
				});
			} else if (layout === 'radial') {
				scope.querySelectorAll('[data-rsmspark-cw-progress-ring]').forEach(function (ring) {
					var percent = parseFloat(ring.getAttribute('data-rsmspark-cw-progress-ring'));
					if (!isNaN(percent)) {
						setRingState(ring, percent);
					}
				});
			} else {
				applyBarFills(scope, false);
			}
		}

		if (reduced) {
			runImmediate(root);
			return;
		}

		if (layout === 'radial') {
			root.querySelectorAll('[data-rsmspark-cw-progress-ring]').forEach(function (ring) {
				ring.style.strokeDasharray = String(ringCircumference(ring));
				ring.style.strokeDashoffset = String(ringCircumference(ring));
			});
		}

		var observer = new window.IntersectionObserver(function (entries) {
			entries.forEach(function (entry) {
				if (!entry.isIntersecting) {
					return;
				}
				runAnimation(entry.target);
				observer.unobserve(entry.target);
			});
		}, { threshold: 0.25 });

		observer.observe(root);
	}

	function initFooterSticky(root) {
		var placement = root.getAttribute('data-rsmspark-footer-placement') || 'static';
		var revealMode = root.getAttribute('data-rsmspark-footer-reveal') || 'always';
		var backToTop = root.querySelector('.rsmspark-footer__back-to-top');
		var reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
		var lastScrollY = window.pageYOffset || 0;
		var ticking = false;

		function updateStickyVisibility() {
			var scrollY = window.pageYOffset || 0;
			var delta = scrollY - lastScrollY;

			if ('sticky_bar' === placement) {
				if ('scroll_up' === revealMode) {
					if (delta > 8 && scrollY > 120) {
						root.classList.add('rsmspark-footer--is-hidden');
					} else if (delta < -8) {
						root.classList.remove('rsmspark-footer--is-hidden');
					}
				} else if ('scroll_down' === revealMode) {
					if (delta < -8) {
						root.classList.add('rsmspark-footer--is-hidden');
					} else if (delta > 8 && scrollY > 120) {
						root.classList.remove('rsmspark-footer--is-hidden');
					}
				} else {
					root.classList.remove('rsmspark-footer--is-hidden');
				}

				document.documentElement.style.setProperty(
					'--rsmspark-footer-sticky-offset',
					root.classList.contains('rsmspark-footer--is-hidden') ? '0px' : root.offsetHeight + 'px'
				);
			}

			if (backToTop) {
				if (scrollY > 320) {
					backToTop.classList.add('is-visible');
				} else {
					backToTop.classList.remove('is-visible');
				}
			}

			lastScrollY = scrollY;
			ticking = false;
		}

		function onScroll() {
			if (ticking) {
				return;
			}
			ticking = true;
			window.requestAnimationFrame(updateStickyVisibility);
		}

		if ('sticky_bar' === placement) {
			document.body.classList.add('rsmspark-footer-has-sticky-bar');
			updateStickyVisibility();
		}

		if (backToTop) {
			backToTop.addEventListener('click', function () {
				if (reducedMotion) {
					window.scrollTo(0, 0);
					return;
				}
				window.scrollTo({ top: 0, behavior: 'smooth' });
			});
		}

		if ('sticky_bar' === placement || backToTop) {
			window.addEventListener('scroll', onScroll, { passive: true });
			window.addEventListener('resize', onScroll, { passive: true });
		}
	}

	function forEachUninitialized(scope, selector, callback) {
		var container = scope && scope.querySelectorAll ? scope : document;
		container.querySelectorAll(selector).forEach(function (root) {
			if (root.getAttribute('data-rsmspark-cw-init') === '1') {
				return;
			}
			root.setAttribute('data-rsmspark-cw-init', '1');
			callback(root);
		});
	}

	function initWithin(scope) {
		forEachUninitialized(scope, '[data-rsmspark-cw-tabs]', initTabs);
		forEachUninitialized(scope, '[data-rsmspark-cw-accordion]', initAccordion);
		forEachUninitialized(scope, '[data-rsmspark-cw-carousel]', initCarousel);
		forEachUninitialized(scope, '[data-rsmspark-cw-pricing]', initPricing);
		forEachUninitialized(scope, '[data-rsmspark-cw-team]', initTeam);
		if (typeof window.rsmCwDpgInit === 'function') {
			window.rsmCwDpgInit(scope || document);
		}
		if (typeof window.rsmCwMarqueeInit === 'function') {
			window.rsmCwMarqueeInit(scope || document);
		}
		forEachUninitialized(scope, '[data-rsmspark-cw-hero-parallax]', initHeroParallax);
		forEachUninitialized(scope, '[data-rsmspark-cw-stats-host]', initStats);
		forEachUninitialized(scope, '[data-rsmspark-cw-progress-bars]', initProgressBars);
		forEachUninitialized(scope, '[data-rsmspark-footer-sticky="1"]', initFooterSticky);
		if (typeof window.rsmCwMarqueeInit === 'function') {
			window.rsmCwMarqueeInit(scope || document);
		}
		if (window.rsmEventCountdownInit) {
			window.rsmEventCountdownInit(scope || document);
		}
	}

	window.rsmContentWidgetsInit = initWithin;
	initWithin(document);
})();
