_G[gTable] = {};

local aTmpVal		= gTable;
local aTmpCounter = 0;
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 to fetch cursor data
_G[gTable].GetCursorInfo = function(pObj, pPolyNum, pName)
	local aCursorTable	= {};
   aCursorTable[0]		= true;
   aCursorTable[1]		= IcGobj.CURSOR_POINTER;

   if pObj.mState >= 1 then
      aCursorTable[1] = IcGobj.CURSOR_FOOT;
	end
   return aCursorTable;

end


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

   -- See if the lever has been operated
	if pObj.mState == 0 then

      if cm.GetGlobalBoolIndirect(pObj, "ActivatorFlag1") then
         pObj:StartFadeRects(PhFadeAnotherTimeShort);
			pObj.mState   = pObj.mState   + 1;
			pObj.mCurCell = pObj.mCurCell + 1;
		end

	elseif pObj.mState == 1 then

      if not pObj.mAlpha:AncIsChanging() then
         pObj:StartFadeRects(PhFadeAnotherTimeShort);
			pObj.mState   = pObj.mState   + 1;
			pObj.mCurCell = pObj.mCurCell + 1;
		end

   end

end

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

	if pName == "" then
		
      if pObj.mState == 2 then
        	pObj.mDiscovered = true;
  			local aNextLevel = pObj.mCsData:GetInt("NextLevel")
			pObj.mPdata:SetNextLevel(aNextLevel);
			pObj.mPdata:LevelComplete(false);
			IcPlaySample("PH_SFX_FOOTSTEPSONGROUND");
			return true;

      else
      
         if not cm.GetGlobalBoolIndirect(pObj, "ActivatorFlag2") then
	         aTmpCounter = aTmpCounter + 1;
	         if aTmpCounter == 2 then
	         	cm.GetShowInfo(pObj, "InfoStr2", "InfoTime2");
	         else
	         	cm.GetShowInfo(pObj, "InfoStr1", "InfoTime1");
	         end
			else
			   cm.GetShowInfo(pObj, "InfoStr3", "InfoTime3");
			end
         return true;

      end

		return false;

	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);
	aRect = aImg:GetCelRect(pObj.mCurCell);
	pG:DrawImage(aImg:GetImage(), pObj.mSmPos.x, pObj.mSmPos.y, aRect);

end



