function MoveChooseTankPanels(where)
	SendMessage("Choose tank panel mover", "move to "..where)				
	Sound:PlaySample("panel_moving")
end

function DontGrowProgressBars() --Не нужно расти показателями по возвращении из просмотра мультов
	SendMessage("choose tank fish 1", "stand by")				
	SendMessage("choose tank beauty 1", "stand by")				
	SendMessage("choose tank comfort 1", "stand by")				
	SendMessage("choose tank fish 2", "stand by")				
	SendMessage("choose tank beauty 2", "stand by")				
	SendMessage("choose tank comfort 2", "stand by")				
	SendMessage("choose tank fish 3", "stand by")				
	SendMessage("choose tank beauty 3", "stand by")				
	SendMessage("choose tank comfort 3", "stand by")				
end

function ChooseTankFunc(message)
	if	--Нажали на книгу
		message == "Choose tank tank 1 pressed" or
		message == "Choose tank tank 2 pressed" or
		message == "Choose tank tank 3 pressed"
	then
		Sound:FadeOutTrack("Intro", 1)
		local newTank = string.sub(message, 18, 18)
		assert(newTank == "1" or newTank == "2" or newTank == "3")
		local currentTank = PermanentStorage.GetLocalString("Current Tank")
		assert(currentTank == "1" or currentTank == "2" or currentTank == "3")
		local tankname = PermanentStorage.GetLocalString("Tank "..newTank.." name")
		PermanentStorage.SetLocalString("Tank name", tankname)
		MoveChooseTankPanels("out")
		PermanentStorage.SetLocalString("Current Tank", newTank)
		SendMessage("Aquarium bottom", "Change Aquarium")
		Sound:FadeInTrack("Menu"..PermanentStorage.GetLocalString("Current Tank"), 1, true)
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) and newTank ~= currentTank then
			WriteToLog("Change Tank")
		end
	elseif string.sub(message, 1, 20) == "Choose tank cassete " --Просмотр фильма из кассеты (старого)
	then	
		local filmName = string.sub(message, 21, 30)
		SendMessage("post:lua:MovieShow", "Choose tank casset darkned to "..filmName)	
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			if filmName == "scene11" then
				WriteToLog("Re Show Movie: Intro")
			else 
				WriteToLog("Re Show Movie: "..filmName)
			end
		end
	elseif message == "Choose tank help button pressed" then	--Кнопка "?"	
		SendMessage("Choose tank modal dialog", "instantiate ChooseTankHelpTemplate")
		SendMessage("Help mover", "report arrival to null")
		SendMessage("Help mover", "set arrival message null")
		SendMessage("Help mover", "move to in")
		Sound:PlaySample("window_moving")
	elseif message == "Choose tank help ok button pressed" then
		SendMessage("Choose tank modal dialog", "hide")
		SendMessage("Help mover", "report arrival to null")
		SendMessage("Help mover", "set arrival message null")
		SendMessage("Help mover", "move to out")
		Sound:PlaySample("window_moving")
	
	elseif message == "Lock 3" then		--Тест анлока
		PermanentStorage.SetLocalBool("3 tank unlocked",false)	
		SendMessage("post:lua:ChooseTankFunc","Enter choose tank")	
	
	elseif message == "Lock 2" then		--Тест анлока
		PermanentStorage.SetLocalBool("2 tank unlocked",false)	
		SendMessage("post:lua:ChooseTankFunc","Enter choose tank")	
			
	elseif message == "Set Gold Current" then	
		local currentTank = PermanentStorage.GetLocalString("Current Tank")--Поставить текущий кубок золотым, последний показываемый - серебрянным, для тестов
		PermanentStorage.SetLocalString(currentTank.." Cup","Gold")
		PermanentStorage.SetLocalString(currentTank.." Cup Last Show","Silver")
		SendMessage("post:lua:ChooseTankFunc","Enter choose tank")	
		
	elseif message == "Unset film casettes" then	--Убрать мегакубок
		PermanentStorage.SetLocalBool("is show scene4", false)			
		PermanentStorage.SetLocalBool("mega cup showed", false)		
		
	elseif message == "Set Silver Current" then	--Поставить текущий кубок серебрянным, последний показываемы - NONE, для тестов
		local currentTank = PermanentStorage.GetLocalString("Current Tank")
		PermanentStorage.SetLocalString(currentTank.." Cup","Silver")
		PermanentStorage.SetLocalString(currentTank.." Cup Last Show","None")
		SendMessage("post:lua:ChooseTankFunc","Enter choose tank")	
		
	elseif message == "Screen darkening for shop" then	--Затемнились для магазина
		SendMessage("Screen", "clear children list")
		SendMessage("Screen", "template AnyShopTemplate")		
		SendMessage("Screen", "create top instance")
		SendMessage("Screen", "template BrighteningTemplate")
		SendMessage("Screen", "create top instance")
		MoveShopPanels("in")					
		Sound:FadeOutTrack("Intro", 1)
		local currentTank = PermanentStorage.GetLocalString("Current Tank")
		Sound:FadeInTrack("Menu"..currentTank , 1, true)
	elseif message == "Shop button pressed" then	--Переходим в магазин по кнопке
		MoveChooseTankPanels("out")
		SendMessage("Screen", "template DarkeningTemplate")
		SendMessage("Screen", "defineText [receiver] post:lua:ChooseTankFunc")
		SendMessage("Screen", "defineText [message] Screen darkening for shop")
		SendMessage("Screen", "create top instance")			
		
	elseif message == "Choose tank fly cassete" then	--Кассета полетела(для показа)
		MoveChooseTankPanels("out")		
		
	elseif message == "Cassete on position" then	--Прилетела кассета (на место)
		MoveChooseTankPanels("in")				
		local cup1 = PermanentStorage.GetLocalStringOrDef("1 Cup","None")
		local cup2 = PermanentStorage.GetLocalStringOrDef("2 Cup","None")
		local cup3 = PermanentStorage.GetLocalStringOrDef("3 Cup","None")
		local cup3 = PermanentStorage.GetLocalStringOrDef("3 Cup","None")
		
		local show1 = PermanentStorage.GetLocalBoolOrDef("is show scene1",false)
		local show2 = PermanentStorage.GetLocalBoolOrDef("is show scene2",false)
		local show3 = PermanentStorage.GetLocalBoolOrDef("is show scene3",false)
		local show4 = PermanentStorage.GetLocalBoolOrDef("is show scene4",false)
		--Мы смотрим какая сцена должна была показываться по кубкам
		--Если показывалась в первы раз - продолжаем сценарий
		if not show1 and (cup1 == "Silver") then
			PermanentStorage.SetLocalBool("is show scene1", true)			
			SendMessage("Choose tank control", "try unlock") --Разблокируем второй танк
		end
		if not show2 and (cup2 == "Silver") then
			PermanentStorage.SetLocalBool("is show scene2", true)
			SendMessage("Choose tank control", "try unlock") --Разблокируем третий танк
		end
		if not show3 and (cup3 == "Silver") then
			PermanentStorage.SetLocalBool("is show scene3", true)
			SendMessage("PersDialog", "show all_tanks")	--А теперь собери все кубки
		end
		if not show4 and cup1 == "Gold" and cup2 == "Gold" and cup3 == "Gold" then
			PermanentStorage.SetLocalBool("is show scene4", true)			
			SendMessage("Choose tank control", "show mega cup") --Мегакубок!!!
			PermanentStorage.SetLocalBool("mega cup showed", true)						
		end
		
	elseif message == "Enter choose tank" then
		SendMessage("Screen", "clear children list")	
		SendMessage("Screen", "template ChooseTankTemplate")
		--SendMessage("Screen", "defineText [fromWhere] none")		
		SendMessage("Screen", "create top instance")		
		
	elseif message == "unlock click 2" then	--Нажали на заблокированную
		SendMessage("PersDialog", "show pirate_lock_click")			
			
	elseif message == "unlock click 3" then --Нажали на заблокированную
		SendMessage("PersDialog", "show western_lock_click")				
		
	elseif message == "first star film start" then	--Старт мульта после сообщения деда
		SendMessage("Screen", "template DarkeningTemplate")
		SendMessage("Screen", "defineText [receiver] post:lua:MovieShow")
		SendMessage("Screen", "defineText [message] Choose tank casset darkned to scene1")
		SendMessage("Screen", "create top instance")
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			WriteToLog("Show Movie: scene1")
		end
		
	elseif message == "second star film start" then --Старт мульта после сообщения деда
		SendMessage("Screen", "template DarkeningTemplate")
		SendMessage("Screen", "defineText [receiver] post:lua:MovieShow")
		SendMessage("Screen", "defineText [message] Choose tank casset darkned to scene2")
		SendMessage("Screen", "create top instance")
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			WriteToLog("Show Movie: scene2")
		end
		
	elseif message == "third star film start" then --Старт мульта после сообщения деда
		SendMessage("Screen", "template DarkeningTemplate")
		SendMessage("Screen", "defineText [receiver] post:lua:MovieShow")
		SendMessage("Screen", "defineText [message] Choose tank casset darkned to scene3")
		SendMessage("Screen", "create top instance")
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			WriteToLog("Show Movie: scene3")
		end
		
	elseif message == "megacup film start" then --Старт мульта после сообщения деда
		SendMessage("Screen", "template DarkeningTemplate")
		SendMessage("Screen", "defineText [receiver] post:lua:MovieShow")
		SendMessage("Screen", "defineText [message] Choose tank casset darkned to scene4")
		SendMessage("Screen", "create top instance")
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			WriteToLog("Show Movie: scene4")
			WriteToLog("Gain Cup - Megacup")
		end
		
	elseif message == "book unlocked 2" then
		--Разблокировали вторую
		SendMessage("PersDialog", "show pirate_tank")				
		
	elseif message == "book unlocked 3" then
		--Разблокировали тетью
		SendMessage("PersDialog", "show western_tank")				
		
	elseif message == "cup finished" then	--Прилетел кубок	
		PermanentStorage.SetLocalBool("first time in choose tank",false) --Чтобы потом не появлялось сообщение о первом посещении чузтанка		
		local currentTank = PermanentStorage.GetLocalString("Current Tank")
		local cup = PermanentStorage.GetLocalStringOrDef(currentTank.." Cup","None")
		local mega = PermanentStorage.GetLocalBoolOrDef("mega cup showed",false)
		
		if mega then
			SendMessage("PersDialog", "show mega_cup")												
			
			--Получили звезду
		elseif cup == "Silver" and currentTank == "1" then
			SendMessage("PersDialog", "show caribian_star")		
			if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
				WriteToLog("Gain Cup - First Star")
			end
		elseif cup == "Silver" and currentTank == "2" then
			SendMessage("PersDialog", "show pirate_star")								
			if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
				WriteToLog("Gain Cup - Second Star")
			end
		elseif cup == "Silver" and currentTank == "3" then
			SendMessage("PersDialog", "show western_star")								
			if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
				WriteToLog("Gain Cup - Third Star")
			end
				
		--Получили кубок
		elseif cup == "Gold" and currentTank == "1" then
			if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
				WriteToLog("Gain Cup - First Cup")
			end
			local cup2 = PermanentStorage.GetLocalStringOrDef("2 Cup","None")
			local cup3 = PermanentStorage.GetLocalStringOrDef("3 Cup","None")
			if cup2 ~= "Gold" and cup3 ~= "Gold" then
				SendMessage("PersDialog", "show caribian_cup_pervoe")								
			elseif cup2 == "Gold" and cup3 ~= "Gold" then
				SendMessage("PersDialog", "show caribian_cup_vtoroe")								
			elseif cup3 == "Gold" and cup2 ~= "Gold" then
				SendMessage("PersDialog", "show caribian_cup_tretie")								
			else
				SendMessage("PersDialog", "show caribian_cup")								
			end			
				
		elseif cup == "Gold" and currentTank == "2" then
			if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
				WriteToLog("Gain Cup - Second Cup")
			end
			local cup1 = PermanentStorage.GetLocalStringOrDef("1 Cup","None")
			local cup3 = PermanentStorage.GetLocalStringOrDef("3 Cup","None")
			if cup1 ~= "Gold" and cup3 ~= "Gold" then
				SendMessage("PersDialog", "show pirate_cup_pervoe")								
			elseif cup1 == "Gold" and cup3 ~= "Gold" then
				SendMessage("PersDialog", "show pirate_cup_vtoroe")								
			elseif cup3 == "Gold" and cup1 ~= "Gold" then
				SendMessage("PersDialog", "show pirate_cup_tretie")								
			else
				SendMessage("PersDialog", "show pirate_cup")								
			end			
				
		elseif cup == "Gold" and currentTank == "3" then
			if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
				WriteToLog("Gain Cup - Third Cup")
			end
			local cup1 = PermanentStorage.GetLocalStringOrDef("1 Cup","None")
			local cup2 = PermanentStorage.GetLocalStringOrDef("2 Cup","None")
			if cup1 ~= "Gold" and cup2 ~= "Gold" then
				SendMessage("PersDialog", "show western_cup_pervoe")								
			elseif cup1 == "Gold" and cup2 ~= "Gold" then
				SendMessage("PersDialog", "show western_cup_vtoroe")								
			elseif cup2 == "Gold" and cup1 ~= "Gold" then
				SendMessage("PersDialog", "show western_cup_tretie")								
			else
				SendMessage("PersDialog", "show western_cup")								
			end			
		end				
		MoveChooseTankPanels("in")	
		
	elseif message == "book finished" then
		--Зашли через книгу
		MoveChooseTankPanels("in")
		local firstTime = PermanentStorage.GetLocalBoolOrDef("first time in choose tank",true)	
		local secondTime = PermanentStorage.GetLocalBoolOrDef("second time in choose tank", false)
		if firstTime then		
			SendMessage("PersDialog", "show kabinet")					
			PermanentStorage.SetLocalBool("first time in choose tank",false)
			PermanentStorage.SetLocalBool("second time in choose tank", true)
		end
		if secondTime then
			SendMessage("Choose tank control", "showtemplate SecondMessageInChooseTank")
			PermanentStorage.UndefLocalName("second time in choose tank")
		end
		
	elseif message == "let exit" then
		--Можно выходить. Но на следующем апдейте
		SendMessage("post:lua:ChooseTankFunc","Choose tank darkened to exit")					
		
	elseif message == "Choose tank darkened to exit" then	
		--Выход в магазин
		SendMessage("Screen", "clear children list")
		SendMessage("Screen", "template AnyShopTemplate")		
		SendMessage("Screen", "create top instance")
		--local currentTank = PermanentStorage.GetLocalString("Current Tank")
		MoveShopPanels("in")
		--SendMessage("Shop cup alpha changer", "change alpha to 1.0")
		--SendMessage(currentTank.." Aquarium bottom", "entered shop")

		--SendMessage("lua:TutorialFunc", "Main screen panel out for shop")	
	else
		assert(false, "Unknown message "..message)
	end
end