function button(id,name,x,y,w_,h_,dis_,subtitle)
	local unitid = MF_create("hud_button")
	local dis = dis_ or 0
	local w = w_ or 1
	local h = h_ or 1
	
	MF_setpos(unitid,x,y)
	MF_setlayer(unitid,1)
	MF_setstring(unitid,TYPE,id)
	MF_setstring(unitid,NAME,name)
	MF_setstring(unitid,MENU,menu[#menu])
	MF_setstring(unitid,SUBTITLE,subtitle or "")
	MF_setvalue(unitid,B_DISABLED,dis)
	MF_setscale(unitid,w,h)
	
	return unitid
end

function button_press(id_,menuname)
	local data = menulist[menuname] or {}
	
	local id = "button_" .. id_
	
	if (data["button_any"] ~= nil) then
		local func = data["button_any"]
		func(id_,menuname)
	end
	
	if (data[id] ~= nil) then
		local func = data[id]
		func(id_,menuname)
	end
end

function openmenu(name)
	local oldmenu = menu[#menu]
	MF_clearbuttons(oldmenu)
	
	if (menulist[oldmenu] ~= nil) then
		local data = menulist[oldmenu]
		
		if (data.close ~= nil) then
			data.close(oldmenu)
		end
	end
	
	menu[#menu] = name
	
	if (menulist[name] ~= nil) then
		local data = menulist[name]
		
		if (data.init ~= nil) then
			data.init(name)
		end
	end
	
	MF_setstring(GDATA,MENU,menu[#menu])
end

function submenu(name,hide_)
	local oldmenu = menu[#menu]
	MF_disablebuttons(oldmenu,1)
	
	local hide = hide_ or false
	if hide then
		MF_hidebuttons(oldmenu,1)
	end
	
	if (menulist[oldmenu] ~= nil) then
		local data = menulist[oldmenu]
		
		if (data.leave ~= nil) then
			data.leave(oldmenu)
		end
	end
	
	table.insert(menu, name)
	
	if (menulist[name] ~= nil) then
		local data = menulist[name]
		
		if (data.init ~= nil) then
			data.init(name)
		end
	end
	
	MF_setstring(GDATA,MENU,menu[#menu])
end

function closemenu()
	local oldmenu = menu[#menu]
	MF_clearbuttons(oldmenu)
	
	if (menulist[oldmenu] ~= nil) then
		local data = menulist[oldmenu]
		
		if (data.close ~= nil) then
			data.close(oldmenu)
		end
	end
	
	table.remove(menu, #menu)
	
	if (#menu > 0) then
		local name = menu[#menu]
		MF_disablebuttons(name,0)
		MF_hidebuttons(name,0)
		
		if (menulist[name] ~= nil) then
			local data = menulist[name]
			
			if (data.back ~= nil) then
				data.back(name)
			end
		end
	else
		MF_alert("Menu is empty, shouldn't happen")
		menu = {"init"}
		openmenu("main")
	end
	
	MF_setstring(GDATA,MENU,menu[#menu])
end