(function() {

jQuery(document).ready(function($) {
	var star = String.fromCharCode(57395);
	var starEmpty = String.fromCharCode(57393);

	window.ags_wc_filters_isInVisualBuilder = $(document.body).hasClass('et-fb');

	var $shopModule = $('.ags-wc-filters-target:first');
	var applyFiltersTimeout = {};
	var $applyButton = $(".ags-wc-filters-button-apply").click(function() {
		window.ags_wc_filters_applyFilters( $(this).closest('.ags_woo_products_filters') );
	});

	$(document).on('click', function(ev) {
		var $hideParent = $(ev.target).closest('.ags-wc-filters-hide-on-click');
		$('.ags-wc-filters-hide-on-click').not($hideParent).hide();
	});

	$(".ags-wc-filters-section-title.ags-wc-filters-section-toggle").click(function(ev) {
		$(this).parent().toggleClass('ags-wc-filters-section-toggle-closed');
	});

	window.ags_wc_filters_processOptionLabel = function(label) {
		// Wrap stars
		var firstStar = label.indexOf(star);

		if (label[firstStar + 4] === starEmpty || label[firstStar + 4] === star) {
			label = ( firstStar > 0 ? label.substring(0, firstStar - 1) + ( label[firstStar - 1] === ' ' ? '&nbsp;' : label[firstStar - 1] ) : '' )
					+ '<span class="ags-wc-filters-stars">'
					+ label.substring(firstStar, firstStar + 5)
								.replaceAll(new RegExp(star, 'g'), '<span class="ags-wc-filters-star-filled">' + star + '</span>')
								.replaceAll(new RegExp(starEmpty, 'g'), '<span class="ags-wc-filters-star-empty">' + star + '</span>')
					+ '</span>'
					+ (label.length > firstStar + 5 ? ( label[firstStar + 5] === ' ' ? '&nbsp;' : label[firstStar + 5] ) : '')
					+ label.substring(firstStar + 6);
		}

		return label;
	}

	window.ags_wc_filters_applyFiltersThrottled = function($filters) {
		var orderClass = $filters[0].className.match(/ags_woo_products_filters_[0-9]+/)[0];

		if (applyFiltersTimeout[orderClass]) {
			clearTimeout(applyFiltersTimeout[orderClass]);
		}

		applyFiltersTimeout[orderClass] = setTimeout(function() {
			delete applyFiltersTimeout[orderClass];
			window.ags_wc_filters_applyFilters($filters);
		}, 200);
	}

	window.ags_wc_filters_applyFilters = function($filters, url, extraData, cb) {
		// Don't allow filters to be applied in the VB
		if (window.ags_wc_filters_isInVisualBuilder) {
			return false;
		}

		var queryString = '', query = {};
		var $selectedData = $('.ags-wc-filters-selected').empty();
		var dirtyProductCounts = [];

		function addToSelectedFilters(queryVar, valueId, valueText, valueTextIsHtml) {
			var $selected = jQuery('<p class="ags-wc-filters-selected-inner">')
				.attr('data-filter', queryVar + ':' + valueId);
			if (valueTextIsHtml) {
				$selected.html(valueText);
			} else {
				$selected.text(valueText);
			}
			$selected
				.prepend('<span class="ags-wc-filters-remove">x&nbsp;</span>')
				.html( window.ags_wc_filters_processOptionLabel($selected.html()) )
				.appendTo($selectedData.not(':has([data-filter="' + queryVar + ':' + valueId + '"])'));
		}

		var skipParams = ['add-to-cart'];

		$filters.find('.ags-wc-filters-section').each(function() {
			skipParams.push($(this).data('ags-wc-filters-query-var'));

			var $section = $(this);
			var queryVar = $section.data('ags-wc-filters-query-var');
			var dynamicProductCounts = $section.data('ags-wc-filters-dynamic-product-counts');

			var displayType = window.ags_wc_filters_getDisplayType($section);

			switch (displayType) {
				case 'dropdown_single_select':
					var $sel = $section.find('.ags-wc-filters-dropdown-single-options:first .ags-wc-filters-active:not([data-id="all"]):first');
					if ($sel.length) {
						addToSelectedFilters(queryVar, $sel.data('id'), $sel.data('label'));
						sel = $sel.data('id').toString();
					}

					if (dynamicProductCounts) {
						$section.find('.ags-wc-filters-dropdown-single-options:first a').each(function() {
							var $option = $(this);
							dirtyProductCounts.push({
								parent: '#' + $option.attr('id'),
								filter: queryVar,
								value: $option.data('id')
							});
						});
					}

					break;
				case 'dropdown_multi_select':
				case 'checkboxes_list':
				case 'radio_buttons':
					var sel = $section.find('.ags-wc-filters-list:first :checked:not([value="all"])')
								.each(function() {
									var $option = $(this);
									addToSelectedFilters(queryVar, $option.val(), $option.data('label'));
								})
								.map(function() {
									return $(this).val();
								})
								.get();


					if (dynamicProductCounts) {
						$section.find('.ags-wc-filters-list:first input').each(function() {
							var $option = $(this);

							dirtyProductCounts.push({
								parent: 'label[for="' + $option.attr('id') + '"]',
								filter: queryVar,
								value: $option.val()
							});
						});
					}

					break;
				case 'search':
					var sel = $section.find('input[type="search"]:first').val().trim();
					if (sel) {
						addToSelectedFilters(queryVar, sel, '"' + sel + '"');
					}
					break;
				case 'number_range':
					var min = $section.find('input[type="number"]:first').val();
					var max = $section.find('input[type="number"]:last').val();

					if (min || max) {
						min = min.length ? parseInt(min) : '';
						max = max.length ? parseInt(max) : '';

						var sel = min + '-' + max;
						var currencySymbol = $section.find('.ags-wc-filters-number-range-container').data('currency-symbol');

						if (!min) {
							var label = wp.i18n.__('Price at most %s', 'divi-shop-builder').replace('%s', currencySymbol + max);
						} else if (!max) {
							var label = wp.i18n.__('Price at least %s', 'divi-shop-builder').replace('%s', currencySymbol + min);
						} else {
							var label = wp.i18n.__('Price from %s to %s', 'divi-shop-builder').replace('%s', currencySymbol + min).replace('%s', currencySymbol + max);
						}

						addToSelectedFilters(queryVar, sel, label);
					} else {
						var sel = null;
					}

					break;
				case 'stars':
					var $control = $section.find('.ags-wc-filters-stars-control:first').clone();
					$control.find('.ags-wc-filters-star-hover').removeClass('ags-wc-filters-star-hover');
					var sel = $control.attr('data-value');

					if (sel === '0') {
						sel = null;
					} else {
						addToSelectedFilters(queryVar, sel, $control.html(), true);
					}

					break;

			}


			if(sel && sel.length){
				var queryVar = $section.data('ags-wc-filters-query-var');
				if (!query[queryVar]) {
					query[queryVar] = [];
				}
				if (typeof sel === 'object') {
					query[queryVar] = query[queryVar].concat(sel);
				} else {
					query[queryVar].push(sel);
				}
				
				
				
			}

		});
		
		for (var queryVar in query) {
			var uniqueValues = [];
			for (var i = 0; i < query[queryVar].length; ++i) {
				if (uniqueValues.indexOf(query[queryVar][i]) === -1) {
					uniqueValues.push(query[queryVar][i]);
				}
			}
			
			queryString += (queryString ? '&' : '') + queryVar + '=' + uniqueValues.map(encodeURIComponent).join('&' + queryVar + '=');
		}
		

		if ($selectedData.has('*').length) {
			$selectedData.closest('.ags-wc-filters-selected-outer').show();
		} else {
			$selectedData.closest('.ags-wc-filters-selected-outer').hide();
		}

		var shop_url = url ? url : location.href;
		var queryIndex = shop_url.indexOf('?');
		if (queryIndex !== -1) {
			var query = shop_url.substring(queryIndex + 1).split('&');
			var newQuery = [];
			for (var i = 0; i < query.length; ++i) {
				query[i] = query[i].split('=');
				if ( skipParams.indexOf(query[i][0]) === -1 && ( url || query[i][0].substring(0, 8) !== 'shopPage' ) ) {
					newQuery.push( query[i].join('=') );
				}
			}

			shop_url = shop_url.substring(0, queryIndex) + (newQuery.length ? '?' + newQuery.join('&') : '');
		}

		if (queryString) {
			shop_url += (shop_url.indexOf('?') === -1 ? '?' : '&') + queryString;
		}
		
		var urlChanged = shop_url !== window.location.href;
		
		if (urlChanged || !$shopModule.hasClass('ags-woo-shop-ajax-loaded')) {
			if (urlChanged) {
				window.history.pushState('', document.title, shop_url);
			}
			loadShopAjax($shopModule, extraData, cb);
		}

		clearAllFilters( $('.ags_woo_products_filters').not( $(this).closest('.ags_woo_products_filters').addBack('.ags_woo_products_filters') ) );
		onUrlChanged(null, null, true);
		

		if (dirtyProductCounts.length) {
			$.post(
				getAjaxUrl(),
				{
					ags_wc_filters_product_counts: JSON.stringify(dirtyProductCounts)
				},
				function(response) {
					for (var i = 0; i < response.length; ++i) {
						$(response[i].parent + ' .ags-wc-filters-product-count').text(response[i].count);
					}
				},
				'json'
			);
		}
	}

	function getAjaxUrl() {
		var url = window.location.href;

		// Process duplicate GET variables
		var queryStartPos = url.indexOf('?');
		if (queryStartPos !== -1) {
			var query = url.substring(queryStartPos + 1).split('&');
			var fields = {};
			for (var i = 0; i < query.length; ++i) {
				query[i] = query[i].split('=');
				if ( fields[ query[i][0] ] ) {
					fields[ query[i][0] ].push( [ query[i][1] ] );
				} else {
					fields[ query[i][0] ] = [ query[i][1] ];
				}
			}

			for (fieldName in fields) {
				fields[fieldName] = fieldName + '=' + fields[fieldName].join('%2C'); // comma
			}

			url = url.substring(0, queryStartPos + 1) + Object.values(fields).join('&');
		}

		return url;
	}

	function loadShopAjax($shop, extraData, cb) {
		if (!extraData) {
			extraData = [];
		}
		
		var $body = $shop.closest('body');
		
		var notices = $body.find('.ags_woo_notices').get().map(function(elem) {
			return elem.className.split(' ').filter(function(className) {
				return className.indexOf('ags_woo_notices_') === 0;
			})[0];
		});
		
		notices = notices.map(function(value) {
			return {
				name: 'ags_wc_filters_ajax_notices[]',
				value: value
			}
		});
		
		var dataToSend = [
			{
				name: 'ags_wc_filters_ajax_shop',
				value: $shop[0].className.split(' ').filter(function(className) {
					return className.indexOf('ags_woo_shop_plus_') === 0;
				})[0]
			}
		].concat(notices)
		.concat(extraData);
		

		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: getAjaxUrl(),
			data: dataToSend,
			beforeSend: function (response) {
			  $shop.addClass('ags-woo-shop-loading');
			},
			success: function(response) {
				if (response.dswcpRedirect) {
					window.location.href = response.dswcpRedirect;
					return;
				}
				
				for (shopId in response.shop) {
					addOrderSelectHandler(
						$body.find('.' + shopId).html(response.shop[shopId]).removeClass('ags-woo-shop-loading').addClass('ags-woo-shop-ajax-loaded')
					);
				}
				
				$('.ags-wc-filters-sections .ags-wc-filters-section[data-ags-wc-filters-query-var="shopPrice"]').each(function() {
					ags_wc_filters_initFilters( $(this) ); // re-init price filters
				});
				
				if (response.notices) {
					for (noticeId in response.notices) {
						$body.find('.' + noticeId).html(response.notices[noticeId]);
					}
				}
				
				  if (cb) {
					  cb(response);
				  }
			},
			error: function(err) {
				$shop.removeClass('ags-woo-shop-loading');
				if (cb) {
					cb();
				}
			}
		});
	}
	
	function addOrderSelectHandler($container) {
		$container.find('select.orderby').change(function(ev) {
			ev.originalEvent.stopPropagation();
			var $field = $(this);
			var fieldValue = $field.val();
			var moduleIndex = $('.ags_woo_shop_plus').index($field.closest('.ags_woo_shop_plus'));
			moduleIndex = moduleIndex ? moduleIndex + 1 : '';
			window.history.pushState(
				null,
				document.title,
				new RegExp('([\?&]shopOrder' + moduleIndex + '\=)').test(window.location.search)
					? window.location.href.replace(new RegExp('([\?&]shopOrder' + moduleIndex + '\=)([^&]*)'), (fieldValue === 'menu_order' ? '' : '$1' + fieldValue.replaceAll(/\$/g, '$$')))
					: window.location.href + (fieldValue === 'menu_order' ? '' : (window.location.href.indexOf('?') === -1 ? '?' : '&') + 'shopOrder' + moduleIndex + '=' + fieldValue)
			);
			loadShopAjax( $field.closest('.ags-divi-wc-shop-ajax') );
			return false;
		});
	}

	if (!window.ags_wc_filters_isInVisualBuilder) {
		addOrderSelectHandler(
			$('.ags-divi-wc-shop-ajax').on('click', 'a', function() {
				var $link = $(this);

				if ($link.hasClass('add_to_cart_button') && $link.attr('href').indexOf('add-to-cart=') !== -1 && !$link.hasClass('wcpa_has_options') ) {
					var extraData = [];
					extraData = $link.closest('.product').find(':input').serializeArray();
					var linkParts = $link.attr('href').split('?');
					if (linkParts.length === 2) {
						var queryParts = linkParts[1].split('&');
						for (var i = 0; i < queryParts.length; ++i) {
							var queryPair = {};
							var equalsPos = queryParts[i].indexOf('=');
							extraData.push({
								name: equalsPos ? queryParts[i].substring(0, equalsPos) : queryParts[i],
								value: equalsPos ? queryParts[i].substring(equalsPos + 1) : ''
							});
						}
					}
					loadShopAjax( $link.closest('.ags-divi-wc-shop-ajax'), extraData, function(response) {
						window.jQuery(document.body).trigger('added_to_cart', [ response && response['wc-fragments'] ? response['wc-fragments'] : {}, response && response['wc-cart-hash'] ? response['wc-cart-hash'] : '' ]);
					} );
					return false;
				}

				if ($link.closest('.woocommerce-pagination').length) {
					var $shop = $link.closest('.ags-divi-wc-shop-ajax');
					
					var moduleIndex = $('.ags_woo_shop_plus').index($shop.closest('.ags_woo_shop_plus'));
					var pageVar = 'shopPage' + (moduleIndex ? moduleIndex + 1 : '');
					var linkHref = $link.attr('href');
					
					var pageNumResult = new RegExp('[\?&]' + pageVar + '\=([0-9]+)').exec(linkHref);
					var pageNum = pageNumResult ? pageNumResult[1] : null;
					
					window.history.pushState(
						null,
						document.title,
						new RegExp('([\?&]' + pageVar + '\=)').test(window.location.search)
							? window.location.href.replace(new RegExp('([\?&]' + pageVar + '\=)([^&]*)'), (pageNum ? '$1' + pageNum : ''))
							: window.location.href + (pageNum ? (window.location.href.indexOf('?') === -1 ? '?' : '&') + pageVar + '=' + pageNum : '')
							);
					loadShopAjax( $shop, null, function() {
						if (window.et_pb_smooth_scroll) {
							window.et_pb_smooth_scroll( $shop );
						}
					} );
					return false;
				}

				if ($link.closest('.categories').length) {
					var filterUrl = $link.data('filter-url');
					if (filterUrl && $('.ags-wc-filters-section[data-ags-wc-filters-query-var="shopCategory"]:not(.ags-wc-filters-children-hide):first').length ) {
						var $shop = $link.closest('.ags-divi-wc-shop-ajax');
						window.history.pushState( null, document.title, decodeURIComponent(filterUrl) );
						onUrlChanged(null, function() {
							if (window.et_pb_smooth_scroll) {
								window.et_pb_smooth_scroll( $shop );
							}
						});
						return false;
					}
				}

			})
		);
	}

	/*---------------Apply Ajax End-----------------*/

   function onUrlChanged(ev, cb, noApplyFilters) {

	   if (ev) {
		$('.ags-wc-filters-sections').each(function() {
			clearAllFilters($(this));
		});
	   }

		var queryPairs = window.location.search.substring(1).split('&');
		var filteringSettings = {};

		for (var i = 0; i < queryPairs.length; ++i) {
			if (queryPairs[i].substring(0, 13) === 'shopCategory=') {
				var queryVar = 'shopCategory';
				var catPara = decodeURIComponent( queryPairs[i].substring(13) );
			} else if (queryPairs[i].substring(0, 8) === 'shopTag=') {
				var queryVar = 'shopTag';
				var catPara = decodeURIComponent( queryPairs[i].substring(8) );
			} else if ( queryPairs[i].substring(0, 14) === 'shopAttribute_' && queryPairs[i].indexOf('=') !== -1 ) {
				var eqPos = queryPairs[i].indexOf('=');
				var queryVar = queryPairs[i].substring(0, eqPos);
				var catPara = decodeURIComponent( queryPairs[i].substring(eqPos + 1) );
			} else if (queryPairs[i].substring(0, 11) === 'shopSearch=') {
				var queryVar = 'shopSearch';
				var catPara = decodeURIComponent( queryPairs[i].substring(11) );
			} else if (queryPairs[i].substring(0, 11) === 'shopRating=') {
				var queryVar = 'shopRating';
				var catPara = decodeURIComponent( queryPairs[i].substring(11) );
			} else if (queryPairs[i].substring(0, 10) === 'shopPrice=') {
				var queryVar = 'shopPrice';
				var catPara = decodeURIComponent( queryPairs[i].substring(10) );
			} else if (queryPairs[i].substring(0, 16) === 'shopStockStatus=') {
				var queryVar = 'shopStockStatus';
				var catPara = decodeURIComponent( queryPairs[i].substring(16) );
			} else if (queryPairs[i].substring(0, 9) === 'shopSale=') {
				var queryVar = 'shopSale';
				var catPara = decodeURIComponent( queryPairs[i].substring(9) );
			}

			if(typeof catPara !== 'undefined'){
				if (filteringSettings[queryVar]) {
					filteringSettings[queryVar].push(catPara);
				} else {
					filteringSettings[queryVar] = [catPara];
				}
			}
		}

		for ( queryVar in filteringSettings ) {

			var catArray = filteringSettings[queryVar];
			if(catArray.length){

				var changed = false;

				$('.ags-wc-filters-section[data-ags-wc-filters-query-var="' + queryVar + '"]').each(function() {

					$filters = $(this);

					switch (window.ags_wc_filters_getDisplayType($filters)) {
						case 'checkboxes_list':
						case 'dropdown_multi_select':
							var $activeCheckboxes = $filters.find(".ags-wc-filters-list:first :checkbox[value='" + catArray[0] + "']");
							for (var i = 1; i < catArray.length; ++i) {
								$activeCheckboxes = $activeCheckboxes.add( $filters.find(".ags-wc-filters-list:first :checkbox[value='" + catArray[i] + "']") );
							}

							changed = $filters.find(".ags-wc-filters-list:first :checkbox:checked").not($activeCheckboxes).prop('checked', false).change().length || changed;
							changed = $activeCheckboxes.not(':checked').prop('checked', true).change().length || changed;
							break;
						case 'radio_buttons':
							changed = $filters.find(".ags-wc-filters-list:first :radio[value='" + catArray[0] + "']:not(:checked)").prop('checked', true).change().length || changed;
							break;
						case 'dropdown_single_select':
							changed = $filters.find('.ags-wc-filters-dropdown-single-options:first a[data-id="' + catArray[0] + '"]:not(.ags-wc-filters-active):first').click().length || changed;
							break;
						case 'search':
							$filters.find('input[type="search"]:first').val( catArray[0] ).trigger('input');
							break;
						case 'number_range':
							catArray = catArray[0].split('-');
							$filters.find('input[type="number"]:first').val( catArray[0] );
							$filters.find('input[type="number"]:last').val( catArray[1] ).trigger('input');
							break;
						case 'stars':
							if ( ( catArray[0].length === 2 ? catArray[0][1] === '+' : catArray[0].length === 1 ) && catArray[0][0] >= 1 && catArray[0][0] <= 5) {
								$filters.find('.ags-wc-filters-stars:first span:eq(' + (catArray[0][0] - 1) + ')').click();
							}
							break;

					}
				});

			}

		}
		
		if (!noApplyFilters) {
			$('.ags_woo_products_filters').each(function() {
				window.ags_wc_filters_applyFilters( $(this), null, null, cb );
			});
		}
	}

	if (!window.ags_wc_filters_isInVisualBuilder) {
		$(window).on('popstate', onUrlChanged);

		$(".ags-wc-filters-button-clear").click(function() {
			clearAllFilters( $(this).closest('.ags_woo_products_filters'), true );
		});
	}

		function clearAllFilters($filtersContainer, apply) {
			$filtersContainer.find('.ags-wc-filters-section').each(function() {
				var $filters = $(this);

				switch (window.ags_wc_filters_getDisplayType($filters)) {
					case 'radio_buttons':
						var $allOption = $filters.find("input[value='all']:first");
						if (!$allOption.prop('checked')) {
							$allOption.prop('checked', true).change();
							if (apply) {
								window.ags_wc_filters_applyFilters($filtersContainer);
							}
						}
						break;
					case 'dropdown_single_select':
						$filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-dropdown-single-options li a").removeClass("ags-wc-filters-active");
						var allCategoriesOptionText = $filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-dropdown-single-options li a[data-id='all']").addClass("ags-wc-filters-active").data('label');
						$filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-active a span").text(allCategoriesOptionText);
						$filters.closest('.ags_woo_products_filters').find('.ags-wc-filters-selected:first .ags-wc-filters-selected-inner[data-filter^="' + $filters.data('ags-wc-filters-query-var') + ':"]').remove();
						if (apply) {
							window.ags_wc_filters_applyFilters($filtersContainer);
						}
						break;
					case 'dropdown_multi_select':
					case 'checkboxes_list':
						var changed = false;
						$filters.find(".ags-wc-filters-list:first :checkbox").each(function(index) {
							if($(this).prop('checked') === true){
								$(this).prop('checked', false).change();
								changed = true;
							}
						});
						if (changed && apply) {
							window.ags_wc_filters_applyFilters($filtersContainer);
						}
						$filters.find(".ags-wc-filters-active span").text( $filters.find('.ags-wc-filters-dropdown-multi:first').data('placeholder-text') );
						break;
					case 'search':
						var $search = $filters.find('input[type="search"]:first');

						if ($search.val()) {
							$search.val('').trigger('input');
							if (apply) {
								window.ags_wc_filters_applyFilters($filtersContainer);
							}
						}
						break;

					case 'number_range':
						var $min = $filters.find('input[type="number"]:first');
						var $max = $filters.find('input[type="number"]:last');

						if ($min.val() || $max.val()) {
							$min.val('');
							$max.val('').trigger('input');
							if (apply) {
								window.ags_wc_filters_applyFilters($filtersContainer);
							}
						}
						break;

					case 'stars':
						var $control = $filters.find('.ags-wc-filters-stars-control:first');
						var hadValue = parseInt($control.attr('data-value')) !== 0;

						if (hadValue) {
							$control
								.attr('data-value', 0)
								.find('.ags-wc-filters-stars:first > span')
								.removeClass('ags-wc-filters-star-filled')
								.addClass('ags-wc-filters-star-empty');
							$filters.closest('.ags_woo_products_filters').find('.ags-wc-filters-selected:first .ags-wc-filters-selected-inner[data-filter^="' + $filters.data('ags-wc-filters-query-var') + ':"]').remove();
							if (apply) {
								window.ags_wc_filters_applyFilters($filtersContainer);
							}
						}
						break;
				}
			});
		}

		$('.ags_woo_products_filters').find('.ags-wc-filters-selected:first').on('click', '.ags-wc-filters-remove', function() {
			if (window.ags_wc_filters_isInVisualBuilder) {
				return false;
			}

			var $selectedItem = $(this).parent();
			var filter = $selectedItem.data('filter').split(':');
			var $filtersContainer = $selectedItem.closest('.ags_woo_products_filters');
			var $filters = $filtersContainer.find('.ags-wc-filters-section[data-ags-wc-filters-query-var="' + filter[0] + '"]');

			switch ( window.ags_wc_filters_getDisplayType( $filters ) ) {
				case 'dropdown_multi_select':
				case 'checkboxes_list':
					$filters.find('.ags-wc-filters-list:first input[value="' + filter[1] + '"]').prop('checked', false).change();
					break;

				case 'dropdown_single_select':
					$filters.find('.ags-wc-filters-dropdown-single-options:first a[data-id="all"]:first').click();
					break;

				case 'radio_buttons':
					$filters.find('.ags-wc-filters-list:first input[value="all"]').prop('checked', true).change();
					break;

				case 'search':
					$filters.find('input[type="search"]:first').val('').trigger('input');
					break;

				case 'number_range':
					$filters.find('input[type="number"]:first').val('');
					$filters.find('input[type="number"]:last').val('').trigger('input');
					break;

				case 'stars':
					var $control = $filters.find('.ags-wc-filters-stars-control:first');
					var emptyStar = $control.data('star-empty');

					$control
						.attr('data-value', 0)
						.find('.ags-wc-filters-stars:first > span')
						.removeClass('ags-wc-filters-star-filled')
						.addClass('ags-wc-filters-star-empty');

					break;

			}

			if (!$applyButton.length) {
				window.ags_wc_filters_applyFilters($filtersContainer);
			}

			$selectedItem.remove();

		});


	$('.ags-wc-filters-section').each(function() {
		window.ags_wc_filters_initFilters($(this));
	});

	$(window).on('et_builder_api_ready', function(ev, api) {

		var filterShopModules = [];

		function findShopFilteringModules(shortcodes) {
			for (var i = 0; i < shortcodes.length; ++i) {

				if (shortcodes[i].type === 'ags_woo_shop_plus') {
					if (shortcodes[i].attrs.filter_target === 'on') {
						filterShopModules.push(shortcodes[i]._key);
					}
				} else if (typeof shortcodes[i].content === 'object') {
					findShopFilteringModules(shortcodes[i].content);
				}
			}
		}

		var activeTogglePollInterval;

		window.et_gb.wp.hooks.addFilter(
			'et.builder.store.action.dispatched',
			'ags-wc-filters',
			function(action) {

				switch ( action.actionType ) {
					case 'MODULE_EDIT_SETTINGS_CHANGE':
						if ( action.module.props.type === 'ags_woo_shop_plus' && action.setting === 'filter_target') {
							var index = filterShopModules.indexOf(action.module.props._key);
							if (action.newValue === 'on') {
								if (index === -1) {
									filterShopModules.push(action.module.props._key);
								}
							} else if (index !== -1) {
								filterShopModules.splice(index, 1);
							}
							window.ags_wc_filters_noShopFilteringModule = !filterShopModules.length;
							window.ags_wc_filters_multipleShopFilteringModules = filterShopModules.length > 1;
						}
						break;
					case 'ET_SET_ROOT_MOUNTED':
						findShopFilteringModules(ETBuilderBackend.shortcodeObject);
						window.ags_wc_filters_noShopFilteringModule = !filterShopModules.length;
						window.ags_wc_filters_multipleShopFilteringModules = filterShopModules.length > 1;
						break;
				}

				return action;

			}
		);

		window.et_gb.wp.hooks.addAction(
			'et.builder.store.module.settings.open',
			'ags-wc-filters',
			function(module) {
				if ( activeTogglePollInterval ) {
					clearTimeout(activeTogglePollInterval);
					activeTogglePollInterval = null;
				}
				window.jQuery('.et_pb_module[data-agswc-active-toggle]').attr('data-agswc-active-toggle', null);

				if ( module.props && module.props.type && module.props.type.substring(0, 8) === 'ags_woo_' ) {
					var activeKey = module.props._key;
					var activeToggle = null;
					activeTogglePollInterval = setInterval(function() {
						var newActiveToggle = window.et_gb.jQuery('.et-fb-tabs__panel--active:first .et-fb-form__toggle-opened:first').data('name');
						if (newActiveToggle !== activeToggle || !window.jQuery('.et-module-' + activeKey + '[data-agswc-active-toggle]').length) {
							activeToggle = newActiveToggle;
							window.jQuery('.et-module-' + activeKey).attr('data-agswc-active-toggle', activeToggle ? activeToggle : null);
						}
					}, 500);
				}
				
			}
		);

		window.et_gb.wp.hooks.addAction(
			'et.builder.store.module.settings.close',
			'ags-wc-filters',
			function(module) {
				if ( activeTogglePollInterval ) {
					clearTimeout(activeTogglePollInterval);
					activeTogglePollInterval = null;
				}
				window.jQuery('.et_pb_module[data-agswc-active-toggle]').attr('data-agswc-active-toggle', null);
			}
		);
	});

	if (!window.ags_wc_filters_isInVisualBuilder) {
		// Initial page load
		onUrlChanged();
	}
});

/* @license
This file includes code from range-slider, with or without modifications
https://github.com/slawomir-zaziablo/range-slider
range-slider is licensed under the following license.
Unmodified source code can be found at ../../sources/range-slider/src/js/rSlider.js

MIT License

Copyright (c) 2017 Slawomir Zaziablo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
!function(){"use strict";var t=function(t){this.input=null,this.inputDisplay=null,this.slider=null,this.sliderWidth=0,this.sliderLeft=0,this.pointerWidth=0,this.pointerR=null,this.pointerL=null,this.activePointer=null,this.selected=null,this.scale=null,this.step=0,this.tipL=null,this.tipR=null,this.timeout=null,this.valRange=!1,this.values={start:null,end:null},this.conf={target:null,values:null,set:null,range:!1,width:null,scale:!0,labels:!0,tooltip:!0,step:null,disabled:!1,onChange:null,valuePrefix:''},this.cls={container:"rs-container",background:"rs-bg",selected:"rs-selected",pointer:"rs-pointer",scale:"rs-scale",noscale:"rs-noscale",tip:"rs-tooltip"};for(var i in this.conf)t.hasOwnProperty(i)&&(this.conf[i]=t[i]);this.init()};t.prototype.init=function(){return"object"===typeof this.conf.target?this.input=this.conf.target:this.input=document.getElementById(this.conf.target.replace("#","")),this.input?(this.inputDisplay=getComputedStyle(this.input,null).display,this.input.style.display="none",this.valRange=!(this.conf.values instanceof Array),!this.valRange||this.conf.values.hasOwnProperty("min")&&this.conf.values.hasOwnProperty("max")?this.createSlider():console.log("Missing min or max value...")):console.log("Cannot find target element...")},t.prototype.createSlider=function(){return this.slider=i("div",this.cls.container),this.slider.innerHTML='<div class="rs-bg"></div>',this.selected=i("div",this.cls.selected),this.pointerL=i("div",this.cls.pointer,["dir","left"]),(this.conf.scale&&(this.scale=i("div",this.cls.scale))),this.conf.tooltip&&(this.tipL=i("div",this.cls.tip),this.tipR=i("div",this.cls.tip),this.pointerL.appendChild(this.tipL)),this.slider.appendChild(this.selected),(this.conf.scale&&this.slider.appendChild(this.scale)),this.slider.appendChild(this.pointerL),this.conf.range&&(this.pointerR=i("div",this.cls.pointer,["dir","right"]),this.conf.tooltip&&this.pointerR.appendChild(this.tipR),this.slider.appendChild(this.pointerR)),this.input.parentNode.insertBefore(this.slider,this.input.nextSibling),this.conf.width&&(this.slider.style.width=parseInt(this.conf.width)+"px"),this.sliderLeft=this.slider.getBoundingClientRect().left,this.sliderWidth=this.slider.clientWidth,this.pointerWidth=this.pointerL.clientWidth,this.conf.scale||this.slider.classList.add(this.cls.noscale),this.setInitialValues()},t.prototype.setInitialValues=function(){if(this.disabled(this.conf.disabled),this.valRange&&(this.conf.values=s(this.conf)),this.values.start=0,this.values.end=this.conf.range?this.conf.values.length-1:0,this.conf.set&&this.conf.set.length&&n(this.conf)){var t=this.conf.set;this.conf.range?(this.values.start=this.conf.values.indexOf(t[0]),this.values.end=this.conf.set[1]?this.conf.values.indexOf(t[1]):null):this.values.end=this.conf.values.indexOf(t[0])}return this.createScale()},t.prototype.createScale=function(t){this.step=this.sliderWidth/(this.conf.values.length-1);if(this.conf.scale){for(var e=0,s=this.conf.values.length;e<s;e++){var n=i("span"),l=i("ins");n.appendChild(l),this.scale.appendChild(n),n.style.width=e===s-1?0:this.step+"px",this.conf.labels?l.innerHTML=this.conf.values[e]:0!==e&&e!==s-1||(l.innerHTML=this.conf.valuePrefix+this.conf.values[e]),l.style.marginLeft=l.clientWidth/2*-1+"px"}}return this.addEvents()},t.prototype.updateScale=function(){this.step=this.sliderWidth/(this.conf.values.length-1);for(var t=this.slider.querySelectorAll("span"),i=0,e=t.length;i<e;i++)t[i].style.width=this.step+"px";return this.setValues()},t.prototype.addEvents=function(){var t=this.slider.querySelectorAll("."+this.cls.pointer),i=this.slider.querySelectorAll("span");e(document,"mousemove touchmove",this.move.bind(this)),e(document,"mouseup touchend touchcancel",this.drop.bind(this));for(var s=0,n=t.length;s<n;s++)e(t[s],"mousedown touchstart",this.drag.bind(this));for(var s=0,n=i.length;s<n;s++)e(i[s],"click",this.onClickPiece.bind(this));return window.addEventListener("resize",this.onResize.bind(this)),this.setValues()},t.prototype.drag=function(t){if(t.preventDefault(),!this.conf.disabled){var i=t.target.getAttribute("data-dir");return"left"===i&&(this.activePointer=this.pointerL),"right"===i&&(this.activePointer=this.pointerR),this.slider.classList.add("sliding")}},t.prototype.move=function(t){if(this.activePointer&&!this.conf.disabled){var i=("touchmove"===t.type?t.touches[0].clientX:t.pageX)-this.sliderLeft-this.pointerWidth/2;return(i=Math.round(i/this.step))<=0&&(i=0),i>this.conf.values.length-1&&(i=this.conf.values.length-1),this.conf.range?(this.activePointer===this.pointerL&&(this.values.start=i),this.activePointer===this.pointerR&&(this.values.end=i)):this.values.end=i,this.setValues()}},t.prototype.drop=function(){this.activePointer=null},t.prototype.setValues=function(t,i){var e=this.conf.range?"start":"end";return this.conf.values.indexOf(t)>-1&&(this.values[e]=this.conf.values.indexOf(t)),i&&this.conf.values.indexOf(i)>-1&&(this.values.end=this.conf.values.indexOf(i)),this.conf.range&&this.values.start>this.values.end&&(this.values.start=this.values.end),this.pointerL.style.left=this.values[e]*this.step-this.pointerWidth/2+"px",this.conf.range?(this.conf.tooltip&&(this.tipL.innerHTML=this.conf.valuePrefix+this.conf.values[this.values.start],this.tipR.innerHTML=this.conf.valuePrefix+this.conf.values[this.values.end]),this.input.value=this.conf.values[this.values.start]+","+this.conf.values[this.values.end],this.pointerR.style.left=this.values.end*this.step-this.pointerWidth/2+"px"):(this.conf.tooltip&&(this.tipL.innerHTML=this.conf.values[this.values.end]),this.input.value=this.conf.values[this.values.end]),this.values.end>this.conf.values.length-1&&(this.values.end=this.conf.values.length-1),this.values.start<0&&(this.values.start=0),this.selected.style.width=(this.values.end-this.values.start)*this.step+"px",this.selected.style.left=this.values.start*this.step+"px",this.onChange()},t.prototype.onClickPiece=function(t){if(!this.conf.disabled){var i=Math.round((t.clientX-this.sliderLeft)/this.step);return i>this.conf.values.length-1&&(i=this.conf.values.length-1),i<0&&(i=0),this.conf.range&&i-this.values.start<=this.values.end-i?this.values.start=i:this.values.end=i,this.slider.classList.remove("sliding"),this.setValues()}},t.prototype.onChange=function(){var t=this;this.timeout&&clearTimeout(this.timeout),this.timeout=setTimeout(function(){if(t.conf.onChange&&"function"===typeof t.conf.onChange)return t.conf.onChange(t.input.value)},500)},t.prototype.onResize=function(){return this.sliderLeft=this.slider.getBoundingClientRect().left,this.sliderWidth=this.slider.clientWidth,this.updateScale()},t.prototype.disabled=function(t){this.conf.disabled=t,this.slider.classList[t?"add":"remove"]("disabled")},t.prototype.getValue=function(){return this.input.value},t.prototype.destroy=function(){this.input.style.display=this.inputDisplay,this.slider.remove()};var i=function(t,i,e){var s=document.createElement(t);return i&&(s.className=i),e&&2===e.length&&s.setAttribute("data-"+e[0],e[1]),s},e=function(t,i,e){for(var s=i.split(" "),n=0,l=s.length;n<l;n++)t.addEventListener(s[n],e)},s=function(t){var i=[],e=t.values.max-t.values.min;if(!t.step)return console.log("No step defined..."),[t.values.min,t.values.max];for(var s=0,n=e/t.step;s<n;s++)i.push(t.values.min+s*t.step);return i.indexOf(t.values.max)<0&&i.push(t.values.max),i},n=function(t){return!t.set||t.set.length<1?null:t.values.indexOf(t.set[0])<0?null:!t.range||!(t.set.length<2||t.values.indexOf(t.set[1])<0)||null};window.rSlider=t}();

})();

function ags_wc_filters_getDisplayType($filters) {
	if ( $filters.has('.ags-wc-filters-checkbox-list').length ) {
		return 'checkboxes_list';
	}
	if ( $filters.has('.ags-wc-filters-radio-button-list').length || $filters.has('.ags-wc-filters-tagcloud').length ) {
		return 'radio_buttons';
	}
	if ( $filters.has('.ags-wc-filters-dropdown-single').length ) {
		return 'dropdown_single_select';
	}
	if ( $filters.has('.ags-wc-filters-dropdown-multi').length ) {
		return 'dropdown_multi_select';
	}
	if ( $filters.has('.ags-wc-filters-search-container').length ) {
		return 'search';
	}
	if ( $filters.has('.ags-wc-filters-number-range-container').length ) {
		return 'number_range';
	}
	if ( $filters.has('.ags-wc-filters-stars-control').length ) {
		return 'stars';
	}
}

function ags_wc_filters_initFilters($filters) {

	var allCategoriesOptionText = jQuery("#allCategoriesOptionText").val();

	var $applyButton = jQuery(".ags-wc-filters-button-apply");

	var displayType = window.ags_wc_filters_getDisplayType($filters);
	var queryVar = $filters.data('ags-wc-filters-query-var');
	var $filtersContainer = $filters.closest('.ags_woo_products_filters');

	var $filtersRow = $filtersContainer.closest('.et_pb_row')[0];

	if (window.ags_wc_filters_isInVisualBuilder) {
		$filtersRow.style.zIndex = "10";
	} else {
		$filtersRow.style.zIndex = "3";
	}

	switch (displayType) {
		case 'checkboxes_list':
		case 'radio_buttons':
			$filters.find('.ags-wc-filters-list:first :checkbox, .ags-wc-filters-list:first :radio').change( function(ev) {
				if (!$applyButton.length && !ev.isTrigger) {
					window.ags_wc_filters_applyFilters($filtersContainer);
				}
			});
			break;

		case 'dropdown_single_select':
			/*-------------single select start---------------*/

			$filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-active a").click(function(ev) {
				$filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-dropdown-single-options").toggle();
				ev.stopPropagation();
			});

			$filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-dropdown-single-options li a").click(function(ev) {
				var label = jQuery(this).data('label');

				$filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-dropdown-single-options li a").removeClass("ags-wc-filters-active");
				jQuery(this).addClass("ags-wc-filters-active");
				var $active = $filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-active a span").text(label);
				$active.html( window.ags_wc_filters_processOptionLabel($active.html()) );
				$filters.find(".ags-wc-filters-dropdown-single .ags-wc-filters-dropdown-single-options").hide();

				if (!$applyButton.length && !ev.isTrigger) {
					window.ags_wc_filters_applyFilters($filtersContainer);
				}
			});

			/*-------------single select end---------------*/
			break;

		case 'dropdown_multi_select':
			/*-------------multi select start--------------*/

			$filters.find(".ags-wc-filters-dropdown-multi .ags-wc-filters-active span").click(function(ev) {
				$filters.find(".ags-wc-filters-dropdown-multi-options").toggle();
				ev.stopPropagation();
			});

			$filters.find(".ags-wc-filters-dropdown-multi-options li input").change(function(ev) {
				var $checkbox = $(this);
				$checkbox.closest('li').toggleClass('ags-wc-filters-active', $checkbox.prop('checked'));

				var sel = $filters.find('.ags-wc-filters-list:first :checked').map(function(_, el) {
					return jQuery(el).data("label");
				}).get();
				if(sel.length === 0){
				  $filters.find(".ags-wc-filters-dropdown-multi > .ags-wc-filters-active span").text( $filters.find('.ags-wc-filters-dropdown-multi:first').data('placeholder-text') );
				} else{
				  $filters.find(".ags-wc-filters-dropdown-multi > .ags-wc-filters-active span").text(sel.join(', '));
				}

				if (!$applyButton.length && !ev.isTrigger) {
					window.ags_wc_filters_applyFilters($filtersContainer);
				}
			});

			/*--------------multi select end ------------*/
			break;

		case 'search':

			function populateSearchSuggestions($container, data) {
				if (data.length) {
					var $suggestionsList = $container.find('.ags-wc-filters-search-suggestions:first').empty();
					if (!$suggestionsList.length) {
						var $suggestionsList = jQuery('<ul class="ags-wc-filters-search-suggestions">').appendTo(
							jQuery('<div class="ags-wc-filters-search-suggestions-container ags-wc-filters-hide-on-click">')
								.append('<div class="ags-wc-filters-dropdown-toggle"></div>')
								.appendTo($container)
						);
					}

					for (var i = 0; i < data.length; ++i) {
						jQuery('<li>').append(
							jQuery('<a>').attr({
								href: data[i].link,
								target: '_blank'
							}).text(data[i].label)
						).appendTo($suggestionsList);
					}

					$suggestionsList.parent().show();
				} else {
					$container.children('.ags-wc-filters-search-suggestions-container:first').hide();
				}
			}

			if ( window.ags_wc_filters_isInVisualBuilder && $filters.has('.ags-wc-filters-search-with-suggestions').length ) {
				populateSearchSuggestions(
					$filters.find('.ags-wc-filters-search-container:first'),
					[
						{
							// translators: placeholder product
							label: wp.i18n.__('Product One', 'divi-shop-builder'),
							link: '#'
						},
						{
							// translators: placeholder product
							label: wp.i18n.__('Product Two', 'divi-shop-builder'),
							link: '#'
						}
					]
				);

				$filters.find('.ags-wc-filters-search-suggestions-container:first').hide().removeClass('ags-wc-filters-hide-on-click').find('a').click(function() {
					return false;
				});
			}

			$filters.find('input[type="search"]:first')
				.on( 'input', function(ev) {
					if (!$applyButton.length && !ev.isTrigger) {
						window.ags_wc_filters_applyFiltersThrottled($filtersContainer);
					}
				})
				.on( 'focus input', function(ev) {
					var $field = jQuery(this);
					var $container = $field.closest('.ags-wc-filters-search-container');

					if ( !ev.isTrigger && !window.ags_wc_filters_isInVisualBuilder && $container.hasClass('ags-wc-filters-search-with-suggestions') ) {

						var query = $field.val();

						var suggestionsTimeout;
						if (suggestionsTimeout) {
							clearTimeout(suggestionsTimeout);
						}

						if (query) {
							suggestionsTimeout = setTimeout(function() {
								suggestionsTimeout = null;
								$.post(
									DiviWoocommercePagesFrontendData.ajaxUrl,
									{
										action: 'ags_wc_filters_search_suggestions',
										query: query
									},
									function(response) {
										if (response.success && response.data) {
											populateSearchSuggestions($container, response.data);
										}
									},
									'json'
								);
							}, 200);
						} else {
							$field.siblings('.ags-wc-filters-search-suggestions-container:first').hide();
						}
					}
				});

			break;

		case 'number_range':
			var $slider = $filters.find('.ags-wc-filters-slider:first');
			var $minInput = $filters.find('input[type="number"]:first');
			var $maxInput = $filters.find('input[type="number"]:last');

			var $queryPriceRange = jQuery('.ags-wc-filters-target:first .ags-divi-wc-query-price-range:first');
			if ($queryPriceRange.length) {
				if (!$minInput.data('min-default')) {
					$minInput.data({
						'min-default': $minInput.attr('min'),
						'max-default': $minInput.attr('max')
					});
				}
				if (!$queryPriceRange.data('max')) {
					var minValue = $minInput.data('min-default');
					var maxValue = $minInput.data('max-default');
				} else if ($queryPriceRange.data('max') - $queryPriceRange.data('min') < 3) {
					var minValue = Math.max(0, Math.floor($queryPriceRange.data('min')) - 1);
					var maxValue = Math.ceil($queryPriceRange.data('min')) + 1;
				} else {
					var minValue = Math.floor($queryPriceRange.data('min'));
					var maxValue = Math.ceil($queryPriceRange.data('max'));
				}

				$minInput.add($maxInput).attr({
					min: minValue,
					max: maxValue
				});
			}

			if ($slider.length) {

				$slider.siblings('.rs-container').remove();

				var minValue = parseInt($minInput.attr('min'));
				var maxValue = parseInt($minInput.attr('max'));
				var sliderOptions = {
					target: $slider[0],
					values: {
						min: minValue,
						max: maxValue
					},
					valuePrefix: $slider.closest('.ags-wc-filters-number-range-container').data('currency-symbol'),
					step: 1,
					range: true,
					scale: false,
					labels: false,
					tooltip: $minInput.hasClass('ags-wc-filters-hidden'),
					onChange: function(val) {
						if (!slider.hadFirstOnChange) {
							slider.hadFirstOnChange = true;
							return;
						}

						slider.isInOnChange = true;
						val = val.split(',');

						$minInput.val( parseInt(val[0]) === minValue ? '' : val[0] );
						$maxInput.val( parseInt(val[1]) === maxValue ? '' : val[1] ).trigger('input');

						if (!$applyButton.length) {
							window.ags_wc_filters_applyFiltersThrottled($filtersContainer);
						}
						slider.isInOnChange = false;
					}

				};

				var currentFromValue = $minInput.val();
				var currentToValue = $maxInput.val();

				if (currentFromValue.length || currentToValue.length) {
					sliderOptions.set = [
						currentFromValue.length ? parseInt(currentFromValue) : minValue,
						currentToValue.length ? parseInt(currentToValue) : maxValue
					];
				}

				var slider = new rSlider(sliderOptions);

				slider.setValues2 = function(from, to) {
					slider.setValues(from, to);
					clearTimeout(slider.timeout);
				}
			}

			$filters.find('input[type="number"]').on( 'input', function(ev) {

				var $container = jQuery(this).closest('.ags-wc-filters-number-range-container');
				var min = $container.find('input[type="number"]:first').val();
				var max = $container.find('input[type="number"]:last').val();

				if ($slider.length && !slider.isInOnChange) {
					slider.setValues2(
						min.length ? parseInt(min) : minValue,
						max.length ? parseInt(max) : maxValue
					);
				}

				if (!$applyButton.length && !ev.isTrigger) {
					window.ags_wc_filters_applyFiltersThrottled($filtersContainer);
				}

			});
			break;

		case 'stars':
			var $control = $filters.find('.ags-wc-filters-stars-control:first');
			var $stars = $control.find('.ags-wc-filters-stars:first');

			$stars.children()
				.click(function(ev) {
					var value = jQuery(this).index() + 1;

					$stars.children(':lt(' + value + ')').removeClass('ags-wc-filters-star-empty').addClass('ags-wc-filters-star-filled');
					$stars.children(':gt(' + ( value - 1 ) + ')').removeClass('ags-wc-filters-star-filled').addClass('ags-wc-filters-star-empty');

					$control.attr( 'data-value', value + ($control.hasClass('ags-wc-filters-stars-control-only') ? '' : '+') );

					if (!$applyButton.length && !ev.isTrigger) {
						window.ags_wc_filters_applyFilters($filtersContainer);
					}
				})
				.hover(function() {
					var value = jQuery(this).index() + 1;

					$stars.children(':lt(' + value + ')').addClass( 'ags-wc-filters-star-hover' );
					$stars.children(':gt(' + ( value - 1 ) + ')').removeClass( 'ags-wc-filters-star-hover' );
				});

			$stars.mouseout(function() {
				$stars.children().removeClass('ags-wc-filters-star-hover');
			});

			break;
	}
}