_G[gTable] = {};

local aTmpVal = gTable;
local aGoingBig = false;
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_FOOT;
   return aCursorTable;

end


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

	if pObj.mCurCell == 1 and (not pObj.mAlpha:AncIsChanging()) then
     	pObj:StartFadeRects(PhVanish4);

	   if aGoingBig then
	      pObj.mCurCell = 2;
		else
		   pObj.mCurCell = 0;
		end

	end

end


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

	if pName == "" then

		pObj:StartFadeRects(PhVanish4);
		pObj.mCurCell = 0;

      -- Warp to next stage or level
		local aNextLevel = pObj.mCsData:GetInt("NextLevel");
		pObj.mPdata:SetNextLevel(aNextLevel);

      local aNextStage = pObj.mCsData:GetBool("NextStage");
      pObj.mPdata:LevelComplete(aNextStage);
      pObj:StopParticleEmission(false);
      IcPlaySample("PH_SFX_FOOTSTEPSONGROUND");
		return true;

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

	return false;

end



-- Called when mouse enters the object
_G[gTable].OnMouseEnter = function(pObj)

  	pObj:StartFadeRects(PhVanish4);
   pObj.mCurCell = 1;
   aGoingBig = true;

end

-- Called when mouse leaves object
_G[gTable].OnMouseLeave = function(pObj)

  	pObj:StartFadeRects(PhVanish4);
   pObj.mCurCell = 1;
   aGoingBig = 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


