-- events for main menu


function OnLoad ()
	SetProperty ("/:enter_trans_duration", 0.5);
	SetProperty ("/:leave_trans_duration", 0.5);
	SetProperty ("/:enable_event_on_key_down", 1);
	CacheSound ("ui/sfx/panel_move.ogg");
end;


function OnEnter ()

	PlaySound ("ui/sfx/panel_move.ogg");
end;

function OnLeave ()
    
end;


function OnClick (name)

	Print ("OnClick " .. name .. "\n");
	

	

	if (name == "VolSound") then

	end;


end;


function OnKeyDown (key)
	
	Print("Any Key Down (" .. key .. ")\n");
	if (key == "ESCAPE") then
		PopScreen ();
	end;
	
	local bm = "worldmap/backgrounds/bg-0001.jpg";
	
	if (key == "1") then
		Azkend_BitmapColorSepia ("GAME_BACKGROUND", bm, 10);
		Azkend_BitmapCreateMask ("MENU_BACKGROUND", 1, 1, "CUMULATIVE|PARTS");
	end;

	if (key == "2") then
		Azkend_BitmapColorSepia ("GAME_BACKGROUND", bm, 10);
		Azkend_BitmapCreateMask ("MENU_BACKGROUND", 1, 2, "CUMULATIVE|PARTS");
	end;

	if (key == "3") then
		Azkend_BitmapColorSepia ("GAME_BACKGROUND", bm, 10);
		Azkend_BitmapCreateMask ("MENU_BACKGROUND", 1, 3, "CUMULATIVE|PARTS");
	end;

	if (key == "4") then
		Azkend_BitmapColorSepia ("GAME_BACKGROUND", bm, 10);
		Azkend_BitmapCreateMask ("MENU_BACKGROUND", 1, 4, "CUMULATIVE|PARTS");
		Azkend_BitmapDrawInto ("MENU_BACKGROUND", "GAME_BACKGROUND");
	end;
	
	if (key == "5") then
		Azkend_BitmapColorSepia ("GAME_BACKGROUND", bm, 10);
		Azkend_BitmapCreateMask ("MENU_BACKGROUND", 1, 5, "CUMULATIVE|PARTS");
	end;
	
	if (key == "6") then
		Azkend_BitmapColorSepia ("GAME_BACKGROUND", bm, 10);
		Azkend_BitmapCreateMask ("MENU_BACKGROUND", 1, 6, "CUMULATIVE|PARTS");
	end;

	if (key == "MOUSE_BUTTON_0") then
		local y = NX_GetKeyState ("MOUSE_Y");
		SpawnFX ("fxs/color-sweep-row.lua", 400, y, 0, 0);
	end;
end;


function OnUpdate (tdelta)

	akey = GetActiveScreenAnimKey ();

	trans = math.sin (0.5*3.1415926535 * GetActiveScreenTransPhase ());
	SetProperty ("panel:position_offset.y", (1-trans) * 200);
	SetProperty ("panel:alpha", trans);
	SetProperty ("fader:alpha", trans + trans * 0.05 * math.sin (2*3.141592*akey));

end;

function OnDraw ()
	local bm0 = "GAME_BACKGROUND";
	local bm1 = "MENU_BACKGROUND";

	local x = NX_GetKeyState ("MOUSE_X");
	local y = NX_GetKeyState ("MOUSE_Y");

	NX_SetAlpha (1);
	NX_SetColor (1,1,1);
	
	-- DrawSubBitmap (bm,  x, y, sx, sy,  ex, ey);
	
	--NX_DrawSubBitmap (bm1, 0, 0,  0,  0, x, 600);
	--NX_DrawSubBitmap (bm0, x, 0,  x,  0, 800, 600);
	
	NX_DrawBitmap (bm0, 0, 0);
	NX_SetAlpha (x/800);
	NX_DrawBitmap (bm1, 0, 0);	
	NX_SetBlend ("ADDITIVE");

	NX_DrawBitmap (bm1, 0, 0);
	
--	NX_DrawSubBitmap (bm0, 0, 0,  0,  0, 800, y);
--	NX_DrawSubBitmap (bm1, 0, y,  0,  y, 800, 600);
	
end;
