_G[gTable] = {};

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


-- Called on Init
_G[gTable].OnInit = function(pObj)
	pObj.mCsData:SetVal("Downsizing", false);
   pObj:SetupParticleSystem("PH_PSYS_S01_L01_FIRE1");
   pObj:StartParticleEmission(1);
   pObj.mDiscovered = true;
   pObj.mGobj.mSoundPlayer:PlayLoopingSfx("PH_SFX_BURNINGFIRE");
end


-- Called after data being loaded from disk
_G[gTable].OnLoad = function(pObj)

   if pObj.mState == 0 then
      pObj:SetupParticleSystem("PH_PSYS_S01_L01_FIRE1");
      pObj:StartParticleEmission(1);
      pObj.mDiscovered = true;
      pObj.mGobj.mSoundPlayer:PlayLoopingSfx("PH_SFX_BURNINGFIRE");

	elseif pObj.mState >= 1 then
		pObj:StopParticleEmission(true);
      pObj:SetupParticleSystem("PH_PSYS_FIRE_SMOKE");
      pObj:StartParticleEmission(1);
   end

end


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

	if pObj.mCsData:GetBool("Downsizing") then
		if not pObj.mAlpha:AncIsChanging() then
			pObj.mCsData:SetVal("Downsizing", false);
			pObj.mCurImg = 0;
			pObj.mAlpha:AncSetCurrent(255);
         pObj:SetupParticleSystem("PH_PSYS_FIRE_SMOKE");
         pObj:StartParticleEmission(1);
		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

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

			elseif pObj.mState == 2 then
				cm.ShowInfo(pObj, "There is nothing more here", 160);
				IcPlaySample("PH_SFX_DOES_NOT_WORK");
				return true;

			else
				cm.ShowInfo(pObj, "The fire burns bright", 160);
				IcPlaySample("PH_SFX_DOES_NOT_WORK");
				return true;
			end

		else

			if pObj.mState == 1 then

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

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

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

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

		pObj.mState	= 1;
		pObj:StopParticleEmission(true);
      pObj:SetupParticleSystem("PH_PSYS_FIRE_SMOKE");
      pObj:StartParticleEmission(1);
		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);
		pObj.mGobj.mSoundPlayer:FadeoutLoopingSfx(40);
		return true;
	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(0);
	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()));
		
		aRpos= pObj.mFrmPos;
		local aBoxImg = IcImageWrap("PH_IMG_CMN_ZOOM_BOX");
		assert(aBoxImg);
		pG:DrawImage(aBoxImg:GetImage(), aRpos.x, aRpos.y);

		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;

