You are clicking two times because you used a flip flop i think.
And you probably are opening the submenus without closing the already opened.
you can use array to list your widget buttons or boxes.
lets say you have Sub_1 _sub_2 and Sub_3
When clicked a Submenu category you want to :
Hide all Sub- but X that must be shown,
and doing it, you just check if they are alredy hidden or visile, otherwise do nothing.
A custom event like:
Active Sub (2)
Loop all Sub and get index, if index is == to (2)
Yes? check if already visible, if not , set it visible
No? check if already hidden, if not, set it hidden