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

   -- Disable the spawner
	if pObj.mState == 2 then
		if not pObj.mAlpha:AncIsChanging() then
			pObj.mIsDone = true;
		end
	end

   -- Activate the spawner
	if pObj.mState == 0 then
   	local aStartFlag = pObj.mCsData:GetString("ActivatorFlag1");
   	if pObj.mPdata.mCsData:GetBool(aStartFlag) then
         pObj.mState = 1;
      	pObj.mAlpha:AncSetupChange(0.0, 255.0, PhMaterializeTime, IcAutoNumChgr.IC_ANCM_LINEAR);
      	pObj:SetActive(0, 0, true);
   	end
	end

end


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

	if pName == "" then

		assert(pObj.mCurImg == 0);
		assert(pObj.mState  == 1);
		pObj.mState = 2;
		pObj:SetActive(0, pPolyNum, false);
		pObj.mAlpha:AncSetupChange(255.0, 0.0, PhSpawnerVanishAfterUse, IcAutoNumChgr.IC_ANCM_LINEAR);

   	cm.SpawnObject(pObj, 0, pObj.mSmPos, "SpawnObject");
		IcPlaySample("PH_SFX_OBJ_PICKUP");
		return true;

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

	return false;

end


-- Called on draw
_G[gTable].OnDraw =  function(pObj, pG)

   if (pObj.mState == 0) then
      return;
   end

	pG:PushState();
	local aImg  = IcImageWrap(pObj.mSmallImage);
	assert(aImg);
	local aRpos = pObj.mSmPos;
	local aRect = aImg:GetCelRect(pObj.mCurCell);

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

   pG:PopState();
end


-- Called on moused
_G[gTable].OnMoused =  function(pObj)
	print(2+2);
end

-- Called on Unmoused
_G[gTable].OnUnMoused =  function(pObj)
	print(2+2);
end



