1jQuery(function () {
2    'use strict';
3
4    var $searchForm = jQuery('.search-results-form');
5    if (!$searchForm.length) {
6        return;
7    }
8
9    var $toggleAssistanceButton = jQuery('<button>')
10        .addClass('toggleAssistant')
11        .attr('type', 'button')
12        .attr('aria-expanded', 'false')
13        .text(LANG.search_toggle_tools)
14        .prependTo($searchForm.find('fieldset'))
15    ;
16
17    $toggleAssistanceButton.on('click', function () {
18        jQuery('.advancedOptions').toggle(0, function () {
19            var $me = jQuery(this);
20            if ($me.attr('aria-hidden')) {
21                $me.removeAttr('aria-hidden');
22                $toggleAssistanceButton.attr('aria-expanded', 'true');
23                DokuCookie.setValue('sa', 'on');
24            } else {
25                $me.attr('aria-hidden', 'true');
26                $toggleAssistanceButton.attr('aria-expanded', 'false');
27                DokuCookie.setValue('sa', 'off');
28            }
29        });
30    });
31
32    if (DokuCookie.getValue('sa') === 'on') {
33        $toggleAssistanceButton.trigger('click');
34    }
35
36    $searchForm.find('.advancedOptions .toggle div.current').on('click', function () {
37        var $me = jQuery(this);
38        $me.parent().siblings().removeClass('open');
39        $me.parent().siblings().find('ul:first').attr('aria-expanded', 'false');
40        $me.parent().toggleClass('open');
41        if ($me.parent().hasClass('open')) {
42            $me.parent().find('ul:first').attr('aria-expanded', 'true');
43        } else {
44            $me.parent().find('ul:first').attr('aria-expanded', 'false');
45        }
46    });
47
48});
49