_G[gTable] = {};

local aTmpVal   = gTable;
cm.SetupTable(_G[aTmpVal]);

-- Called on Init
_G[gTable].OnInit = function(pObj)

end


-- Called after data being loaded from disk
_G[gTable].OnLoad = function(pObj)

end


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

	-- See if the activation condition is met
   if not pObj.mCsData:GetBool("IsActivated") then
      if cm.GetGlobalBoolIndirect(pObj, "ActivatorFlag1") then
         pObj.mCsData:SetVal("IsActivated", true);
      end
   end

end


-- Called on a succesful click
_G[gTable].OnClick =  function(pObj, pName, pActorObj, pPolyNum, pX, pY)

	pObj.mDiscovered = true;

   -- If not active, show a message & exit
	if not pObj.mCsData:GetBool("IsActivated") then
      cm.GetShowInfo(pObj, "InactiveStr", "InactiveTime");
      
      if pName == "" then
       	return true;
      end
      return false;
	end

	if pName == "" then

      local aState = pObj.mState;
      if aState == 0 then

         pObj:StartFadeRects(PhFadeAnotherTimeMedium);
			pObj.mState		 = aState + 1;
			pObj.mCurCell	 = pObj.mCurCell + 1;
			pObj:SetActive(0, pPolyNum, false);
			pObj:SetActive(0, pPolyNum + 1, true);
			pObj:StopParticleEmission(false);

			if pObj.mCsData:IfExistsString("ObjSfxId") then
			   local aStr = pObj.mCsData:GetString("ObjSfxId");
			   IcPlaySample(aStr);
			else
			   IcPlaySample("PH_SFX_OBJ_USED");
			end

      else

         if not cm.SpawnObject(pObj, 0, pObj.mSmPos, "SpawnObject") then
            return true;
         end

         pObj:StartFadeRects(PhFadeAnotherTimeShort);
			pObj.mState		 = aState + 1;
			pObj.mCurCell	 = pObj.mCurCell + 1;
			cm.DisableObject(pObj);
         IcPlaySample("PH_SFX_OBJ_PICKUP");

		end
		return true;
	else
		cm.ObjDoesNotWork(pObj);
		return false;
	end
	return false;
end



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


end

