{% comment %}
<!--
  Copyright (C) 2011 University of Dundee & Open Microscopy Environment.
  All rights reserved.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
{% endcomment %}

<script type="text/javascript">


    $(document).ready(function(){

        $('body').click(function(event) {
            if (!$(event.target).hasClass("scriptButton")) {
                OME.hideScriptList();
            }
        });
        // Loading Scripts with AJAX for drop-down menu, (only the first time we click)

        // handles clicking on a script (if href is not '#')
        $("#scriptList.sub_menu").on('click', 'a', OME.openScriptWindow);

        $("#scriptList.sub_menu").on('click', 'a', function(event) {
            var $a = $(event.target),
                script_url = $a.attr('href');
            if (script_url != "#") {
                // Clicked on script - handled by OME.openScriptWindow above
                $("#scriptList").hide();
                return false;
            }

            // we have clicked on <a> within a <li>, with sibling <ul>
            var $li = $a.parent(),
                $ul = $li.children('ul');
            if ($li.hasClass('menu_back')) {
                $li.parent().parent().siblings().show();
                $li.parent().hide();
                $li.parent().siblings('a').show();
            } else {
                $ul.show();
                $li.siblings().hide();
                $a.hide();
            }
        });

        $("#scriptButton").click(
            {webindex: "{% url 'webindex' %}"},
            OME.showScriptList
        );
    });

</script>
