$(document).ready(function() 
    { 
		$('li > ul').each(function(i) {
		        // Find this list's parent list item.
		        var parent_li = $(this).parent('li');
		        // Temporarily remove the list from the
		        // parent list item, wrap the remaining
		        // text in an anchor, then reattach it.
		        var sub_ul = $(this).remove();
		        parent_li.wrapInner('<a/>').find('a').addClass("folderlink").click(function() {
		            // Make the anchor toggle the leaf display.
		            sub_ul.toggle();
					$(this).toggleClass("collapsed");				
		        });
		        parent_li.append(sub_ul);
		    });

		    // Hide all lists except the outermost.
		    $('ul ul').hide();
    } 
);
