_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)

end


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

   cm.ZoomOutUpdate(pObj);

   if pObj.mState == 4 then
  		if not pObj.mCsData:GetBool("Downsizing") then
         pObj.mState = pObj.mState + 1;
         cm.DisableObject(pObj);
         cm.SetGlobalValIndirect(pObj, "SetFlag1", true);
         
		end
   end

end


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


	pObj.mDiscovered = true;

	if pName == "" then

      if pObj.mCurImg == 0 then
         _G[aTmpVal].GetBigger(pObj, PhGetBigTime);
         return true;
      else
  	      cm.GetShowInfo(pObj, "InactiveStr1", "InactiveTime");
		   return true;
		end

		return true;

	else

      if pObj.mCurImg == 0 then
         _G[aTmpVal].GetBigger(pObj, PhGetBigTime);
         return true;
      end

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

         if pObj.mState  ~= 0 or pPolyNum ~= 0 then
            cm.GetShowInfo(pObj, "InactiveStr2", "InactiveTime");
            IcPlaySample("PH_SFX_DOES_NOT_WORK");
      		return false;
         end

         pObj:StartFadeRects(PhFadeAnotherTimeShort);
   		pObj.mState		= pObj.mState + 1;
   		pObj.mCurCell	= pObj.mCurCell + 1;
      	pObj:SetActive(1, pPolyNum, false);
   		pObj:StopParticleEmission(false);
   		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);
   		return true;

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

   		if pObj.mState == 1 and pPolyNum == 1 then

            pObj:StartFadeRects(PhFadeAnotherTimeShort);
      		pObj.mState		= pObj.mState + 1;
      		pObj.mCurCell	= pObj.mCurCell + 1;
      	   pObj:SetActive(1, pPolyNum, false);
      		pObj:StopParticleEmission(false);
      		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);
   		   return true;

         else
            -- Tell the player he's made a mistake
            cm.GetShowInfo(pObj, "InactiveStr2", "InactiveTime");
            IcPlaySample("PH_SFX_DOES_NOT_WORK");
            return false;
         end

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

   		if pObj.mState == 2 and pPolyNum == 2 then

            pObj:StartFadeRects(PhFadeAnotherTimeShort);
      		pObj.mState		= pObj.mState + 1;
      		pObj.mCurCell	= pObj.mCurCell + 1;
      	   pObj:SetActive(1, pPolyNum, false);
      		pObj:StopParticleEmission(false);
      		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);
   		   return true;

         else
            -- Tell the player he's made a mistake
            cm.GetShowInfo(pObj, "InactiveStr2", "InactiveTime");
            IcPlaySample("PH_SFX_DOES_NOT_WORK");
            return false;
         end

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

   		if pObj.mState == 3 and pPolyNum == 3 then

      		pObj.mState		= pObj.mState + 1;
      		pObj.mCurCell	= pObj.mCurCell + 1;
      	   pObj:SetActive(1, pPolyNum, false);
      		pObj:StopParticleEmission(false);

      		_G[aTmpVal].NormalSize(pObj);
      		pObj.mCb:Disappear();
      		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);
   		   return true;

         else
            -- Tell the player he's made a mistake
            cm.GetShowInfo(pObj, "InactiveStr2", "InactiveTime");
            IcPlaySample("PH_SFX_DOES_NOT_WORK");
            return false;
         end

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

	end

	return false;

end



-- Called on draw
_G[gTable].OnDraw =  cm.DrawZoomable;

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


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


