_G[gTable] = {};

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


-- Called on Init
_G[gTable].OnInit = function(pObj)
	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)

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

	cm.ZoomOutUpdate(pObj);

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");
   	return true;
	end

	if pName == "" then

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

		else
         if pObj.mState == 0 then

            pObj:StartFadeRects(PhFadeAnotherTimeShort);
   			pObj.mState		 = pObj.mState + 1;
   			pObj.mCurCell	 = pObj.mCurCell + 1;
   			pObj:SetActive(0, pPolyNum, false);
   			pObj:SetActive(1, pPolyNum, false);
   			pObj:SetActive(0, pPolyNum + 1, true);
   			pObj:SetActive(1, 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.mBigPos, "SpawnObject") then
               return true;
            end
				if pObj.mCsData:IfExistsString("ObjSpawnStr") then
				   cm.GetShowInfo(pObj, "ObjSpawnStr", "ObjSpawnTime");
				end

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

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

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



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


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

	if (pObj.mCurImg == 1) then
		pG:SetColorizeImages(true);
		pG:SetColor(Color(255, 255, 255, pObj.mAlpha:AncGetVal()));

		local aBoxImg = IcImageWrap("PH_IMG_CMN_ZOOM_BOX");
		assert(aBoxImg);
		aRect = aBoxImg:GetCelRect(0);
		aRpos = pObj.mFrmPos;
		pG:DrawImage(aBoxImg:GetImage(), aRpos.x, aRpos.y, aRect);

		aImg = IcImageWrap(pObj.mBigImage);
		aRpos= pObj.mBigPos;
		assert(aImg);
		aRect = aImg:GetCelRect(pObj.mCurCell);
		pG:DrawImage(aImg:GetImage(), aRpos.x, aRpos.y, aRect);
	end


end



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


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

