Vertical dropdown menu; return to original state?

Hello, I want to make a mune of “x” buttons, and when I click on those butten the menu grows and subbuttons become visible. There is only one thing that I cant yet do: namely when the menu is enlarged and I press on another button, the menu has to return smoothly into its original state first and then perform the second animation. Ive made a couple of pictures to graphically display the “problem”:

This is the original state

Then when I click number one the menu should look something like this:

Button I has moved upward and buttons II and III have gone slightly downward. The problem however is this: when I now press the second button I want my menu to return into its original state first before going to this state:

I have no idea how to do this and I hope somebody can help me, because it looks like a promising menu to me ;)…