KRACOEUS-7196 adding jquery and javascript to hide/show the medusa tree

I have a bug with the Javascript/jQuery.  The first time you open the medusa page, the medusa tree is expanded, and you can't toggle it to closed.  The second time you open the medusa page, the the medusa tree is collapsed, and you can toggle it open and close as the user likes.  This is the expected behavior.  If you open the medusa page a third time, the tree to closed, but you can't toggle it.  Any ideas on how to fix this?