You want to use the jQuery accordion API, such that it is not tied to click but actual toggle of accordion.
jQuery().ready(function () {
jQuery("#accordion").accordion({
header: "h3",
collapsible: true,
active: false,
heightStyle: "content",
navigation: true,
activate: function( event, ui ) {
ui.newHeader.find('span').toggle();
ui.oldHeader.find('span').toggle();
}
});
});