You already have functionality built in. All you have to do is generate the menu, look at the code, figure out what elements/classes/ids are there and just apply current functionality to appropriate elements.
Don’t worry about asking questions! It’s the reason this place exists.
It’s always hard before it’s easy. Don’t get frustrated.