(function($) {
$.fn.orphans = function(){
    var txt = [];
    this.each(function(){$.each(this.childNodes, function() {
        if (this.nodeType == 3 && $.trim(this.nodeValue)) txt.push(this)
    })}); 
    return $(txt);
};
})(jQuery);
$(function() {
    $('div.categories ul.children').parent().find('a:first').wrap('<a href="#" title="expand/collapse"></a>');
    $('div.categories ul').find('ul.children').hide();
    $('div.categories ul.children').parent().find('a:first').click(function() {
        $(this).parent().toggleClass('open').siblings().removeClass('open')
		.end().find('ul').slideToggle(400)
		.end().siblings('li').find('ul:visible').slideToggle(800);
        return false;
    });
	$('div.categories ul.children li a').click(function() {
        return true;
    });
});
