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


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 aState ~= 1 then
         cm.GetShowInfo(pObj, "InfoStr2", "InfoTime2");

      else
         pObj:StartFadeRects(PhFadeAnotherTimeMedium);
      	pObj.mState   = aState        + 1;
      	pObj.mCurCell = pObj.mCurCell + 1;
         pObj.mPdata:SetupScreenShake(6, 40);
		   cm.DisableObject(pObj);
         IcPlaySample("PH_SFX_BIGBUTTONPRESSED");
         cm.SetGlobalValIndirect(pObj, "SetFlag1", true);
         cm.GetShowInfo(pObj, "InfoStr3", "InfoTime3");
      end
		return true;

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

      if aState == 0 then
         pObj:StartFadeRects(PhFadeAnotherTimeMedium);
   		pObj.mState     = aState        + 1;
   		pObj.mCurCell   = pObj.mCurCell + 1;

         pObj:StopParticleEmission(false);
			pObj:SetActive(0, pPolyNum,     false);
			pObj:SetActive(0, pPolyNum + 1, true);
   		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);
   		return true;
      end
      return _G[aTmpVal].MaybeLater(pObj);

	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 aRpos = pObj.mSmPos;
	local aRect = aImg:GetCelRect(pObj.mCurCell);

	if (aState == 3 or aState == 1) then
		pG:SetColorizeImages(true);
		pG:SetColor(Color(255, 255, 255, pObj.mAlpha:AncGetVal()));
	end
	pG:DrawImage(aImg:GetImage(), aRpos.x, aRpos.y, aRect);

end


-- Show some info
_G[gTable].MaybeLater =  function(pObj)
   pObj.mPdata:UnMouseObject();
   cm.GetShowInfo(pObj, "InfoStr1", "InfoTime1");
   IcPlaySample("PH_SFX_DOES_NOT_WORK");
   return true;
end
