_G[gTable] = {};

local aTmpVal = gTable;
cm.SetupTable(_G[aTmpVal]);



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

	local aKey = "MovingToSlot";
	pObj.mCsData:SetVal(aKey, false);

	aKey = "Downsizing";
	pObj.mCsData:SetVal(aKey, false);

	pObj.mAlpha:AncSetCurrent(255);
	pObj.mDiscovered = true;
	_G[aTmpVal].MoveToSlot(pObj, PhKeyToSlotTime, true);

end


-- Called after data being loaded from disk
_G[gTable].OnLoad = function(pObj)

end

-- Called after exiting a level
_G[gTable].OnLevelExit = function(pObj)

   if pObj.mPdata:GetNextLevel() == pObj.mCsData:GetInt("EndLevel") then
      pObj.mIsDone = true;
   	pObj.mCsData:SetVal("Used", true);
   	pObj.mPdata.mBar:RemoveSlot(pObj.mId);
   	pObj.mAlpha:AncSetupChange(255.0, 0.0, PhKeyVanishAfterUse,
         IcAutoNumChgr.IC_ANCM_LINEAR);
   end

end


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

   cm.MoveToSlotUpdate(pObj);
   cm.ZoomOutUpdate(pObj);

end


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

	if pName == "" then
		if pObj.mCurImg == 0 then
			_G[aTmpVal].GetBigger(pObj, PhGetBigTime);
			return true;
		end
		return true;
	else
		cm.ObjDoesNotWork(pObj);
		IcPlaySample("PH_SFX_DOES_NOT_WORK");
	   return false;
	end
	return false;

end


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


	if pObj.mCurImg == 0 then
		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);
	else
		pG:SetColorizeImages(true);
		pG:SetColor(Color(255, 255, 255, 255 - pObj.mAlpha:AncGetVal()));

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

		pG:SetColor(Color(255, 255, 255, pObj.mAlpha:AncGetVal()));
		aImg  = IcImageWrap(pObj.mBigImage);
		assert(aImg);
		aRpos = pObj.mBigPos;
		aRect = aImg:GetCelRect(pObj.mCurCell);
		pG:DrawImage(aImg:GetImage(), aRpos.x, aRpos.y, aRect);
		
		local aStr = pObj.mCsData:GetString("ShowString");
		local aFont= IcFontWrap("PH_FONT_TEXT");
		pG:SetFont(aFont:GetFont());
		pG:SetColor(Color(72, 65, 58, pObj.mAlpha:AncGetVal()));

		local aX     = pObj.mCsData:GetInt("StringX") + aRpos.x;
		local aY     = pObj.mCsData:GetInt("StringY") + aRpos.y + aFont:GetAscent();
		local aWidth = pObj.mCsData:GetInt("StringWidth");
		pG:DrawStringWordWrapped(aStr, aX, aY, aWidth, -1, -1, null);

	end

end

_G[gTable].GetParticleSystemInfo = function(pObj, pPolyNum, pName)
   local gMouseOverTable	= {};
   gMouseOverTable[0]		= false;
   gMouseOverTable[1]		= "PH_PSYS_UNDYING_SPARKLE";
   return gMouseOverTable;
end


-- Called to reduce the size
_G[gTable].NormalSize = cm.ZoomOut;


-- Called on draw
_G[gTable].GetBigger =  function(pObj, aTime1)

	pObj.mCurImg = 1;
	pObj.mAlpha:AncSetupChange(0.0, 255.0, aTime1, IcAutoNumChgr.IC_ANCM_LINEAR);

	local aImg1 = IcImageWrap(pObj.mBigImage);
	pObj.mBigPos.x = (gGobj.mWidth - aImg1:GetCelWidth())/2;
	pObj.mBigPos.y = gGobj.mHeight - aImg1:GetCelHeight() - pObj.mPdata.mBar:GetWorkingHeight() + 4;
	pObj.mFrmPos   = pObj.mBigPos;

	pObj:StopParticleEmission(false);

   local aImg3  = IcImageWrap("PH_IMG_CMN_ZOOM_BOX_CLOSE");
   local aRect1 = aImg1:GetCelRect(0);
   local aRect3 = aImg3:GetCelRect(0);
	local aCbPos = IcVector2d((aRect1.mWidth - aRect3.mWidth)/2 + 6, aRect1.mHeight - aRect3.mHeight - 24);

	pObj.mCb:SetPos(aCbPos);
	pObj.mCb:StartAppearing(aTime1, aTime1);

	pObj.mCsData:SetValf("CbPosX", aCbPos.x);
	pObj.mCsData:SetValf("CbPosY", aCbPos.y);
	pObj.mCsData:SetVal("Time1", aTime1);
	IcPlaySample("PH_SFX_CLOSER_LOOK");
end

-- Moves the key to a slot
_G[gTable].MoveToSlot = cm.MoveToSlot;



