-- events for newarea screen

timer = 0
episode = 0

function OnLoad ()
	CacheSound ("music/bonus.ogg");
	--CacheSound ("music/episodestart.ogg");
end;

function OnEnter ()
    Reset()
 	SetProperty ("/Storyscreen:enter_trans_duration", 1);
    SetProperty ("/Storyscreen:leave_trans_duration", 1);
	SwitchMusic ("music/bonus.ogg", 2, 3);	
	--PlaySound ("music/episodestart.ogg")
	reset();
	
	
end;

function reset()
	--level_number = GetGameValue ("level_number")-1;
	--episode = math.floor (level_number/7);
	
	if(episode < 1 or episode > 10) then
		episode = 1;
	end;
	
	imagenumber = string.format("%04d", episode);
	imagename = "worldmap/backgrounds/bg-"..imagenumber..".jpg";
	
	val = DM_GetValue ("xml/story.xml", "newareas", episode-1, "title");
	SetProperty ("title:label.text", val);
	
	val = DM_GetValue ("xml/story.xml", "newareas", episode-1, "text");
	SetProperty ("story_text:label.text", val);
	
	--Azkend_SetMenuBackground (imagename);
	--SetProperty("bg:label.bitmap", imagename);
end;

function OnLeave ()

end;

function Reset ()
   timer = 0

end;

function OnClick (name)

	Print ("OnClick " .. name .. "\n");
		
	if (name == "add") then	
		episode = episode + 1;
		reset();
	end;
	
	if (name == "Continue") then			
		PopScreen ("NewArea");
		return;
	end;
end;


function OnUpdate (tdelta)

    timer = timer + tdelta;    
	akey = GetActiveScreenAnimKey ();	
	alpha = GetActiveScreenTransPhase();
	
    
    SetProperty ("bg:alpha", GetActiveScreenTransPhase()*2)
    
end;

function OnDraw ()

end;
