
_G[gTable] = {};

local aTmpVal		= gTable;
local aInfoShown	= false;
local aHelpShown	= false;
local aCount		= 0;
cm.SetupTable(_G[aTmpVal]);

-- Called on Init
_G[gTable].OnInit = function(pObj)
	aInfoShown = false;
	aHelpShown = false;
	aCount	  = 0;
	pObj.mCsData:SetVal("aInfoShown", aInfoShown);
	pObj.mCsData:SetVal("aHelpShown", aHelpShown);
end

-- Called after data being loaded from disk
_G[gTable].OnLoad = function(pObj)
	aInfoShown = pObj.mCsData:GetBool("aInfoShown");
	aHelpShown = pObj.mCsData:GetBool("aHelpShown");
	aCount	  = 0;
end


-- Called after a level is loaded
_G[gTable].OnLevelLoad = function(pObj)
	aCount = 0;
   pObj.mGobj.mSoundPlayer:PlayMusic("IcMusicBuilderInsides");
  	pObj.mGobj.mSoundPlayer:PlayAmbient("Ambient_WoodenRoom", 5);
end

-- Called after a level is exited
_G[gTable].OnLevelExit = function(pObj)
   pObj.mGobj.mSoundPlayer:ClearMusic(0);
   pObj.mGobj.mSoundPlayer:FadeoutAmbient(20);
end

-- Called on a update
_G[gTable].OnUpdate = function(pObj)

	if not aInfoShown then

		aCount = aCount + 1;
		if aCount == 25 then
         aCount		= 0;
			aInfoShown	= true;
			pObj.mCsData:SetVal("aInfoShown", aInfoShown);
			--pObj.mPdata:ShowCurLevelInfo();
			pObj.mPdata:ShowCurLevelInfo("PH_SFX_INGAME_01");
		end

	elseif not aHelpShown and (not pObj.mPdata.mInfo:IsAlive()) then

		aCount = aCount + 1;
		if aCount == 15 then
		   aCount		= 0;
			aHelpShown	= true;
			local aInfoStr  = pObj.mCsData:GetString("InfoStr1");
			pObj.mPdata:ShowHelp(pObj.mGobj.mDataManager:GetString(aInfoStr),
				IcVector2d(517, 462), false, false);
			pObj.mCsData:SetVal("aHelpShown", aHelpShown);
			cm.SetGlobalValIndirect(pObj, "SetFlag1", true);
		end

	elseif pObj.mState == 0 and cm.GetGlobalBoolIndirect(pObj, "ActivatorFlag1") then

      aCount = aCount + 1;
      if aCount == 25 then
		   pObj.mState = 1 + pObj.mState;
		   local aInfoStr  = pObj.mCsData:GetString("InfoStr2");
			pObj.mPdata:ShowImportantInfo(pObj.mGobj.mDataManager:GetString(aInfoStr));
		end

	elseif pObj.mState == 1 and (not pObj.mPdata.mInfo:IsAlive()) then

	   pObj.mState = 1 + pObj.mState;
		pObj.mPdata:LevelComplete(true);
		pObj.mPdata:SetupCutScene(1);

	end

end

-- Called on a succesful click
_G[gTable].OnClick =  function(pObj, pName)
	return false;
end

-- Called on draw
_G[gTable].OnDraw =  function(pObj, pG)

	local aImg = IcImageWrap(pObj.mSmallImage);
	if (pObj.mCurImg == 1) then
		aImg = IcImageWrap(pObj.mBigImage);
	end
	assert(aImg);

	aRect = aImg:GetCelRect(pObj.mCurCell);
	if pObj:SmIsMoving() then
		pG:DrawImageF(aImg:GetImage(), pObj.mSmPos.x, pObj.mSmPos.y, aRect);
	else
		pG:DrawImage(aImg:GetImage(), pObj.mSmPos.x, pObj.mSmPos.y, aRect);
	end

end


