_G[gTable] = {};

local aTmpVal     = gTable;
local aInfoShown  = false;
local aCount      = 0;
cm.SetupTable(_G[aTmpVal]);


-- Called on Init
_G[gTable].OnInit = function(pObj)

   pObj.mState= 0;
	aCount     = 0;
	aInfoShown = false;

	pObj.mCsData:SetVal("aInfoShown", aInfoShown);
	cm.SetGlobalValIndirect(pObj, "BrazierCounter1", 0);

end

-- Called after data being loaded from disk
_G[gTable].OnLoad = function(pObj)
	aInfoShown = pObj.mCsData:GetBool("aInfoShown");
	aCount = 0;
end

-- Called after a level is loaded
_G[gTable].OnLevelLoad = function(pObj)
   pObj.mGobj.mSoundPlayer:PlayMusic("IcMusicBuilderInsides");
  	pObj.mGobj.mSoundPlayer:PlayAmbient("Ambient_UnderGround", 5);
end


-- Called after a level is exited
_G[gTable].OnLevelExit = function(pObj)
   pObj.mGobj.mSoundPlayer:FadeoutAmbient(20);
   pObj.mGobj.mSoundPlayer:ClearMusic(0);
end


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

	if not aInfoShown then
		aCount = aCount + 1;
		if aCount == 25 then
			aInfoShown = true;
			pObj.mCsData:SetVal("aInfoShown", aInfoShown);
			--pObj.mPdata:ShowCurLevelInfo();
			pObj.mPdata:ShowCurLevelInfo("PH_SFX_INGAME_10");
		end
	end

	-- Handle braziers
	if pObj.mState == 0 then
   	local aCount = cm.GetGlobalIntIndirect(pObj, "BrazierCounter1");
   	if aCount == 6 then
         pObj.mState = pObj.mState + 1;
      end

	elseif pObj.mState == 1 then
   	if cm.GetGlobalBoolIndirect(pObj, "GuardiansHappy") then
         pObj.mState = pObj.mState + 1;
         cm.SetGlobalValIndirect(pObj, "SetFlag1", true);
      end
	end


end

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

	pObj.mDiscovered = true;
	if pName == "" then
   	return false;
	else
		cm.ObjDoesNotWork(pObj);
		return false;
	end

end

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

	local aImg = IcImageWrap(pObj.mSmallImage);
	if (pObj.mCurImg == 1) then
		aImg = IcImageWrap(pObj.mBigImage);
	end
	assert(aImg);

	aRect = aImg:GetCelRect(pObj.mCurCell);
	if pObj:SmIsMoving() then
		pG:DrawImageF(aImg:GetImage(), pObj.mSmPos.x, pObj.mSmPos.y, aRect);
	else
		pG:DrawImage(aImg:GetImage(), pObj.mSmPos.x, pObj.mSmPos.y, aRect);
	end

end


