/**
 * File tabs.jquery-plugin.js.
 *
 * Handles toggling the navigation menu for small screens and enables TAB key
 * navigation support for dropdown menus.
 */
( function($) {
	const ns = 'plethoraplugins';
	const dataNS = 'pds-tabs--';
	const pds = 'pds';
	const classToAdd = 'js-' + ns + '-tabs';
	const classToAddToLinks = 'js-' + ns + '-tabs--link'; //adding a class to the link will prevent the default link styles from kicking in.
	const activeClass = 'active';
	const linkSelector = 'a[href]';
	const headerSelector = 'h1,h2,h3,h4,h5,h6';
	const isMobileClass = ns + '-tabs-mobile';
	const initialHash = window.location.hash;
	const defaultSettings = {
		mobileDisplay: null,// determines how to display this for mobile devices. Options: 'accordion'
		mobileBreakpoint: null,//determines the breakpoint at which the mobile display takes effect.  Options: an integer representing the max width, or 'auto' (in which case the assumption is that this is a 'horizontal' tab, and that all tabs should fit the browser's screen width)
		mobileBreakpointForced: '', // if set, it will be considered mobile below this threshold (example: 500 for 500px)
		accordionAutoClose: true, //if responsive behavior of vertical tab results in an accordion, should it auto close?
		responsiveAccordionsCollapsedInitially: false, //if responsive behavior of vertical tab results in an accordion, should all accordion items be collapsed initially?
		responsiveAccordionsBreakpoint: false, //set this to a valid css breakpoint value, like 500px, where you want to always have it collapse to accordion
	};
	const scrollIntoViewOptions = {behavior: "smooth"};
	let sideNavNumber = 0;
	if(!$.fn.scrollIntoViewIfNeeded) $.fn.scrollIntoViewIfNeeded = function(){
		if (this.length) {
			if(this[0].scrollIntoViewIfNeeded) this[0].scrollIntoViewIfNeeded(scrollIntoViewOptions);
			else this[0].scrollIntoView(scrollIntoViewOptions);
		}
		return this;
	};

	$.fn[ns + 'Tabs'] = function(inputOptions){
		const options = $.extend({}, defaultSettings, inputOptions);
		return this.each(function(){
			const $nav = $(this);
			if ($nav.hasClass(classToAdd)) return; //prevent double initialization
			$nav.addClass(classToAdd);
			$nav.attr('role', 'tablist').children('li').attr('role','presentation');
			if(options.layout == 'vertical') $nav.attr('aria-orientation', 'vertical');
			if(options.layout == 'horizontal') $nav.attr('aria-orientation', 'horizontal');
			var linkIds = [];
			
			const $container = $nav.closest('.' + ns + '-tabs-container');
			const $contentContainer = $container.find('.' + ns + '-sidenavjump-content:first,.' + ns + '-tabs--content:first');
			let $mobileDisplay = null;
			let isMobile = false;
			sideNavNumber++;
			$nav.attr('data-' + dataNS + 'tab-number', sideNavNumber);
			const $header = $nav.prev(headerSelector);
			if($header.length && !$nav.attr('aria-labelledby')) {
				let headerId = $header.attr('id');
				if(!headerId) {
					headerId = ns + 'tab_' + sideNavNumber + '_header';
					$header.attr('id', headerId);
				}
				$nav.attr('aria-labelledby', headerId);
			}
			let $tabButtons = null;
			const intializeTabButtons = function(){
				$tabButtons = $nav.find(linkSelector).each(function(index){
					const $link = $(this).addClass(classToAddToLinks);
					if(!$link.attr('id')) $link.attr('id', ns + 'tab_' + sideNavNumber + '_tablink_' + index);
					linkIds.push($link.attr('id'));
					if(!$link.attr('role')) $link.attr('role', 'tab');
					if($link.hasClass(activeClass))  $link.attr('aria-selected', 'true').removeAttr('tabindex');
					else $link.attr('aria-selected', 'false').attr('tabindex', '-1');
					const href = $link.attr('href');
					if(!href || !href.charAt(0) == '#') return;
					let $content = $(href).attr('aria-hidden', 'true');
					if(!$content.length) {
						if($contentContainer.length){
							var children = $contentContainer.children();
							if (children.length > index) $content = $(children[index]);
							else return;
						}
						else return;
					}
					if(!$content.attr('id')) $content.attr('id', href.replace('#', ''));
					if($link.hasClass('active')) $content.addClass('active').attr('aria-hidden', 'false');
					$content.addClass('js-' + ns + '-tab-panel');
					$link.attr('aria-controls', $content.attr('id'));
					if(!$content.attr('role')) $content.attr('role', 'tabpanel');
					if(!$content.attr('aria-labelledby')) $content.attr('aria-labelledby', $link.attr('id'));
				});
				$nav.attr('aria-owns', linkIds.join(' '));
					
				$tabButtons.on('click', function(e){ e.preventDefault(); activateTab($(this)); return false; });
				$tabButtons.on('keydown', function(e){ 
					if (event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40) {
						event.preventDefault();
						navigateTabs(event.keyCode);
						return false;
					} 
				});
				//it is possible that NO tabs are active initially, in which case there would be no way for the user to access any of them. In this case, add the first button back into the tab loop
				if($tabButtons.filter('[tabindex="-1"]').length === $tabButtons.length) $tabButtons.first().removeAttr('tabindex');
			};
			
			
			
			const removeActiveClasses = function(){
				//remove active class from all currently active links
				$nav.find('a.' + activeClass).each(function(){
					const $curLink = $(this);
					$curLink.removeClass(activeClass).attr('aria-selected', 'false').attr('tabindex','-1');
					const tabId = $curLink.attr('aria-controls');
					if(tabId) $('#' + tabId).removeClass(activeClass).attr('aria-hidden', 'true');
				});
			};
			const activateTab = function($link, doNotPushState){
				const tabId = $link.attr('aria-controls');
				if(!tabId) return;
				const newHash = '#' + tabId;
				const $content = $(newHash);
				removeActiveClasses();
				$content.addClass(activeClass).attr('aria-hidden','false');
				$link.addClass(activeClass).attr('aria-selected', 'true').removeAttr('tabindex');
				if(!doNotPushState) history.pushState(undefined, undefined, newHash);
				return $link;
			}
			const onHashChange = function(){
				$tabButtons.each(function(){
					//by default, the markup can have the 'active' class on the target content div, but not yet on the link in the side nav - so we add it to the link to match the content...
					const $link = $(this);
					const href = $link.attr('href');
					if(!href || !href.charAt(0) == '#') return;
					if(window.location.hash === href) {
						activateTab($link, true).scrollIntoViewIfNeeded($link);
					}
					
				});
			};
					
			// Navigate tabs with arrow keys
			const navigateTabs = function (keyCode) {
			  var $currentTabButton = $tabButtons.filter('[aria-selected="true"]');
			  var index = $tabButtons.index($currentTabButton);

			  if (keyCode === 37 || keyCode === 38) { // Previous tab
				index--;
				if (index < 0) {
				  index = $tabButtons.length - 1;
				}
			  } else if (keyCode === 39 || keyCode === 40) { // Next tab
				index++;
				if (index >= $tabButtons.length) {
				  index = 0;
				}
			  }
			  const $newTabButton = $tabButtons.eq(index);
			  activateTab($newTabButton);
			  $newTabButton.trigger('focus');
			};
			
			
			const setInitialTab = function(){
				let $initialTabButton = null;
				let $tabButtonThatAlreadyHadActiveClass = null;
				$tabButtons.each(function(){
					//by default, the markup can have the 'active' class on the target content div, but not yet on the link in the side nav - so we add it to the link to match the content...
					const $link = $(this);
					const href = $link.attr('href');
					if(!href || !href.charAt(0) == '#') return;
					if(initialHash === href) $initialTabButton = $link; //detect if the href upon loading the page has a hash that matches one of our links
					const $content = $(href);
					if($content.hasClass(activeClass)) $tabButtonThatAlreadyHadActiveClass = $link;
					
				});
				// if one of our links matched the current location's hash, then trigger a click to load that content and have the page jump down.
				if($initialTabButton) {
					activateTab($initialTabButton, true).scrollIntoViewIfNeeded();
				}
				else if ($tabButtonThatAlreadyHadActiveClass){
					$tabButtonThatAlreadyHadActiveClass.addClass(activeClass);
					//MAYBE: update the URL to show which tab is currently selected...
					//if(history.replaceState) history.replaceState(undefined, undefined, $tabButtonThatAlreadyHadActiveClass.attr('href'));
				}
			};
			
			intializeTabButtons();
			window.addEventListener("hashchange", onHashChange, false);
			setInitialTab();
			
			if(options.mobileDisplay && options.mobileBreakpoint !== null){
				const detectModeSwitch = function(){
					let wasMobile = isMobile;
					
					if(options.mobileBreakpoint === 'always') isMobile = true;
					else if(options.mobileBreakpointForced && window.matchMedia('(max-width: ' + options.mobileBreakpointForced + 'px)').matches) isMobile = true;
					else if(options.mobileBreakpoint === 'auto'){
						$nav.removeClass(isMobileClass);
						const heightBeforeWrap = $nav.height();
						$nav.css('flex-wrap', 'wrap');
						const heightAfterWrap = $nav.height();
						$nav.css('flex-wrap', '');
						if(wasMobile) $nav.addClass(isMobileClass);
						isMobile = heightBeforeWrap !== heightAfterWrap;
					}
					else isMobile = window.matchMedia('(max-width: ' + mobileBreakpoint + 'px)').matches;
					
				
					
					if(isMobile !== wasMobile) {
						$nav[isMobile ? 'addClass' : 'removeClass'](isMobileClass);
						if($mobileDisplay) {
							$tabButtons.each(function(){
								const $link = $(this);
								const href = $link.attr('href');
								const $content = $('[data-' + dataNS + 'tab-content-for="' + $(href).attr('id') + '"]');
								$(href).empty().append($content.children());
							});
							$mobileDisplay.remove();
							$mobileDisplay = null;
						}
						if(isMobile) {
							switch(options.mobileDisplay){
								case 'accordion':
									var theme = getTheme($container);
									var themeClasses = getThemeClasses(theme);
									$mobileDisplay = $('<div class="' + ns + '-accordion ' + themeClasses + '"></div>');
									 
									$tabButtons.each(function(){
										const $link = $(this);
										const itemId = $link.attr('id') + '_acc';
										const href = $link.attr('href');
										const $content = $(href);
										let isActive = options.responsiveAccordionsCollapsedInitially ? false : $link.hasClass(activeClass);
										// if Accordion Item: Open Initially is checked, isActive should be forced to true
										if($content.attr('data-' + dataNS + 'accordion-initially-open') === 'true') isActive = true;
										const $item = $('<div id="' + itemId + '" class="wp-block-pb-accordion-item pds-accordion__item pds-js-accordion-item pds-no-js" data-' + dataNS + 'click-to-close="true" data-' + dataNS + 'scroll="false" data-' + dataNS + 'scroll-offset="0"/>')
											.attr('data-' + dataNS + 'auto-close', options.accordionAutoClose)
											.attr('data-' + dataNS + 'initially-open', isActive)
											.attr('data-' + dataNS + 'icon', options.accordionIcon)
											.attr('data-' + dataNS + 'icon-size', options.accordionIconSize);
										const headingLevelInt = parseInt(options.accordionHeadingLevel.charAt(0).toLowerCase() === 'h' ? options.accordionHeadingLevel.substring(1) : options.accordionHeadingLevel, 10);
										const $controller = $('<div id="at-' + itemId + '" class="pds-accordion__title pds-js-accordion-controller"></div>');
										$controller.append($('<span class="pds-accordion__heading" role="heading" />').attr('aria-level', headingLevelInt).html($link.html()));
										$item.append($controller);
										const $mobileContent = $('<div id="ac-' + itemId + '" class="pds-accordion__content"></div>').attr('data-' + dataNS + 'tab-content-for', $content.attr('id')).append($content.children());
										$item.append($mobileContent);
										$mobileDisplay.append($item);
										$mobileDisplay.insertAfter($nav);
									});
									$(document).trigger('pds-accordion--apply-widgets');
									break;
							}
						}
					}
				};
				$(window).on('resize', detectModeSwitch);
				detectModeSwitch();
			}
		});
	};
	function getThemeClasses(theme){
		var themeClasses = [];
		if (theme != 'none' && theme != 'minimal') themeClasses.push(ns + '-theme__minimal');
		themeClasses.push(ns + '-theme__' + (theme || 'basic'));
		return themeClasses.join(' ');
	}
	function getTheme($element){
		var themeAtt = 'data-' + dataNS + 'theme';
		return $element.closest('['  + themeAtt + ']').attr(themeAtt);
	}
	function getResponsiveBehavior($element){
		return $element.closest('.' + ns + '-tabs-container').attr('data-' + dataNS + 'responsive');
	}
	function getAccordionAutoClose($element){
		var b = $element.closest('.' + ns + '-tabs-container').attr('data-' + dataNS + 'accordion-auto-close');
		if(b) return b == 'true';
		return null;
	}
	function getResponsiveAccordionsCollapsedInitially($element){
		var b = $element.closest('.' + ns + '-tabs-container').attr('data-' + dataNS + 'responsive-accordion-collapsed-initially');
		if(b) return b == 'true';
		return null;
	}
	function getMobileBreakpointForced($element){
		return $element.closest('.' + ns + '-tabs-container').attr('data-' + dataNS + 'mobile-breakpoint-forced') || '';
	}
	function getLayout($element){
		return $element.closest('.' + ns + '-tabs-container').attr('data-' + dataNS + 'layout') || '';
	}
	function getAccordionIconTemplate($element){
		let $container = $element.closest('.' + ns + '-tabs-container');
		return $container.attr('data-' + dataNS + 'accordion-icon') || '';
	}
	function getAccordionIconSize($element){
		let $container = $element.closest('.' + ns + '-tabs-container');
		return $container.data(dataNS + 'accordion-icon-size');
	}
	function getAccordionHeadingLevel($element){
		let $container = $element.closest('.' + ns + '-tabs-container');
		return $container.data(dataNS + 'accordion-heading-level') || 'h3';
	}
	$(function(){
		$('.' + ns + '-sidenavjump,.' + ns + '-tabs').each(function(){
			const $container = $(this);
			const $ul = $container.find('ul');
			const isAccordion = $container.is('.' + ns + '-tabs') && $container.closest('.' + ns + '-tabs-container').is('.' + ns + '-tabs-container--accordion');
			const isTabs = !isAccordion && $container.is('.' + ns + '-tabs');
			let options = {};

			const responsive = getResponsiveBehavior($container);
			if (responsive) {
				const mobileBreakpoint = isAccordion ? 'always' : 'auto';
				var e = {
					mobileDisplay: responsive, 
					mobileBreakpoint: mobileBreakpoint, 
					accordionAutoClose: getAccordionAutoClose($container), 
					responsiveAccordionsCollapsedInitially: getResponsiveAccordionsCollapsedInitially($container),
					accordionIcon: getAccordionIconTemplate($container),
					accordionIconSize: getAccordionIconSize($container),
					accordionHeadingLevel: getAccordionHeadingLevel($container),
					mobileBreakpointForced: getMobileBreakpointForced($container),
					layout: getLayout($container)
				};
				var accordionAutoClose = getAccordionAutoClose($container);
				if(accordionAutoClose !== null) e.accordionAutoClose = accordionAutoClose;
				var responsiveAccordionsCollapsedInitially = getResponsiveAccordionsCollapsedInitially($container);
				if(responsiveAccordionsCollapsedInitially !== null) e.responsiveAccordionsCollapsedInitially = responsiveAccordionsCollapsedInitially;
				options = $.extend(options, e);
			}
			$ul[ns + 'Tabs'](options);
		});
	});
}(jQuery) );;
(function($) {
	'use strict';
	
	const dataNS = 'pds-tabs--';
	/**
	 * Accordion plugin function
	 *
	 * @param object options Plugin settings to override the defaults
	 */
	$.fn.pdsAccordionItem = function(options) {
		const defaultAccordionIcon = '<span class="pds-accordion__icon" role="presentation" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 12 7.4099998" ><path d="M12 1.41 10.59 0 6 4.58 1.41 0 0 1.41l6 6z" fill="currentColor"></path></svg></span>';
		const iconClass = 'pds-accordion__icon';

		var settings = $.extend({
			// Set default settings
			initiallyOpen: false,
			autoClose:     true,
			clickToClose:  true,
			scroll:        false,
			scrollOffset:  false,
			icon: true, /*
				true: default icon. 
				false: hide the icon 
				'<svg>...</svg>': custom markup for a single-state icon. 180 degree rotation will be applied when the state of the accordion item is open.
				{closed: '<b>+</b>', open:'<b>-</b>'}: custom markup for a two-state icon
				*/
			iconSize: '', 
		}, options);

		var duration = 250;
		var hashID = window.location.hash.replace('#', '');

		var item = {};

		item.self       = $(this);
		item.id         = $(this).attr('id');
		item.controller = $(this).find('.pds-js-accordion-controller');
		item.uuid       = getAccordionItemUUID(item.self);
		item.content    = $('#ac-' + item.uuid);
		item.accordionGroupItems = [item.uuid];
		item.accordionAncestorItems = [];
		initialSetup();
		


		/**
		 * Initial setup
		 * Set the scroll offset, and figure out which items should be open by
		 * default.
		 */
		function initialSetup() {
			// Remove the 'pds-no-js' class since JavaScript is enabled
			item.self.removeClass('pds-no-js');
			/**
			 * Set up some defaults for this controller
			 */
			item.controller.attr({
				'tabindex': 0,
				'aria-controls': 'ac-' + item.uuid,
				'role': 'button'
			});
			
			if(!item.controller.attr('id')) item.controller.id(item.uuid + '_acc_header');
			item.content.attr({
				'role':'region',
				'aria-labelledby':item.controller.attr('id')
			});

			settings.scrollOffset = Math.floor(parseInt(settings.scrollOffset, 10)) || 0;

			/**
			 * Add any sibling accordion items to the accordionGroupItems array.
			 */
			$.each(item.self.siblings('.pds-js-accordion-item'), function(index, ele) {
				var uuid = getAccordionItemUUID(ele);

				item.accordionGroupItems.push(uuid);
			});

			/**
			 * Add any parent accordion items to the accordionAncestorItems array.
			 */
			$.each(item.self.parents('.pds-js-accordion-item'), function(index, ele) {
				var uuid = getAccordionItemUUID(ele);

				item.accordionAncestorItems.push(uuid);
			});

			// If this item has `initially-open prop` set to true, open it
			if (settings.initiallyOpen) {
				/**
				 * We aren't opening the item here (only setting open attributes)
				 * because the openItem() function fires the `pds-openAccordionItem`
				 * event which, if `autoClose` is set, would override the users
				 * defined initiallyOpen settings.
				 *
				 * Only setting open attributes is fine since the item's content
				 * display (`display: none|block`) is already set by the plugin.
				 */
				setOpenItemAttributes();
			}
			// If the hash matches this item, open it
			else if (item.id === hashID) {
				/**
				 * Unlike the `initiallyOpen` case above, if a hash is detected
				 * that matches one of the accordion items, we probably _want_
				 * the other items to close so the user can focus on this item.
				 */
				openItem();

				// Open ancestors if necessary
				$.each(item.accordionAncestorItems, function(index, uuid) {
					$(document).trigger('pds-openAncestorAccordionItem', uuid);
				});
			}
			// Otherwise, close the item
			else {
				/**
				 * Don't use closeItem() function call since it animates the
				 * closing. Instead, we only need to set the closed attributes.
				 */
				setCloseItemAttributes();
			}
			adjustIcon();
		}

		function adjustIcon(){
			if(!settings.icon) {
				item.controller.find('.' + iconClass).remove();
				return;
			}
			var $icon = item.controller.find('.' + iconClass);
			if(!$icon.length)  {
				$icon = $(defaultAccordionIcon);
				item.controller.append($icon);
			}
			$icon.css('width', settings.iconSize).css('height', settings.iconSize)
			if(settings.icon !== true){
				if (typeof settings.icon === 'string') {
					$icon.addClass(iconClass + '--custom').empty().append(settings.icon);
				}
				else if (typeof settings.icon === 'object' && settings.icon.open && settings.icon.closed){
					//must be a two-state icon definition
					var $closed = $('<span/>').addClass(iconClass + '--closed').append(settings.icon.closed);
					var $open = $('<span/>').addClass(iconClass + '--open').append(settings.icon.open);
					$icon.addClass(iconClass + '--two-state').empty().append($closed).append($open)
				}
			}
		}


		/**
		 * Default click function
		 * Called when an accordion controller is clicked.
		 */
		function clickHandler() {
			// Only open the item if item isn't already open
			if (!item.self.hasClass('is-open')) {
				// Open clicked item
				openItem();
			}
			// If item is open, and click to close is set, close it
			else if (settings.clickToClose) {
				closeItem();
			}

			return false;
		}



		/**
		 * Get the accordion item UUID for a given accordion item DOM element.
		 */
		function getAccordionItemUUID(ele) {
			return $(ele).find('.pds-js-accordion-controller').attr('id').replace('at-', '');
		}



		/**
		 * Opens an accordion item
		 * Also handles accessibility attribute settings.
		 */
		function openItem(doNotPushState) {
			setOpenItemAttributes();

			// Clear/stop any previous animations before revealing content
			item.content.clearQueue().stop().slideDown(duration, function() {
				// Scroll page to the title
				if (settings.scroll) {
					// Pause scrolling until other items have closed
					setTimeout(function() {
						$('html, body').animate({
							scrollTop: item.self.offset().top - settings.scrollOffset
						}, duration);
					}, duration);
				}
			});

			$(document).trigger('pds-openAccordionItem', item);
			
			if(!doNotPushState) {
				const newHash = '#' + item.id;
				if(newHash !== window.location.hash) history.pushState(undefined, undefined, newHash);
			}
		}



		/**
		 * Set open item attributes
		 * Mark accordion item as open and read and set aria attributes.
		 */
		function setOpenItemAttributes() {
			item.self.addClass('is-open is-read');
			item.controller.attr('aria-expanded', true);
			item.content.prop('hidden', false);
		}



		/**
		 * Closes an accordion item
		 * Also handles accessibility attribute settings.
		 */
		function closeItem() {
			// Close the item
			item.content.slideUp(duration, function() {
				setCloseItemAttributes();
			});
		}



		/**
		 * Set closed item attributes
		 * Mark accordion item as closed and set aria attributes.
		 */
		function setCloseItemAttributes() {
			item.self.removeClass('is-open');
			item.controller.attr('aria-expanded', false);
			item.content.attr('hidden', true);
		}



		/**
		 * Close all items if auto close is enabled
		 */
		function maybeCloseItem() {
			if (settings.autoClose && item.self.hasClass('is-open')) {
				closeItem();
			}
		}



		/**
		 * Add event listeners
		 */
		item.controller.on('click', clickHandler);



		/**
		 * Listen for other accordion items opening
		 *
		 * The `pds-openAccordionItem` event is fired whenever an accordion item is
		 * opened after initial plugin setup.
		 */
		$(document).on('pds-openAccordionItem', function(event, ele) {
			/**
			 * Only trigger potential close these conditions are met:
			 *
			 * 1. This isn't the item the user just clicked to open.
			 * 2. This accordion is in the same group of accordions as the one
			 *    that was just clicked to open.
			 * 3. This accordion is not an ancestor of the item that was just
			 *    clicked to open.
			 *
			 * This serves two purposes:
			 *
			 * 1. It allows nesting of accordions to work.
			 * 2. It allows users to group accordions to control independently
			 *    of other groups of accordions.
			 * 3. It allows child accordions to be opened via hash change
			 *    without automatically closing the parent accordion, therefore
			 *    hiding the accordion the user just indicated they wanted open.
			 */
			if (
				ele !== item &&
				ele.accordionGroupItems.indexOf(item.uuid) > 0 &&
				ele.accordionAncestorItems.indexOf(item.uuid) === -1
			) {
				maybeCloseItem();
			}
		});



		/**
		 * Listen for ancestor opening requests
		 *
		 * The `pds-openAncestorAccordionItem` event is fired whenever a nested
		 * accordion item is opened, but the ancestors may also need to be
		 * opened.
		 */
		$(document).on('pds-openAncestorAccordionItem', function(event, uuid) {
			if (uuid === item.uuid) {
				openItem(true);
			}
		});



		item.controller.on('keydown', function(event) {
			var code = event.which;

			if (item.controller.prop('tagName') !== 'BUTTON') {
				// 13 = Return, 32 = Space
				if ((code === 13) || (code === 32)) {
					// Simulate click on the controller
					$(this).click();
				}
			}

			// 27 = Esc
			if (code === 27) {
				maybeCloseItem();
			}
		});

		// Listen for hash changes (in page jump links for accordions)
		$(window).on('hashchange', function() {
			hashID = window.location.hash.replace('#', '');

			// Only open this item if the has matches the ID
			if (hashID === item.id) {
				var ele = $('#' + hashID);

				// If there is a hash and the hash is on an accordion item
				if (ele.length && ele.hasClass('pds-js-accordion-item')) {
					// Open clicked item
					openItem(true);

					// Open ancestors if necessary
					$.each(item.accordionAncestorItems, function(index, uuid) {
						$(document).trigger('pds-openAncestorAccordionItem', uuid);
					});
				}
			}
		});

		return this;
	};


	function initializeNewAccordions(){
		$('.pds-js-accordion-item.pds-no-js').each(function() {
			var fromData = {
				// Set default settings
				initiallyOpen: $(this).data(dataNS + 'initially-open'),
				autoClose:     $(this).data(dataNS + 'auto-close'),
				clickToClose:  $(this).data(dataNS + 'click-to-close'),
				scroll:        $(this).data(dataNS + 'scroll'),
				scrollOffset:  $(this).data(dataNS + 'scroll-offset'),
				icon:  		   $(this).data(dataNS + 'icon'),
				iconSize:  	   $(this).data(dataNS + 'iconSize'),
			};
			$(this).pdsAccordionItem(fromData);
		});
	}
	// Loop through accordion settings objects
	// Wait for the entire page to load before loading the accordion
	$(window).on('load', initializeNewAccordions);
	$(document).on('pds--apply-widgets pds-accordion--apply-widgets', initializeNewAccordions);
}(jQuery));
;
