function MoveShopPanels(where)
	if IsReceiver("Shop mover") then
		SendMessage("Shop mover", "move to "..where)
		SendMessage("Left top panel mover", "move to "..where)
		SendMessage("Right top panel mover", "move to "..where)
		SendMessage("Play panel mover", "move to "..where)
	end
end


function ShopFunc(message)
	if message == "Enter shop" then
		SendMessage("Screen", "clear children list")
		SendMessage("Screen", "template AnyShopTemplate")
		SendMessage("Screen", "create top instance")
		SendMessage("Shop mover", "move to in")		
		SendMessage("TimedSMS", "Shop play panel mover, move to in, 0.3")
		SendMessage("Sell mover", "move to out")
		TutorialFunc("Enter shop")
		
		if not PermanentStorage.GetLocalBoolOrDef("tooltip: shown shop", false) and
		   not PermanentStorage.GetLocalBoolOrDef("temp:inTutorial", false) then

			ShowHelpSmall(622, 225, "ShopHelp1DoneButtonText", 622, 115, -90)
			PermanentStorage.SetLocalBool("tooltip: shown shop", true)
		end
	
	elseif message == "Shop mover to in" then
		if IsReceiver("Shop mover") then		
			SendMessage("Shop mover", "move to in")
		end
		if IsReceiver("Play panel mover") then
			SendMessage("Play panel mover", "move to in")
		end
	elseif message == "Shop mover to out" then
		if IsReceiver("Shop mover") then
			SendMessage("Shop mover", "move to out")
		end
		SendMessage("Play panel mover", "move to out")
				
	elseif message == "Won a cup" or (message == "cheat:Won a cup" and PermanentStorage.GetGlobalBool("temp:dev")) then

		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")
		local tankId = PermanentStorage.GetLocalString("Current Tank")
		PermanentStorage.SetLocalBool(tankId.." ShowCupEffect", true)
		SendMessage("TimedSMS", "lua:ShopFunc, Won a cup after block, 2.5")
		
	elseif message == "Won a cup after block" then
	
		MoveShopPanels("out")	
		SendMessage("Cup alpha changer", "change alpha to 0.0")
		SendMessage("TimedSMS", "post:lua:ShopFunc, Won a cup after pause, 0.5")
		SendMessage("TimedSMS", "post:lua:ShopFunc, Shop mover to out, 0.5")
		--ShopFunc("Shop mover to out")
		
	elseif message == "Won a cup after pause" then

		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			local player = PermanentStorage.GetActivePlayerName()
			WriteToLogColor("Player '"..player.."' won "..cup.." cup in tank "..tankId, "Red")			
		end
		
		if not IsReceiver("Shop mover") then
			if SendMessageReply("Screen", "name of top") == "ZGlassTemplate" then
				SendMessage("Screen", "erase top child")
			end
			return
		end

		SendMessage("Screen", "erase top child")
			-- ZGlass

		local tankId = PermanentStorage.GetLocalString("Current Tank")
		--тот кубок, что получили - пишем в cup
		local cup = PermanentStorage.GetLocalString(tankId.." Cup")
		local cup2
		local cup3
		if tonumber(tankId) <= 3 then
			if PermanentStorage.GetGlobalString("temp:Ver") == "Full" then
				if tankId == "1" then
					cup2 = PermanentStorage.GetLocalStringOrDef("2 Cup", "None")
					cup3 = PermanentStorage.GetLocalStringOrDef("3 Cup", "None")
				elseif tankId == "2" then
					cup2 = PermanentStorage.GetLocalStringOrDef("1 Cup", "None")
					cup3 = PermanentStorage.GetLocalStringOrDef("3 Cup", "None")
				elseif tankId == "3" then
					cup2 = PermanentStorage.GetLocalStringOrDef("1 Cup", "None")
					cup3 = PermanentStorage.GetLocalStringOrDef("2 Cup", "None")
				end
				if cup == "Bronze" and (cup2 == "None" or cup3 == "None") then -- получили не последний бронзовый кубок
					TwoButtonCupDialog("WonABronzeCupHeader", "won_cup_bronze_cup", "WonNotLastBronzeCupText")
					Sound:PlaySample("big_cup_showing_bronze")
				elseif cup == "Bronze" then	-- получили последний бронзовый кубок
					TwoButtonCupDialog("WonABronzeCupHeader", "won_cup_bronze_cup", "WonLastBronzeCupText")
					Sound:PlaySample("big_cup_showing_bronze")
				elseif cup == "Silver" then -- получили серебренный кубок
					TwoButtonCupDialog("WonASilverCupHeader", "won_cup_silver_cup", "WonASilverCupText")
					Sound:PlaySample("big_cup_showing_silver")
				elseif cup == "Gold" and (cup2 ~= "Gold" or cup3 ~= "Gold") then -- получили не последний золотой кубок
					TwoButtonCupDialog("WonAGoldCupHeader", "won_cup_gold_cup", "WonNotLastGoldCupText")
					Sound:PlaySample("big_cup_showing_gold")
				elseif cup == "Gold" and cup2 == "Gold" and cup3 == "Gold" then  -- получили последний золотой кубок
					TwoButtonCupDialog("WonAGoldCupHeader", "won_cup_gold_cup", "WonLastGoldCupText")
					Sound:PlaySample("big_cup_showing_gold")
				end
			else 
				if cup == "Bronze" then
					TwoButtonCupDialog("WonABronzeCupHeader", "won_cup_bronze_cup", "WonLastBronzeCupText")
					Sound:PlaySample("big_cup_showing_bronze")
				elseif cup == "Silver" then
					TwoButtonCupDialog("WonASilverCupHeader", "won_cup_silver_cup", "WonASilverCupText")
					Sound:PlaySample("big_cup_showing_silver")
				elseif cup == "Gold" then
					TwoButtonCupDialog("WonAGoldCupHeader", "won_cup_gold_cup", "WonLastGoldCupText")
					Sound:PlaySample("big_cup_showing_gold")
				end
			end
		else
			if cup == "Bronze" then
				TwoButtonCupDialog("WonABronzeCupHeader", "won_cup_bronze_cup", "WonLastBronzeCupText")
				Sound:PlaySample("big_cup_showing_bronze")
			elseif cup == "Silver" then
				TwoButtonCupDialog("WonASilverCupHeader", "won_cup_silver_cup", "WonASilverCupText")
				Sound:PlaySample("big_cup_showing_silver")
			elseif cup == "Gold" then
				TwoButtonCupDialog("WonAGoldCupHeader", "won_cup_gold_cup", "WonCupInAnyTank")
				Sound:PlaySample("big_cup_showing_gold")
			end
		end
		PermanentStorage.SetLocalBool("SetUpTutorialPause", true)
		
	elseif message == "Won cup panel choose tank button pressed" then
	
		SendMessage("Cup panel mover", "move to out")
		SendMessage("Shop modal dialog", "hide")
		SendMessage("Left top panel mover", "move to in")
		SendMessage("Right top panel mover", "move to in")
		SendMessage("TimedSMS", "post:lua:MainScreenFunc, Main screen panel out for choose tank, 0.4")
		LockScreen()
		
	elseif message == "Won cup panel stay in shop button pressed" then
	
		SendMessage("Cup panel mover", "move to out")
		SendMessage("Shop modal dialog", "hide")
		MoveShopPanels("in")
		SendMessage("Cup alpha changer", "change alpha to 1.0")
	
	elseif message == "Shop done button pressed" then
	
		SendMessage("CSVSTATISTICS", "shop done pressed")
		SendMessage("lua:ShopFunc", "Shop exit")

	elseif message == "Shop exit" then
		
		PermanentStorage.SetLocalString("temp:Current mode", "menu")
		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")
		SendMessage("Aquarium bottom", "exit from shop")
			-- Блокировка экрана
		SendMessage("Shop mover", "move to out")
		--SendMessage("TimedSMS", "Shop play panel mover, move to out, 0.2")
		SendMessage("Shop play panel mover", "move to out")
		SendMessage("TimedSMS", "post:lua:MainScreenFunc, Enter main screen, 0.4")
		PermanentStorage.SetLocalString("Move in button mover", "out")
		
		PermanentStorage.SetLocalBool("tooltip: shown shop", true)
			-- Если закрыли крестиком сами, то в следующий раз
			-- уже не нужно показывать подсказку
			
	elseif message == "Shop help button pressed" then
	
		SendMessage("Shop modal dialog", "instantiate ShopHelpTemplate")
		SendMessage("Help mover", "move to in")

	else
		assert(false, "Unknown message "..message)
	end
end
