
(function($) {

    var methods = {
        init : function(options) {
            var settings = $.extend( {
                'slide_speed' : 1000,
                'current_class' : 'current',
                'menu_root_class' : 'root'
            }, options);

            return this.each(function() {
                var $this = $(this),
                    data = $this.data('floatdrop');
                if (!data) {
                    $($this).ready(function() {
                        $('li.' + options['current_class'] + ' ul', $this).slideDown(options['slide_speed'])
                        $(' > li > a', $this).bind('click.floatdrop', function(event) {
                            event.preventDefault();
                            var sub_menus = $('ul.' + options['menu_root_class'] + ' > li > ul', $this.parent());
                            if (sub_menus.length > 0) {
                                sub_menus.slideUp(options['slide_speed'], function () {
                                    document.location = $(event.target).attr('href');
                                });
                            } else {
                                document.location = $(event.target).attr('href');
                            };
                        });
                    });
                    $(this).data('floatdrop', 'initialized');
                }
            });
        },
        destroy : function() {
            return this.each(function() {
                var $this = $(this),
                    data = $this.data('floatdrop');
                $this.unbind('.floatdrop');
                $this.removeData('floatdrop');
            })
        }
    };

    $.fn.floatdrop = function( method ) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || ! method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' +  method + ' does not exist on jQuery.floatdrop');
        }
    };

})(jQuery);


