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

	cm.ZoomOutUpdate(pObj);

end


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

   -- Check if the holder is active
   if not cm.GetGlobalBoolIndirect(pObj, "ActivatorFlag1") then
      cm.GetShowInfo(pObj, "InfoStr1", "InfoTime1");
      if pName ~= "" then
         pObj.mPdata:UnMouseObject();
      end
      IcPlaySample("PH_SFX_DOES_NOT_WORK");
      return true;
   end

	pObj.mDiscovered = true;
	if pName == "" then

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

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

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

			_G[aTmpVal].NormalSize(pObj);
			pObj.mCb:Disappear();
			IcPlaySample("PH_SFX_OBJ_PICKUP");
			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 aMaxCells = aImg:GetNumCells();
	local aCell = pObj.mCurCell;
	if aCell >= aMaxCells then
      aCell = aMaxCells - 1;
   end

	local aRect = aImg:GetCelRect(aCell);
	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()));

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

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

	end


end



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


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

