
function create_button(screen, up, over, down, name, pos_x, pos_y, pos_z)
    local spr_up = screen:GetObject(up):GetAnimationPtr();
	screen:GetObject(up):SetVisible(false);
	local spr_over = screen:GetObject(over):GetAnimationPtr();
	screen:GetObject(over):SetVisible(false);
	local spr_down = screen:GetObject(down):GetAnimationPtr();
	screen:GetObject(down):SetVisible(false);
	local button = CreateButton(spr_up, spr_over, spr_down, name, screen);
	button:SetXY(pos_x, pos_y);
	button:SetZ(pos_z);
	button:AttachTo(screen);

    return button
end

function create_button_ex(screen, texture_path, name, pos_x, pos_y, pos_z)
    local parameter_tex = GetAnimationParametr(texture_path)
    local w = parameter_tex.x
    local h = parameter_tex.y
    local spr_up = name..'__up'
    local spr_over = name..'__over'
    local spr_down = name..'__down'

    -- create anim
    local anim = CreateAnimation(texture_path,0,0,w,h/3,1,0)
	anim:SetHotSpot(w/2,h/2/3)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject(spr_up,anim,0,0,0,0,1,1)
	
	local anim = CreateAnimation(texture_path,0,h/3,w,h/3,1,0)
	anim:SetHotSpot(w/2,h/2/3)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject(spr_over,anim,0,0,0,0,1,1)
	
	local anim = CreateAnimation(texture_path,0,2*h/3,w,h/3,1,0)
	anim:SetHotSpot(w/2,h/2/3)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject(spr_down,anim,0,0,0,0,1,1)
	
	-- create button
	local button = create_button(screen, spr_up, spr_over, spr_down, name, pos_x, pos_y, pos_z)

    return button
end
