// ==PREPROCESSOR==
// @name "Menu Sample"
// @author "T.P Wang / marc2003"
// @import "%fb2k_component_path%docs\flags.txt"
// ==/PREPROCESSOR==

function on_mouse_lbtn_down(x, y) {
	var _context = fb.CreateContextMenuManager();
	var _basemenu = window.CreatePopupMenu();
	var _child = window.CreatePopupMenu();
	var idx;
	
	// MF_STRING is defined in docs\flags.txt
	// start index at 1, NOT 0
	_basemenu.AppendMenuItem(MF_STRING, 1, "item1");
	_basemenu.AppendMenuItem(MF_STRING, 2, "item2");
	_child.AppendTo(_basemenu, MF_STRING, "Now Playing");
	
	_context.InitNowPlaying();
	_context.BuildMenu(_child, 3, -1);
	
	idx = _basemenu.TrackPopupMenu(x, y);
	
	switch (idx) {
		case 0: //user dismissed menu by clicking elsewhere. that's why you can't use 0 when building menu items
			break;
		case 1:
			fb.ShowPopupMessage("You have chose item1.");
			break;
		case 2:
			fb.ShowPopupMessage("Ok, item2 is clicked");
			break;
		default:
			_context.ExecuteByID(idx - 3);
			break;
	}
	_basemenu.Dispose();
	_child.Dispose();
	_context.Dispose();
}
