_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)
	print(2+2);
end


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

	if pObj.mState == 1 then
		if not pObj.mAlpha:AncIsChanging() then
			pObj.mState = 2;
			local aFlag = pObj.mCsData:GetString("SetLevelFlag");
			pObj.mPdata.mCsData:SetVal(aFlag, 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
		
      if not cm.GetGlobalBoolIndirect(pObj, "ActivatorFlag1") then
         cm.ShowInfo(pObj, "The painting seems jammed. Maybe it will move later.", 250);
         return true;
      end

      pObj:StartFadeRects(PhFadeAnotherTimeShort);
		pObj.mState   = pObj.mState    + 1;
		pObj.mCurCell = pObj.mCurCell  + 1;
	   pObj.mDiscovered = false;

		pObj:StopParticleEmission(false);
		pObj:SetActive(0, pPolyNum, false);
		IcPlaySample("PH_SFX_PAINTINGSTRAIGHTENED");
		return true;
	else
		cm.ObjDoesNotWork(pObj);
		return true;
	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);
	pG:DrawImage(aImg:GetImage(), aRpos.x, aRpos.y, aRect);

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



