_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     = pObj.mState;


	if pName == "" then

      if aState  < 2 then
  	      cm.GetShowInfo(pObj, "InactiveStr2", "InactiveTime");
		   return true;

      elseif aState == 2 then

         pObj:StartFadeRects(PhFadeAnotherTimeShort);
   		pObj.mState		= aState + 1;
   		pObj.mCurCell	= pObj.mCurCell + 1;

   	   pObj:SetActive(0, pPolyNum, false);
   	   pObj:SetActive(0, pPolyNum + 1, true);
   		pObj:StopParticleEmission(false);
     		pObj.mDiscovered = false;
         return true;

      elseif aState == 3 then

         pObj:StartFadeRects(PhFadeAnotherTimeShort);
   		pObj.mState		= aState + 1;
   		pObj.mCurCell	= pObj.mCurCell - 1;

         cm.SetGlobalValIndirect(pObj, "SetFlag1", true);
         cm.GetShowInfo(pObj, "InfoStr1", "InfoTime");
			cm.DisableObject(pObj);
			IcPlaySample("PH_SFX_GOOD_JOB");
         return true;

		end
		return true;

	else


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

         pObj:StartFadeRects(PhFadeAnotherTimeShort);
   		pObj.mState		= aState + 1;
   		pObj.mCurCell	= pObj.mCurCell + 1;

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

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

   		if aState == 1 then

         	pObj:StartFadeRects(PhFadeAnotherTimeShort);
      		pObj.mState		= aState + 1;
      		pObj.mCurCell	= pObj.mCurCell + 1;
      		pObj:StopParticleEmission(false);
      		_G[pActorObj.mScriptTag].OnUse(pActorObj, pObj);
      		pObj.mDiscovered = false;
   		   return true;

         else
            -- Tell the player he's made a mistake
            cm.GetShowInfo(pObj, "InactiveStr1", "InactiveTime");
            IcPlaySample("PH_SFX_DOES_NOT_WORK");
            return false;
         end

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

	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;


