-- events for main menu


akey = 0;
tpart = 0;

function ResetAnim ()
	akey = 0;
	tpart = 0;
end;

function UpdateAnim (tdelta)

	akey = akey + 2 * tdelta;
	
	if (akey >= 1) then
		akey = 0;
		tpart = tpart + 1;		
	end;
	
	i = 1;
	current_part = tpart;
	while (i <= 5) do
	
		r = 10;
		dx = GetProperty ("t1part" .. i .. ":position.x");-- - GetProperty ("t1:position.x"); 
		dy = GetProperty ("t1part" .. i .. ":position.y");-- - GetProperty ("t1:position.y"); 
		
		if (i > current_part) then
			SetProperty ("t1part" .. i ..":position_offset", r * dx, r * dy);
		elseif (i < current_part) then
			SetProperty ("t1part" .. i ..":position_offset", 0, 0);
		else
			SetProperty ("t1part" .. i ..":position_offset", (1-akey) * r * dx, (1-akey) * r * dy);
		end;
		
		i = i + 1;
	end;
end;


function OnLoad ()

end;


function OnEnter ()
	ResetAnim ();

end;

function OnLeave ()
	ResetAnim ();

end;




function OnClick (name)

	Print ("OnClick " .. name .. "\n");
	
	if (name == "Exit") then
		PopScreen ();
		return;
	end;
	
	if (name == "Anim") then
		ResetAnim ();
		return;
	end;

end;


function OnUpdate (tdelta)


	
	UpdateAnim (tdelta);

end;

function OnDraw ()
	NX_DrawText ("fonts/small.mft", 100, 100, "part: " .. tpart);

end;
