1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/////////////////////////////////////////////////////////////////////////////////////////////////////////
    //FAQ ACCORDION
    /////////////////////////////////////////////////////////////////////////////////////////////////////////

    function initFaq() {

        if (mainContainer.find('section').hasClass('faq')) {

            var faqItem = $('.faq').find('article');
            var toggle = $('.faq').attr('data-toggle') == "true" ? true: false;
			
			//get window url, get question number and parse to zero based
			var href = window.location.href;
			var param = parseInt(href.split('q=')[1], 10)-1;
			

            faqItem.each(function(i) {
								  
                var t = $(this);
                var q = t.find('.question');
                var p = t.find('p');
                
				
                p.css({
                    display: 'none'
                });
				
				
				//check if window url param corresponds to a question and open if so
				if(i == param){
				  q.addClass('selected');
                  p.slideDown(500);
				}
				

                q.click(function() {

                    var qs = $(this);

                    //if toggle option is on, remove previous section
                    if (toggle && !qs.hasClass('selected')) {

                        $('.faq .question').each(function() {
                            var qItem = $(this);
                            var p = qItem.parent().find('p');
                            if (qItem.hasClass('selected') && qItem != qs) {
                                qItem.removeClass('selected');
                                p.slideUp(500);
                            }

                        });

                    }

                    //open current slide
                    if (qs.hasClass('selected')) {
                        qs.removeClass('selected');
                        p.slideUp(500);
                        return;
                    } else {
                        qs.addClass('selected');
                        p.slideDown(500);
                    }

                });

            });

        };

    }