/***********************************************************
# jquery.menu_popup.js Dynamic Recursive Popup Animator
# Django 1.1 version for use with "menus" app
# Copyright (C) 2009 Stephen DeGrace
# stephen@infiniterecursion.ca
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
************************************************************/

/**
This is a refactoring of the original menu_popup.js script to use jQuery
(www.jquery.com). The original version descended the DOM looking for the
ULs containing menus based on their class then descended them and attched
closures to the LIs that contained submenus. The current version uses
jQuery selectors and events and is written as a plugin.

TO USE:

Load the jquery.menu_popup.js library after the jQuery library.
Select the menus in your document ready function and call the popupMenus()
function on them.
**/

(function ($) {
    $.fn.popupMenus = function (animation) {            
        return this.each( function () {
            // Get the ULs inside the main UL which are children of LIs
            $("li > ul", this).each( function () {
                // Bind hover event to the LI parent of each UL
                var UL = this;
                $(this).closest('li').hover( function () { // Over
                    $(UL).show(animation);
                }, function () { // Out
                    $(UL).hide(animation);
                });
            });
        });
    };
})(jQuery);
