local iIndex = Var("GameCommand"):GetIndex();
local sName = Var("GameCommand"):GetName();

-- common stuff for everyone to love!!
local genericGainFocusCmd = cmd(finishtweening;visible,true);
local genericLoseFocusCmd = cmd(visible,false);

local t = Def.ActorFrame{
	Name="Item"..iIndex;
	GainFocusCommand=genericGainFocusCmd;
	LoseFocusCommand=genericLoseFocusCmd;
	
	LoadFont("_frutiger lt std 55 roman 24px")..{
		Name="StyleName"..iIndex;
		Text=THEME:GetString(Var 'LoadingScreen',sName);
		InitCommand=cmd(shadowlength,1;diffuse,color("#FFFFFF"));
		OnCommand=cmd(y,(SCREEN_CENTER_Y*0.8)-48);
	};
	LoadFont("_frutiger lt std 55 roman 24px")..{
		Name="InfoOption"..iIndex;
		Text=THEME:GetString(Var 'LoadingScreen',sName.."Desc");
		InitCommand=cmd(shadowlength,0;zoom,0.6;diffuse,color("#000000"));
		OnCommand=cmd(y,SCREEN_CENTER_Y*0.8);
	};
};

-- dividers
if(sName == "DifficultyList" or sName == "RadarBars") then
	t[#t+1] = Def.ActorFrame{
		Name="Dividers";
		InitCommand=cmd(diffuse,color("0,0,0,0.25"));
		OnCommand=cmd(diffusealpha,0;linear,0.2;diffusealpha,1);
		OffCommand=cmd(linear,0.2;diffusealpha,0);
		
		Def.Quad{
			Name="Divider1";
			InitCommand=cmd(y,10;zoomto,294,2);
		};
		Def.Quad{
			Name="Divider2";
			InitCommand=cmd(y,30;zoomto,294,2);
		};
		Def.Quad{
			Name="Divider3";
			InitCommand=cmd(y,50;zoomto,294,2);
		};
		Def.Quad{
			Name="Divider4";
			InitCommand=cmd(y,70;zoomto,294,2);
		};
	};
end;

-- option-specific junk
if(sName == "DifficultyList") then
	t[#t+1] = Def.ActorFrame{
		Name="DifficultyListPreview";
		GainFocusCommand=genericGainFocusCmd;
		LoseFocusCommand=genericLoseFocusCmd;
		
		LoadActor("_cursor p1") .. {
			Name="CursorP1";
			InitCommand=cmd(x,-128);
		};
		
		LoadActor("_cursor p2") .. {
			Name="CursorP2";
			InitCommand=cmd(x,128;y,60);
		};
		
		OffFocusedCommand=function(self)
			SetSSMusicInfo("DifficultyList");
		end;
	};
	
	for i, diff in pairs(Difficulty) do
		-- hack to hide edit (only 5 difficulties are ever shown at once)
		if i < 6 then
			t[#t+1] = LoadFont("_frutiger lt std 55 roman 24px")..{
				Text=(i*2);
				InitCommand=cmd(x,-96;y,(i-1)*20;shadowlength,0;zoom,0.75);
				BeginCommand=function(self)
					self:diffuse( DifficultyColor(diff) );
				end;
			};
			
			for j=1,i*2 do
				t[#t+1] = LoadActor( "_ticks 7x1" )..{
					InitCommand=cmd(horizalign,left;x,-64+(j*7);y,(i-1)*20;shadowlength,0;pause);
					BeginCommand=function(self)
						self:setstate(i-1);
					end;
				};
			end;
			for j=(i*2)+1,20 do
				t[#t+1] = LoadActor( "_ticks 7x1" )..{
					InitCommand=cmd(horizalign,left;x,-64+(j*7);y,(i-1)*20;shadowlength,0;pause);
					BeginCommand=function(self)
						self:setstate(6);
					end;
				};
			end;
		end;
	end;
	
elseif(sName == "RadarBars") then
	t[#t+1] = Def.ActorFrame{
		Name="RadarBarsPreview";
		GainFocusCommand=genericGainFocusCmd;
		LoseFocusCommand=genericLoseFocusCmd;
		
		OffFocusedCommand=function(self)
			SetSSMusicInfo("RadarBars");
		end;
	};
	
	local craps = {
		THEME:GetString("RadarCategory","Stream"),
		THEME:GetString("RadarCategory","Voltage"),
		THEME:GetString("RadarCategory","Air"),
		THEME:GetString("RadarCategory","Freeze"),
		THEME:GetString("RadarCategory","Chaos");
	};
	
	t[#t+1] = Def.Quad{
		Name="RB_Background";
		InitCommand=cmd(zoomto,192,96;x,28;y,40);
		OnCommand=cmd(diffuse,color("0.5,0.5,0.5,0.5"));
	};
	
	t[#t+1] = Def.ActorFrame{
		InitCommand=cmd(x,-63);
		
		LoadFont("_frutiger lt std 55 roman 24px")..{
			InitCommand=cmd(y,-16;shadowlength,1;zoom,0.55;diffuse,color("#FFFFFF");settext,"0%";horizalign,left);
		};
		
		Def.Quad{
			Name="RB_0";
			InitCommand=cmd(zoomto,2,92;y,40);
			OnCommand=cmd(diffuse,color("1,1,1,0.5"));
		};
	};
	
	t[#t+1] = Def.ActorFrame{
		InitCommand=cmd(x,28);
		
		LoadFont("_frutiger lt std 55 roman 24px")..{
			InitCommand=cmd(y,-16;shadowlength,1;zoom,0.55;diffuse,color("#FFFFFF");settext,"50%");
		};
		
		Def.Quad{
			Name="RB_50";
			InitCommand=cmd(zoomto,2,92;y,40);
			OnCommand=cmd(diffuse,color("1,1,1,0.5"));
		};
	};
	
	t[#t+1] = Def.ActorFrame{
		InitCommand=cmd(x,120);
		
		LoadFont("_frutiger lt std 55 roman 24px")..{
			InitCommand=cmd(y,-16;shadowlength,1;zoom,0.55;diffuse,color("#FFFFFF");settext,"100%";horizalign,right);
		};
		
		Def.Quad{
			Name="RB_100";
			InitCommand=cmd(zoomto,2,92;y,40);
			OnCommand=cmd(diffuse,color("1,1,1,0.5"));
		};
	};
	
	for i=1,5 do
		t[#t+1] = LoadFont("_frutiger lt std 55 roman 24px")..{
			InitCommand=cmd(x,-80;y,(i-1)*20;shadowlength,1;zoom,0.5;diffuse,color("#FFFFFF");settext,craps[i];horizalign,right);
		};
		
		local r = math.random(1,3);
		local barsize = 12;
		local p;
		if r == 1 or r == 2 then
			-- P1 or P2 only
			if r == 1 then p = PLAYER_1;
			else p = PLAYER_2;
			end;
			
			t[#t+1] = Def.Quad{
				InitCommand=function(self)
					self:diffuse(PlayerColor(p));
					self:diffusebottomedge(PlayerMidColor(p));
					local width = math.random(64,184);
					self:x(-64);
					self:y((i-1)*20);
					self:zoomx(width);
					self:zoomy(barsize);
					self:horizalign(left);
				end;
			};
		else
			-- both
			local width = math.random(64,184);
			for s=1,2 do
				t[#t+1] = Def.Quad{
					InitCommand=function(self)
						if s == 1 then p = PLAYER_1;
						else p = PLAYER_2;
						end;
						
						self:diffuse(PlayerColor(p));
						self:diffusebottomedge(PlayerMidColor(p));
						self:x(-64);
						if s == 1 then self:y( ((i-1)*20)-3 );
						else self:y( ((i-1)*20)+3 );
						end;
						self:zoomx(width);
						self:zoomy(barsize/2);
						self:horizalign(left);
					end;
				};
			end;
		end;
	end;
	
elseif(sName == "PaneDisplay") then
	local paneStrings = {
		THEME:GetString("PaneDisplay","Steps"),
		THEME:GetString("PaneDisplay","Jumps"),
		THEME:GetString("PaneDisplay","Holds"),
		THEME:GetString("PaneDisplay","Mines"),
		THEME:GetString("PaneDisplay","Hands"),
		THEME:GetString("PaneDisplay","Rolls")
	};
	
	t[#t+1] = Def.ActorFrame{
		Name="PaneDisplayPreview";
		GainFocusCommand=genericGainFocusCmd;
		LoseFocusCommand=genericLoseFocusCmd;
		
		OffFocusedCommand=function(self)
			SetSSMusicInfo("PaneDisplay");
		end;
		
		LoadActor( THEME:GetPathB("","_frame 3x3"), "_square blackinset transparent normal", 238, 80)..{
			InitCommand=cmd(y,56);
		};
		
		LoadActor( THEME:GetPathB("","_frame 3x1"), "_infobox header", 240 )..{
			InitCommand=cmd(diffuse,PlayerColor(PLAYER_1);y,-5);
		};
		
		LoadFont("_frutiger lt std 55 roman 24px")..{
			InitCommand=cmd(shadowlength,1;zoom,0.55;y,-5;settext,"P1 Information");
		};
	};
	
	for i=1,#paneStrings do
		t[#t+1] = Def.ActorFrame{
			InitCommand=cmd(x,-64;y,(i)*16);
			
			LoadFont("_frutiger lt std 55 roman 24px")..{
				Text=paneStrings[i];
				InitCommand=cmd(shadowlength,1;horizalign,right;zoom,0.55);
			};
			
			LoadFont("_frutiger lt std 55 roman 24px")..{
				InitCommand=cmd(x,8;shadowlength,1;horizalign,left;zoom,0.55;playcommand,"Set");
				SetCommand=cmd(settext,math.random(1,500));
			};
		};
	end;
end;

return t;