{# most, if not all javascripts should go here
   this template is included at the very bottow of the
   main template "base.html"
#}
<div id="no-javascript">
    <noscript class="noscript">
        {% trans app_name = settings.APP_SHORT_NAME %}Please note: {{ app_name }} requires javascript to work properly, please enable javascript in your browser, <a href="{{ noscript_url }}">here is how</a>{% endtrans %}
    </noscript>
    <script type="text/javascript">
        //IE fix to hide the red margin
        var noscript = document.getElementsByTagName('noscript')[0];
        noscript.style.padding = '0px';
        noscript.style.backgroundColor = 'transparent';
    </script>
</div>
{# this section cannot be compressed because lots of data is runtime #}
<script type="text/javascript">
    askbot['urls']['mark_read_message'] = '{{ url('read_message') }}';
    askbot['urls']['get_tags_by_wildcard'] = '{{ url('get_tags_by_wildcard') }}';
    askbot['urls']['get_tag_list'] = '{{ url('get_tag_list') }}';
    askbot['urls']['follow_user'] = '/followit/follow/user/{{ '{{' }}userId{{ '}}' }}/';
    askbot['urls']['unfollow_user'] = '/followit/unfollow/user/{{'{{'}}userId{{'}}'}}/';
    askbot['urls']['user_signin'] = '{{ settings.LOGIN_URL }}';
    askbot['urls']['getEditor'] = '{{ url('get_editor') }}';
    {% if settings.MULTILINGUAL %}
        askbot['urls']['translateUrl'] = '{{ url('translate_url') }}';
    {% endif %}
    askbot['urls']['apiGetQuestions'] = '{{ url('api_get_questions') }}';
    askbot['urls']['ask'] = '{{ url('ask') }}';
	askbot['urls']['questions'] = '{{ url('questions') }}';
    askbot['settings']['groupsEnabled'] = {{ settings.GROUPS_ENABLED|as_js_bool }};
    askbot['settings']['static_url'] = '{{ settings.STATIC_URL }}';
    askbot['settings']['minSearchWordLength'] = {{ min_search_word_length }};
    askbot['settings']['mathjaxEnabled'] = {{ settings.ENABLE_MATHJAX|as_js_bool }};
    askbot['settings']['sharingSuffixText'] = '{{ settings.SHARING_SUFFIX_TEXT|escape }}';
    askbot['settings']['errorPlacement'] = 'after-label';
    askbot['data']['maxCommentLength'] = {{ settings.MAX_COMMENT_LENGTH }};
    askbot['settings']['editorType'] = '{{ settings.EDITOR_TYPE }}';
    {% if settings.EDITOR_TYPE == 'tinymce' %}
        askbot['settings']['tinyMCEConfigJson'] = '{{ settings.TINYMCE_CONFIG_JSON|escapejs }}';
    {% endif %}
    askbot['settings']['commentsEditorType'] = '{{ settings.COMMENTS_EDITOR_TYPE|escapejs }}';
    askbot['messages']['askYourQuestion'] = '{{ settings.WORDS_ASK_YOUR_QUESTION|escapejs }}';
    askbot['messages']['acceptOwnAnswer'] = '{{ settings.WORDS_ACCEPT_OR_UNACCEPT_OWN_ANSWER|escapejs }}';
    askbot['messages']['followQuestions'] = '{{ settings.WORDS_FOLLOW_QUESTIONS|escapejs }}';
    {% if settings.ALLOWED_UPLOAD_FILE_TYPES %}
        askbot['settings']['allowedUploadFileTypes'] = [
            "{{ settings.ALLOWED_UPLOAD_FILE_TYPES|join('", "')|replace('.','') }}"
        ];
    {% else %}
        askbot['settings']['allowedUploadFileTypes'] = [];
    {% endif %}
    askbot['data']['haveFlashNotifications'] = {{ user_messages|as_js_bool }};
    askbot['data']['activeTab'] = '{{ active_tab }}';
    askbot['settings']['csrfCookieName'] = '{{ settings.CSRF_COOKIE_NAME }}';
    {% if search_state %}
        askbot['data']['searchUrl'] = '{{ search_state.query_string()|escapejs }}';
    {% else %}
        askbot['data']['searchUrl'] = '';
    {% endif %}
</script>
{# everything below until the custom js and google analytics is compressable #}
<form name="scroll-pos-form"><input id="scroll-mem" type="text" style="display: none;"/></form>
{% compress js %}
    <script type="text/javascript" src="{{ '/jslib/jquery-1.7.2.min.js'|media }}"></script>
    <script type="text/javascript" src="{{ '/bootstrap/js/bootstrap.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/jslib/timeago.js'|media }}"></script>
    <!-- History.js -->
    <script type='text/javascript' src="{{ '/jslib/jquery.history.js'|media }}"></script>
    <!-- Utils.js -->
    <script type='text/javascript' src="{{ '/js/utils.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/scroll_memory.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/q_sutils.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/wrapped_element.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/wait_icon.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/paginator.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/limited_width_image.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/one_shot_form.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/link.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/widget.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/tipped_input.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/flash_alert.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/alert_box.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/simple_content.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/simple_control.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/post_expander.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/edit_link.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/comment_convert_link.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/delete_icon.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/modal_dialog.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/confirm_dialog.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/file_upload_dialog.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/text_property_editor.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/toggle.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/ajax_toggle.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/dropdown_select.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/box_item_content.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/select_box_item.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/select_box.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/group_dropdown.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/tag.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/hover_card.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/perms_hover_card.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/show_perms_trigger.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/autocompleter.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/js/utils/lang_nav.js'|media }}"></script>

    <script type='text/javascript' src="{{ '/jslib/se_hilite.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/jslib/json.js'|media }}"></script>
    <script type='text/javascript' src="{{ '/jslib/jquery-fieldselection.js'|media }}"></script>
    {% if settings.USE_ASKBOT_LOGIN_SYSTEM and use_login_page == False %}
        <script type="text/javascript" src="{{ '/js/jquery-openid/jquery.authenticator.js'|media }}"></script>
    {% endif %}
    <!-- End Utils.js -->
    <script type="text/javascript" src="{{ '/js/searchbar/drop_menu.js'|media }}"></script>
    <script type="text/javascript" src="{{ '/js/searchbar/tag_warning_box.js'|media }}"></script>
    <script type="text/javascript" src="{{ '/js/searchbar/full_text_search.js'|media }}"></script>
    <script type="text/javascript" src="{{ '/js/searchbar/tag_search.js'|media }}"></script>
{% endcompress %}
<script type="text/javascript">
    /*<![CDATA[*/
    $('.mceStatusbar').remove();//a hack to remove the tinyMCE status bar
    $(document).ready(function(){
        // focus input on the search bar endcomment
        var activeTab = askbot['data']['activeTab'];
        if (inArray(activeTab, ['users', 'questions', 'tags', 'badges'])) {
            var searchInput = $('#keywords');
        } else if (activeTab === 'ask') {
            var searchInput = $('#id_title');
        } else {
            var searchInput = undefined;
            animateHashes();
        }

        var wasScrolled = $('#scroll-mem').val();
        if (searchInput && !wasScrolled) {
            searchInput.focus();
            putCursorAtEnd(searchInput);
        }

        var haveFullTextSearchTab = inArray(activeTab, ['questions', 'badges', 'ask']);
        var haveUserProfilePage = $('body').hasClass('user-profile-page');
        if ((haveUserProfilePage || haveFullTextSearchTab) && searchInput && searchInput.length) {
            var search = new FullTextSearch();
            askbot['controllers'] = askbot['controllers'] || {};
            askbot['controllers']['fullTextSearch'] = search;
            search.setSearchUrl(askbot['data']['searchUrl']);
            if (activeTab === 'ask') {
                search.setAskButtonEnabled(false);
            }
            search.decorate(searchInput);
        } else if (activeTab === 'tags') {
            var search = new TagSearch();
            search.decorate(searchInput);
        }

        if (askbot['data']['userIsAdminOrMod']) {
            $('body').addClass('admin');
        }
        if (askbot['settings']['groupsEnabled']) {
            askbot['urls']['add_group'] = "{{ url('add_group') }}";
            var group_dropdown = new GroupDropdown({{ group_list }});
            $('.groups-dropdown').append(group_dropdown.getElement());
        }
        var userRep = $('#userToolsNav .reputation');
        if (userRep.length) {
            var showPermsTrigger = new ShowPermsTrigger();
            showPermsTrigger.decorate(userRep);
        }
    });
    if (askbot['data']['haveFlashNotifications']) {
        $('#validate_email_alert').click(function(){notify.close(true)})
        notify.show();
    }

    var langNav = $('.lang-nav');
    if (langNav.length) {
        var nav = new LangNav();
        nav.decorate(langNav);
    }
    /*]]>*/
</script>
{% include "meta/custom_javascript.html" ignore missing %}
{# stuff below should not be compressed #}
{% if settings.ENABLE_MATHJAX %}
    {# we don't want to load mathjax just in case, only if it is really enabled #}
    <script type='text/javascript' src="{{settings.MATHJAX_BASE_URL}}/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
        if (typeof MathJax != 'undefined') {
            MathJax.Hub.Config({
                extensions: ["tex2jax.js"],
                jax: ["input/TeX","output/HTML-CSS"],
                tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
            });
        } else {
            console.log('Could not load MathJax');
        }
    </script>
{% endif %}
{% if settings.USE_CUSTOM_JS %}
<script src="{{ url('custom_js') }}?v={{ settings.MEDIA_RESOURCE_REVISION }}"
    type="text/javascript"
></script>
{% endif %}
{% if settings.GOOGLE_ANALYTICS_KEY %}
<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker('{{ settings.GOOGLE_ANALYTICS_KEY }}');
    pageTracker._trackPageview();
    } catch(err) {}
</script>
{% endif %}
