(function($) {
$.fn.collapsor = function(settings) {
    $('#mb').hide();
	// override default settings
	settings = $.extend({}, $.fn.collapsor.defaults, settings);
	var triggers = this;
	// for each element
	return this.each(function() {
		// occult the collapsing elements
		$(this).find('+ ' + settings.sublevelElement).hide();
		//show the opened
		if($(this).hasClass(settings.openClass)){
			$(this).find('+ ' + settings.sublevelElement).show();
            $('#mb').show();
		}
		// event handling
	  $(this).click(function()
       {
			// if the new active have sublevels
			if ($(this).next().is(settings.sublevelElement)){

            // blur and add the open class to the clicked
			$(this).blur().toggleClass(settings.openClass);

            // close others

            if (settings.closeOthers == true)
            {
			    $(this).parent().parent().children().find('.'+settings.openClass).not(this).removeClass(settings.openClass).next().animate({height:'toggle', opacity:'toggle'}, settings.speed, settings.easing);
			}

            // toggle the clicked

            $(this).next().animate({height:'toggle', opacity:'toggle'}, settings.speed, settings.easing);

            //$('#mb').slideToggle(settings.speed);

            if($(this).hasClass(settings.openClass)){
            $('#mb').show(settings.speed);
		    } else $('#mb').hide(settings.speed);

            return false;

			}
	   });
	});
};
// default settings
$.fn.collapsor.defaults = {
	openClass:'open',
	sublevelElement: 'ul',
	closeOthers: false,
	speed: 300,
	easing: 'swing'
};
})(jQuery);

