function MoveShopPanels(where)
	SendMessage("Shop mover", "move to "..where)
	SendMessage("Shop left top panel mover", "move to "..where)
	SendMessage("Shop right top panel mover", "move to "..where)
	Sound:PlaySample("panel_moving")
end

function SafeMoveShopPanels(where)
	if not PermanentStorage.GetLocalBoolOrDef("Move mode", false) and not PermanentStorage.GetLocalBoolOrDef("inTutorial", false) and not PermanentStorage.GetLocalBoolOrDef("inHelp", false) then
		SendMessage("Shop mover", "move to "..where)
		SendMessage("Shop left top panel mover", "move to "..where)
		SendMessage("Shop right top panel mover", "move to "..where)
		Sound:PlaySample("panel_moving")
	end
end

function Greetings(message)
	if PermanentStorage.GetGlobalBoolOrDef("dev", false) then
		WriteToLog("Greetings "..message)
	end
	if message == "show" then
		SendMessage("lua:ChooseTankFunc", "Shop button pressed")
		SendMessage("Timed messages", "post:lua:Greetings, continue show, 0.70")
	elseif message == "continue show" then
		SendMessage("Greeting modal dialog", "clear")
		SendMessage("Greeting modal dialog", "instantiate FinalGreetingsTemplate")
		SendMessage("Final Greetings mover", "move to in")
		Sound:PlaySample("greeting_card")
	elseif message == "hide" then
		SendMessage("Final Greetings mover", "move to out")
		SendMessage("Greeting modal dialog", "hide")
		Sound:PlaySample("window_moving")
	end	
end

function Hints(message)
	if IsReceiver("HintsMutable") then
		if message == "create EyeHint" then
			PermanentStorage.SetLocalBool("EyeHintsShown", true)
			SendMessage("HintsMutable", "clear children list")
			SendMessage("HintsMutable", "template EyeHintTemplate")
			SendMessage("HintsMutable", "create top instance")
			SendMessage("ShopHint", "show")
			Sound:PlaySample("hint_show")
		elseif message == "create MyTanksHint" then
			PermanentStorage.SetLocalBool("MyTanksHintsShown", true)
			SendMessage("HintsMutable", "clear children list")
			SendMessage("HintsMutable", "template MyTanksHintTemplate")
			SendMessage("HintsMutable", "create top instance")
			SendMessage("ShopHint", "show")
			Sound:PlaySample("hint_show")
		else
			WriteToLog("wrong message -> "..message)
		end
	else 
		WriteToLog("HintsMutable does not exist")
	end	
end

function ShopFunc(message)
	if message == "Show podskazka pro mouse clear" then
		if PermanentStorage.GetGlobalBoolOrDef("dev", false) then
			PermanentStorage.SetLocalBool("Show podskazka pro mouse", true)
			PermanentStorage.SetLocalBool("Show podskazka pro mouse 2", true)
		end
	elseif message == "Shop tank name pressed" then
		local currentTank = PermanentStorage.GetLocalString("Current Tank")
		local oldTankName = PermanentStorage.GetLocalString("Tank name")
		SendMessage("Shop modal dialog", "instantiate TankNameEditTemplate")
		SendMessage("Tank name mover", "move to in")
		SendMessage("Tank name edit", "set value "..oldTankName)
		--SendMessage("ShopTipsManager", "Pause")
		Sound:PlaySample("window_moving")
	elseif message == "Enter tank name dialog ok pressed" then
		local currentTank = PermanentStorage.GetLocalString("Current Tank")
		local newTankName = SendMessageReply("Tank name edit", "get value")
		while string.len(newTankName) > 0 and string.find(newTankName, "%s") == 1 do 
			newTankName = string.sub(newTankName, 2);
		end
		if string.len(newTankName) > 0 then
			PermanentStorage.SetLocalString("Tank name", newTankName)
			PermanentStorage.SetLocalString("Tank "..currentTank.." name", newTankName)
			SendMessage("Tank name edit", "disable cursor")
			SendMessage("Tank name mover", "move to out")
			SendMessage("Shop modal dialog", "hide")
			--SendMessage("ShopTipsManager", "Continue")
			Sound:PlaySample("window_moving")
		end
	elseif message == "Shop help button pressed" then
		--start help window
		SendMessage("Shop modal dialog", "instantiate ShopHelpTemplate")
		SendMessage("Help mover", "report arrival to null")
		SendMessage("Help mover", "set arrival message null")
		SendMessage("Help mover", "move to in")
		PermanentStorage.SetLocalBool("inHelp", true)
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			WriteToLog("Help Shop")
		end
		Sound:PlaySample("window_moving")
	elseif message == "Progress bar pressed" then
		--start help window with last page
		SendMessage("Shop modal dialog", "instantiate ShopHelpTemplate")
		SendMessage("Help mover", "report arrival to null")
		SendMessage("Help mover", "set arrival message null")
		SendMessage("Help mover", "move to in")
		SendMessage("post:Main screen help scroll", "set -1470")
		Sound:PlaySample("window_moving")
	elseif message == "Shop help ok button pressed" then
		SendMessage("Shop modal dialog", "hide")
		SendMessage("Help mover", "report arrival to null")
		SendMessage("Help mover", "set arrival message null")
		SendMessage("Help mover", "move to out")
		PermanentStorage.SetLocalBool("inHelp", false)
		Sound:PlaySample("window_moving")
	elseif message == "Enter tank name dialog cancel pressed" then
		SendMessage("Tank name edit", "disable cursor")
		SendMessage("Tank name mover", "move to out")
		SendMessage("Shop modal dialog", "hide")
		--SendMessage("ShopTipsManager", "Continue")
		Sound:PlaySample("window_moving")
	elseif message == "Won a cup" then
		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")
		local tankId = PermanentStorage.GetLocalString("Current Tank")
		PermanentStorage.SetLocalBool(tankId.." ShowCupEffect", true)
		SendMessage("Won cup reminder", "set delay 2.0")
		SendMessage("Won cup reminder", "set message Won a cup after block")
		SendMessage("Won cup reminder", "report to lua:ShopFunc")

		SendMessage("Fish indicator", "freeze 1.0")
		SendMessage("Beauty indicator", "freeze 1.0")
		SendMessage("Comfort indicator", "freeze 1.0")
	elseif message == "Won a cup after block" then
		SendMessage("Screen", "template BeforeWonCupTemplate")
		SendMessage("Screen", "create top instance")
		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")
		SendMessage("before won cup", "show")
		MoveShopPanels("out")
		--SendMessage("Shop cup alpha changer", "change alpha to 0.0")
		SendMessage("Won cup reminder", "set delay 5.0")
		SendMessage("Won cup reminder", "set message Won a cup after pause")
		SendMessage("Won cup reminder", "report to lua:ShopFunc")
	elseif message == "Won a cup after pause" then
		SendMessage("Screen", "erase top child")
			-- ZGlass
		SendMessage("Screen", "erase top child")
			-- BeforeWonCup
		SendMessage("Screen", "erase top child")
			-- ZGlass
		local tankId = PermanentStorage.GetLocalString("Current Tank")
		local cup = PermanentStorage.GetLocalString(tankId.." Cup")
		local templateName = nil
		if cup == "Bronze" and (tankId == "1" or tankId == "2") then
			templateName = "WonNotLastBronzeCupTemplate"
		elseif cup == "Bronze" and (tankId == "3") then
			templateName = "WonLastBronzeCupTemplate"
		elseif cup == "Silver" then
			templateName = "WonASilverCupTemplate"
		elseif cup == "Gold" then
			local cup1 = PermanentStorage.GetLocalString("1 Cup")
			local cup2 = PermanentStorage.GetLocalString("2 Cup")
			local cup3 = PermanentStorage.GetLocalString("3 Cup")
			if cup1 ~= "Gold" or cup2 ~= "Gold" or cup3 ~= "Gold" then
				templateName = "WonNotLastGoldCupTemplate"
			else
				templateName = "WonLastGoldCupTemplate"
			end
		else
			assert(false, "tankId="..tankId.." cup="..cup)
		end
		assert(templateName ~= nil)
		SendMessage("Shop modal dialog", "instantiate "..templateName)
		SendMessage("Cup panel mover", "move to in")
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			local player = PermanentStorage.GetActivePlayerName()
			WriteToLogColor("Player '"..player.."' won "..cup.." cup in tank "..tankId, "Red")
			--SendMessage("post:lua:BetaFunc", "Duplicate player won cup")
			--SendMessage("post:lua:BetaFunc", "Clear cup time")
		end
		Sound:SetLowVolumeTime(6.0, 0.4)
	elseif message == "Won cup panel stay in shop button pressed" then
		SendMessage("Fish indicator", "unfreeze")
		SendMessage("Beauty indicator", "unfreeze")
		SendMessage("Comfort indicator", "unfreeze")
		SendMessage("Cup panel mover", "move to out")
		SendMessage("Shop modal dialog", "hide")
		MoveShopPanels("in")
		SendMessage("Sell mover", "move to out")
		--SendMessage("Shop cup alpha changer", "change alpha to 1.0")
		SendMessage("CupRenderElement", "EffectShow")
		PermanentStorage.SetLocalBool(PermanentStorage.GetLocalString("Current Tank").." ShowCupEffect", false)
	elseif message == "Choose tank button pressed" then
		PermanentStorage.SetLocalBool("NeedMyTanksShown", false)
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			WriteToLog("My_Tanks Pressed")
		end
		SendMessage("Aquarium bottom", "exit from shop")
		local tankname = PermanentStorage.GetLocalString("Tank name")
		local tankId = PermanentStorage.GetLocalString("Current Tank")
		Sound:FadeOutTrack("Menu"..tankId, 1)
		Sound:FadeInTrack("Intro", 1, true)
		PermanentStorage.SetLocalString("Tank "..tankId.." name", tankname)
		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")
			-- Блокировка экрана
		--SendMessage("Cup panel mover", "move to out")
		--SendMessage("Shop modal dialog", "hide")
		MoveShopPanels("out")		
		SendMessage("TimedSMS", "post:lua:ShopFunc, Shop panel out for choose tank, 0.4")
	elseif message == "Shop panel out for choose tank" then
		SendMessage("Screen", "clear children list")
		SendMessage("lua:ChooseTankFunc", "Enter choose tank")
	elseif message == "Shop dive now button pressed" then
		if PermanentStorage.GetLocalBool("inTutorial") and IsReceiver("Tutorial") then
			SendMessage("Tutorial", "next")
		end
		SendMessage("Aquarium bottom", "exit from shop")
		-- SendMessage("lua:ShopFunc", "Shop done button pressed")

		-- MoveMainScreenPanels("out", "null", "null")
		-- SendMessage("Main screen cup alpha changer", "change alpha to 0.0")
		MoveShopPanels("out")
		--SendMessage("Screen", "template DarkeningTemplate")
		--SendMessage("Screen", "defineText [receiver] post:lua:ShopFunc")
		--SendMessage("Screen", "defineText [message] Shop darkened for game field")
		--SendMessage("Screen", "create top instance")
		ISpyFunc("Load level")
	elseif message == "Shop darkened for game field" then
		-- Sound:FadeOutTrack("Menu", 1.0)
		-- Sound:DelayPlayTrack("Game", 1.0, 1.0, true)
		-- ISpyFunc("Show gamefield")
		--ISpyFunc("Load level")
	elseif message == "Shop done button pressed" then
		--if TutorialFunc("Shop done button pressed") then
		--	return
		--end
		SendMessage("Aquarium bottom", "exit from shop")
		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")
			-- Блокировка экрана
		MoveShopPanels("out")
		SendMessage("TimedSMS", "post:lua:ShopFunc, Shop panel out for main menu, 0.4")
		SendMessage("Tutorial", "hide")
		--SendMessage("Move items message mover", "move to out")
		PermanentStorage.SetLocalString("Move in button mover", "out")
			-- на всякий случай, если были в режиме перетаскивания
		--SendMessage("Shop cup alpha changer", "change alpha to 0.0")
	elseif message == "Shop move button pressed" then
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			WriteToLog("Press Design")
		end
		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")
			-- Блокировка экрана
		MoveShopPanels("out")
		SendMessage("TimedSMS", "post:lua:ShopFunc, Shop panels out for move mode, 0.4")
		PermanentStorage.SetLocalBool("Move mode", true)
		SendMessage("Sell target", "mode sell")
	elseif message == "Shop panels out for move mode" then
		if not PermanentStorage.GetLocalBoolOrDef("HelpInMoveModeShown", false) then
			SendMessage("HelpInMoveMode", "move to in")
			PermanentStorage.SetLocalBool("HelpInMoveModeShown", true)
		end
		SendMessage("Screen", "erase top child")
			-- ZGlass
		--SendMessage("Move items message mover", "move to in")
		PermanentStorage.SetLocalString("Move in button mover", "in")
	elseif message == "Shop move mode done button pressed" then
		SendMessage("HelpInMoveMode", "move to out")
		--SendMessage("Move items message mover", "move to out")
		PermanentStorage.SetLocalString("Move in button mover", "out")
		SendMessage("TimedSMS", "post:lua:ShopFunc, Move mode panels out for shop, 0.2")
		PermanentStorage.SetLocalBool("Move mode", false)
	elseif message == "Move mode panels out for shop" then
		MoveShopPanels("in")
		SendMessage("Sell mover", "move to out")
	elseif message == "Shop panel out for main menu" then
		local currentTank = PermanentStorage.GetLocalString("Current Tank")
		SendMessage("Screen", "clear children list")
		PermanentStorage.SetLocalString("temp:Tutorial main screen panels in after", "shop")
		SendMessage("lua:MainMenuFunc", "Enter main menu")
		--SendMessage("Aquarium bottom", "leaved shop")
		SendMessage("lua:BetaFunc", "Shop to main menu")
	elseif message == "Shop eye button pressed" then
		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")
			-- Блокировка экрана
		MoveShopPanels("out")
		SendMessage("TimedSMS", "post:lua:ShopFunc, Shop panel out for eye, 0.4")
		--SendMessage("Shop cup alpha changer", "change alpha to 0.0")
	elseif message == "Shop panel out for eye" then
		SendMessage("Screen", "clear children list")
		SendMessage("Screen", "template TankOnlyTemplate")
		SendMessage("Screen", "defineText [variable] Current Tank")
		SendMessage("Screen", "defineText [exitMessageReceiver] post:lua:ShopFunc")
		SendMessage("Screen", "defineText [exitMessage] Tank only to shop")
		SendMessage("Screen", "create top instance")
	elseif message == "Tank only to shop" then
		local currentTank = PermanentStorage.GetLocalString("Current Tank")
		--local tankname = PermanentStorage.GetLocalString("Tank "..currentTank.." name")
		--PermanentStorage.SetLocalString("Tank name", tankname)
		SendMessage("Screen", "clear children list")
		--SendMessage("Screen", "template Aquarium"..currentTank.."Template")
		SendMessage("Screen", "template AnyShopTemplate")
		SendMessage("Screen", "create top instance")

		MoveShopPanels("in")
		SendMessage("Sell mover", "move to out")
		--SendMessage("Shop cup alpha changer", "change alpha to 1.0")
		--SendMessage(currentTank.." Aquarium bottom", "entered shop")
	elseif message == "Shop help button pressed" then
		SendMessage("Shop modal dialog", "instantiate ShopHelpTemplate")
		SendMessage("Help mover", "move to in")
		Sound:PlaySample("window_moving")
	elseif message == "Shop help ok button pressed" then
		SendMessage("Shop modal dialog", "hide")
		SendMessage("Help mover", "move to out")
		Sound:PlaySample("window_moving")
	elseif string.sub(message, 1, 15) == "First got 100% " then
		local prefix = string.sub(message, 16)
		SendMessage("100 percents holder", "template "..prefix.."100PercentsTemplate");
		SendMessage("100 percents holder", "create top instance");
		SendMessage("100 percents alpha changer", "change alpha to 1.0");
		SendMessage("100 percents reminder", "set delay 8.0");
		SendMessage("100 percents reminder", "set message change alpha to 0.0");
		SendMessage("100 percents reminder", "report to 100 percents alpha changer");
	else
		assert(false, "Unknown message "..message)
	end
end