/*
Name: jQuery Simple Drop Down Plugin
Author: Etienne Fardet
Version: 1.0
*/

(function($){  

    $.simpledropdown = function(selector) {

        var speed = 550;

        $(selector).children("ul").addClass("dropdown");
        $("ul.dropdown>li:first-child").addClass("selected");
        $("ul.dropdown>li").not(".dropdown>li:first-child").addClass("drop").css('display', 'none');

        $(document).click(function() {
            // Close dropdown when its open and clicked elsewhere
            if($('li.drop').is(':visible')) {
                $('li.drop').slideUp(speed);
            }
        });

        $("ul.dropdown").click(function(event) {

            // Prevent event from closing the dropdown
            event.stopPropagation();

            var subitems = $(this).find(".drop ul li, .drop ul li a");
            var selecteditem = $(this).find(".selected");

            $('li.drop').slideToggle(speed, function() {
                subitems.click(function() {
                    var selection = $(this).text();
                    selecteditem.text(selection).fadeOut(5, function() {
                        if (jQuery.browser.msie) {
                            $(this).fadeIn(100);
                        } else {
                            $(this).fadeIn(400);
                        }
                    });
                    $('li.drop').hide();
                });
            });
        });

    };
    
})(jQuery); 

