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

   -- Activate the bridge
	if pObj.mState == 0 then

   	local aStartFlag = pObj.mCsData:GetString("ActivatorFlag1");
   	if pObj.mPdata.mCsData:GetBool(aStartFlag) then

	      pObj.mDiscovered = false;
	      pObj:StartFadeRects(PhFadeAnotherTimeLong);
         pObj.mState    = 1;
         pObj.mCurCell  = pObj.mCurCell + 1;
      	pObj:SetActive(0, 0, false);
      	IcPlaySample("PH_SFX_OBJ_USED");
      	
   	end

   elseif pObj.mState == 1 then

      if not pObj.mAlpha:AncIsChanging() then
         pObj.mState = 2;
      end

   end

end


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

	pObj.mDiscovered = true;
	if pName == "" then
      cm.ShowInfo(pObj, "The bridge is broken");
		return true;
	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);
	local aRpos = pObj.mSmPos;
	local aRect = aImg:GetCelRect(pObj.mCurCell);

	if pObj.mState == 1 then
		pG:SetColorizeImages(true);
		pG:SetColor(Color(255, 255, 255, 255 - pObj.mAlpha:AncGetVal()));
		local aRect2 = aImg:GetCelRect(pObj.mCurCell - 1);
      pG:DrawImage(aImg:GetImage(), aRpos.x, aRpos.y, aRect);

		pG:SetColor(Color(255, 255, 255, pObj.mAlpha:AncGetVal()));
      pG:DrawImage(aImg:GetImage(), aRpos.x, aRpos.y, aRect);
      pG:PopState();
      return;
	end

	pG:DrawImage(aImg:GetImage(), aRpos.x, aRpos.y, aRect);

end




