/**
 * @author Fstrauss <florian.strauss@wgo-online.com>
 */
(function($){
    $.categories = function(el, options){
		
        var base = this;


        base.$el = $(el);
        base.el = el;

        // Add a reverse reference to the DOM object
        base.$el.data("categories", base);

        base.init = function(){
            base.options = $.extend({},$.categories.defaultOptions, options);

			base.hideAll();
			base.showFirst();
			base.setEvents();
        };
		base.showFirst = function() {
			base.$el
				.children('li.selected')
				.children('ul')
				.show();

		}
		base.hideAll = function() {
			base.$el
				.children('li')
				.children('ul')
				.hide();
		}
		base.slideUpAll = function() {
			base.$el
				.children('li')
				.children('ul')
				.slideUp( base.options.speed);
		}
		base.setEvents = function() {
			base.$el
				.children('li')
				.find('a.level-1')
				.click(function() {
					base.slideUpAll();
					
					$(this).next()
						.slideDown(base.options.speed);

					return false;
				})

		}
		

        // Run initializer
        base.init();
    };

    $.categories.defaultOptions = {
		speed: 'normal'
    };

    $.fn.categories = function(options){

        return this.each(function(){
            (new $.categories(this, options));
        });
    };

})(jQuery);
