(function ($) {

    $.fn.Submenu = function (method) {

        return this.each(function () {

            var self = $(this);

            if (method == 'click') {

                self.click(function () {
                    $(this).parent().find(".submenu").toggle();
                });

                $(document).click(function (event) {
                    if ($(event.target).parents().index($("#btnLogin")) == -1) {
                        if ($(event.target).parents().index($("#slideshow")) == -1) {
                            self.parent().find(".submenu").hide();
                        }
                    }
                });

            } else {
                self.find("ul li").hover(function () {
                    $(this).find(".submenu").show();
                }, function () {
                    $(this).find(".submenu").hide();
                });
            }
        });
    }

})(jQuery);
