/*
Name: jQuery Simple Drop Down Plugin
Author: Etienne Fardet
Version: 1.2
*/

(function ($) {
    $.simpledropdown = function (selector) {

        $(selector).children("ul").addClass("dropdown");
        $("ul.dropdown>li:first-child").addClass("selected");
        $("ul.dropdown>li").not(".dropdown>li:first-child").addClass("drop");

        // Make sure we only do it for the selector just in case it's ajax.
        // KNP original $("ul.dropdown").click(function() {
        $(selector + " ul.dropdown").click(function (e) {
            var subitems = $(this).find(".drop ul li");
            var selecteditem = $(this).find(".selected");
            subitems.slideToggle("fast", function () {

                subitems.click(function (e) {
                    var selection = $(this).text();
                    selecteditem.text(selection).fadeOut(2, 'fast',function () {
                        if (jQuery.browser.msie) {
                            $(this).fadeIn(100);
                        } else {
                            $(this).fadeIn(400);
                        }
                    });

                    e.stopPropagation();
                });
            });

            e.stopPropagation();
        });

      

    };
})(jQuery); 


$(document).click(function(event){
     $(this).find(".drop ul li:visible").slideUp();
});

$(document).keypress(function(event){
 if (event.keyCode == 27) {
               $(this).find(".drop ul li:visible").slideUp();
            }
     
});

