_G[gTable] = {};

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

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


-- Called after data being loaded from disk
_G[gTable].OnLoad = function(pObj)
   if pObj.mState == 0 then
      _G[aTmpVal].SetupParticleSystem(pObj);
   end
end


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

end


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

	pObj.mDiscovered = true;
	local aState     = 0 + pObj.mState;

	if pName == "" then
      cm.GetShowInfo(pObj, "InfoStr1", "InfoTime1");
   	return true;

   -- The key is used upon the object
	elseif pName == pObj.mCsData:GetString("KeyObject1") then

      if aState == 0 then

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

   		cm.DisableObject(pObj);
   		cm.SetGlobalValIndirect(pObj, "SetFlag1", true);

   		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);
   		return true;
		end

		cm.ObjDoesNotWork(pObj);
		return false;

	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

-- Sets up the particle system
_G[gTable].SetupParticleSystem =  function(pObj)

   pObj.mDiscovered = true;
   local aStr = pObj.mCsData:GetString("ParticleSystemName");
   pObj:StopParticleEmission(false);
   pObj:SetupParticleSystem(aStr);
   pObj:StartParticleEmission(1);

end


