_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;
	if pName == "" then

		assert(pObj.mCurImg == 0);
		if pObj.mState == 0 then
			cm.ShowInfo(pObj, "The door is locked", 120);
			return true;

		elseif pObj.mState == 1 then
			pObj.mState	= pObj.mState + 1;
			pObj:SetActive(0, pPolyNum, false);
			pObj.mDiscovered = false;
			
			local aNextLevel = pObj.mCsData:GetInt("NextLevel")
			pObj.mPdata:SetNextLevel(aNextLevel);
			pObj.mPdata:LevelComplete(false);
			return true;
		end
		return true;

	elseif pName == pObj.mCsData:GetString("KeyObject") then
		assert(pObj.mCurImg == 0);
		if pObj.mState == 0 then
			pObj.mState		= pObj.mState   + 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;
		end
		return false;
	else
		cm.ObjDoesNotWork(pObj);
		return false;
	end
	return false;
end



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

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


