function MoveShopPanels(where)
	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

function ShopFunc(message)
	if message == "Enter shop" then
		SendMessage("Screen", "clear children list")
		SendMessage("Screen", "template AnyShopTemplate")
		SendMessage("Screen", "create top instance")
		if PermanentStorage.GetLocalBoolOrDef("temp:Start spawn game", false) then
			SendMessage("lua:SpawnScreenFunc", "Enter spawn screen")
		else
			SendMessage("Shop mover", "move to in")
			SendMessage("TimedSMS", "Shop play panel mover, move to in, 0.3")
			SendMessage("Sell mover", "move to out")
			if PermanentStorage.GetLocalBoolOrDef("temp:place diamonds", false) then
				PermanentStorage.SetLocalBool("temp:place diamonds", false)
				SendMessage("Aquarium bottom", "place diamonds")
			end
			TutorialFunc("Enter shop")
		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
		SendMessage("Shop mover", "move to out")
		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")
		
	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
			return
		end
		
		ShopFunc("Shop mover to out")
		
		SendMessage("Screen", "erase top child")
			-- ZGlass
		
		local tankId = PermanentStorage.GetLocalString("Current Tank")
		--тот кубок, что получили - пишем в cup
		local cup = PermanentStorage.GetLocalString(tankId.." Cup")
		if cup == "Gold" then
			-- если получили золотой кубок, выключаем миниигру в этом аквариуме
			PermanentStorage.SetLocalBool(tankId.." Spawn game active", false)
		end
		local cup2
		local cup3
		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")
		else  -- получили последний золотой кубок
			TwoButtonCupDialog("WonAGoldCupHeader", "won_cup_gold_cup", "WonLastGoldCupText")
			Sound:PlaySample("big_cup_showing_gold")
		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 escape pressed" then
	
		if IsReceiver("Help alpha mover") then
			SendMessage("lua:HelpFunc", "hide")
		else
			SendMessage("lua:ShopFunc", "Shop exit button pressed")
		end
		
	elseif message == "Shop exit button pressed" then
		
		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 == "Plus button pressed" then
	
		SendMessage("New Shop", "plus")
	
	elseif message == "Minus button pressed" then
	
		if PermanentStorage.GetLocalBool("Want tutorial") == false then
			SendMessage("New Shop", "minus")
		end
	
	else
		assert(false, "Unknown message "..message)
	end
end
