_G[gTable] = {};

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


-- Called on Init
_G[gTable].OnInit = function(pObj)
	pObj.mState = 0;
end


-- Called after data being loaded from disk
_G[gTable].OnLoad = function(pObj)
	if pObj.mState == 1 then
		pObj:StopParticleEmission(false);
	   pObj:SetupParticleSystem("PH_PSYS_S02_L05_BRAZIER_SPARKLE");
	   pObj:StartParticleEmission(0);
	end

end


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

   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)


   -- If not active, show a message & exit
	if not pObj.mCsData:GetBool("IsActivated") then

      cm.GetShowInfo(pObj, "InactiveStr", "InactiveTime");
      IcPlaySample("PH_SFX_DOES_NOT_WORK");
   	if pName == "" then
         return true;
      end
   	return false;

	end

   -- If active handle the click
	pObj.mDiscovered = true;
	if pName == "" then
      cm.GetShowInfo(pObj, "InfoStr", "InfoTime");
   	return true;

	elseif pName == pObj.mCsData:GetString("KeyObject1") then

      pObj:StartFadeRects(PhFadeAnotherTimeShort);
		pObj.mState		  = 1;
		pObj.mCurCell	  = pObj.mCurCell + 1;

		pObj:DisablePolys();
		pObj:StopParticleEmission(false);
	   pObj:SetupParticleSystem("PH_PSYS_S02_L05_BRAZIER_SPARKLE");
	   pObj:StartParticleEmission(0);

		-- Remove the key
		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);

		-- Set global counter
		local aSetFlag = pObj.mCsData:GetString("SetFlag1");
		
		local aFlagVal = 0;
		if pObj.mPdata.mCsData:IfExistsInt(aSetFlag) then
         aFlagVal = pObj.mPdata.mCsData:GetInt(aSetFlag);
      end
		aFlagVal = aFlagVal + 1;
		pObj.mPdata.mCsData:SetVal(aSetFlag, aFlagVal);
		return true;

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

	return false;
end



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

	local aRpos = pObj.mSmPos;
	local aImg  = IcImageWrap(pObj.mSmallImage);
	assert(aImg);
	local aRect = aImg:GetCelRect(pObj.mCurCell);
	pG:DrawImage(aImg:GetImage(), aRpos.x, aRpos.y, aRect);

end

-- Zooms Out
_G[gTable].NormalSize = cm.ZoomOut;


-- Zooms In
_G[gTable].GetBigger = cm.ZoomIn;


