function OnMenuItemInitControl(self)
	local attr = self:GetAttribute()
	local textObj = self:GetControlObject("menuitem.text")
	textObj:SetText(attr.Text)
end

function OnMenuItemControlMouseEnter(self)
	local bkg = self:GetControlObject("menuitem.bkg")
	bkg:SetVisible(true)
end

function OnMenuItemControlMouseLeave(self)
	local bkg = self:GetControlObject("menuitem.bkg")
	bkg:SetVisible(false)
end

function OnMenuItemLButtonUp(self)
	self:FireExtEvent("OnClick")
	self:GetOwner():GetBindHostWnd():EndMenu()
end

function OnTransprentClick(self)
	local app = XLGetObject("Wizard.App")
	
	local opaque = app:GetInt("ConfigGraphics", "ConfigGraphics_MainWndOpaque", 0)
	if opaque == 0 then
		opaque = 1
	else
		opaque = 0
	end
	
	app:SetInt("ConfigGraphics", "ConfigGraphics_MainWndOpaque", opaque)
end

function OnPlayClick(self)
		--目录节点则播放第一个，否则重新播放
		local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
		local hostwnd = hostwndManager:GetHostWnd("Player.Wnd")
		local objtree = hostwnd:GetBindUIObjectTree()
		local tree = objtree:GetUIObject("treeview")
		local btnstop = objtree:GetUIObject("btnstop")
		btnstop:FireExtEvent("OnClick")
		local item = tree:GetSelected()
		if item.level == 1 then --目录
			if item.children[1] ~= nil then
				tree:SetSelected(item.children[1], true)
				tree:SetExpand(item, true, true)
			end
		end
		tree:FireExtEvent("OnDoubleClicked", tree:GetSelected().obj)
end

function OnDelClick(self)
		local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
		local hostwnd = hostwndManager:GetHostWnd("Player.Wnd")
		local objtree = hostwnd:GetBindUIObjectTree()
		local tree = objtree:GetUIObject("treeview")
		local item = tree:GetSelected()
		if item.level == 1 then
			if myClass==nil then
			myClassFactory = XLGetObject("Rola.MyClass.Factory")
			myClass = myClassFactory:CreateInstance()
			end
			myClass:RemoveSong(item.data)
			tree:RemoveItem(item)
		end
end

function OnClearClick(self)
		local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
		local hostwnd = hostwndManager:GetHostWnd("Player.Wnd")
		local objtree = hostwnd:GetBindUIObjectTree()
		local tree = objtree:GetUIObject("treeview")
		--移除全部
		if myClass==nil then
			myClassFactory = XLGetObject("Rola.MyClass.Factory")
			myClass = myClassFactory:CreateInstance()
		end
		local root = tree:GetAttribute().root
		for i=1,#root.children do
			myClass:RemoveSong(root.children[i].data)
		end
		tree:Clear()
end

function OnAlphaLButtonDown(self, x, y)
	local left, top, right, bottom = self:GetObjPos()
	local alpha = x/(right - left) * 255
	if alpha < 5 then
		alpha = 5
	elseif alpha > 255 then
		alpha = 255
	end
	
	local app = XLGetObject("Wizard.App")
	app:SetInt("ConfigGraphics", "ConfigGraphics_MainWndAlpha", alpha)
end

function OnPopupMenu(self)
end