_G[gTable] = {};

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


-- Called on Init
_G[gTable].OnInit = function(pObj)
	pObj.mState = 0;
	pObj.mCsData:SetVal("Downsizing", false);
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);

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

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

		else

			if aState == 1 then

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

				pObj.mState   = aState + 1;
				pObj.mCurCell = pObj.mCurCell + 1;
				cm.DisableObject(pObj);

				_G[aTmpVal].NormalSize(pObj);
				pObj.mCb:Disappear();
				IcPlaySample("PH_SFX_OBJ_PICKUP");
				return true;
			end

      	if pObj.mCsData:IfExistsString("LockedInfo") then
            cm.GetShowInfo(pObj, "LockedInfo", "LockedInfoTime");
         else
            cm.ShowInfo(pObj, "It is locked");
         end
			return true;
		end

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

      if aState == 0 then

   		if pObj.mCurImg == 0 then
   			_G[aTmpVal].GetBigger(pObj, PhGetBigTime);
   		else
            pObj:StartFadeRects(PhFadeAnotherTimeShort);
         end

   		pObj.mState		  = aState + 1;
   		pObj.mCurCell	  = pObj.mCurCell + 1;
   		--Deactivate used polygons & activate new ones
   		pObj:SetActive(0, pPolyNum, false);
   		pObj:SetActive(0, pPolyNum + 1, true);
   		pObj:SetActive(1, pPolyNum, false);
   		pObj:SetActive(1, pPolyNum + 1, true);
   		pObj:StopParticleEmission(false);
   		_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 =  cm.DrawZoomable;


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


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


