// imagine the accordion is started like this:
$("#accordion").accordion({ header: 'h5', collapsible: true , active: false});
// this gets you the index of open accordion [0.....n]
$("#accordion h5").index($("#accordion h5.ui-state-active"));
// let's save that index.. and use it to activate/deactivate the tab
n = $("#accordion h5").index($("#accordion h5.ui-state-active"));
$('#accordion').accordion('activate', n);