$(function() {
	var search = $('#js-regional-courts-search'),
		submenuItems = $('.js-regional-courts-menu-item');

	if (search.length) {
		search.keyup(function () {
			var search_val = $(this).val(),
				linkSubmenu = submenuItems.find('.regional-courts-menu-link');
			
			if (search_val.length > 2) {
				linkSubmenu.each(function() {
					var self = $(this),
						in_search = self.text(),
						reg = new RegExp(search_val, 'gi');
					
					self
						.parent()
						.toggleClass(
							'g-hidden', 
							(in_search.search(reg) == -1)
						);
				});
			} else {
				linkSubmenu.each(function() { 
					$(this).parent().removeClass('g-hidden'); 
				});
			}
		});
	}
});