jQuery(document).ready(function() {

    $('.switch').click(function() {
        if (jQuery(this).parent().hasClass("expanded")) {
            jQuery(this).next().hide('fast', function() {
                jQuery(this).parent().removeClass("expanded");
            });
        }

        else {
            var expandChildCount = 0;
            var children = jQuery(this).parent().children().each(function() {
                jQuery(this).children('ul').each(function() {
                    jQuery(this).css({ display: 'block' });
                    expandChildCount++;
                });
            });
            if (expandChildCount > 0) {
                jQuery(this).next().show('fast');
            }
            jQuery(this).parent().addClass("expanded");
        }

        return true;
    });

});