

local time = 0

-- *************************
-- Phoenicia animation
-- *************************
cuurentMult = 0
function AnimationReset()
	if currentMult == 0 then
		PhoeniciaAnimationReset()
	elseif currentMult == 1 then
		BabylonAnimationReset()
	elseif currentMult == 2 then
		EgyptAnimationReset()
	elseif currentMult == 3 then
		CarthAnimationReset()
	elseif currentMult == 4 then
		RomeAnimationReset()
	elseif currentMult == 5 then
		GreeceAnimationReset()
	elseif currentMult == 6 then
		TroyAnimationReset()
	end
end

local scenesTime = {}
local currentAnimationName = "Phoenicia"
local currentScene = 0

animationSpeed = 1.5

scenesTime["Phoenicia"] = {12.0, 24.0, 36.0, -1}
scenesTime["Babylon"] = {12.0, 24.0, 36.0, -1}
scenesTime["Egypt"] = {12.0, 24.0, 36.0, -1}
scenesTime["Carthage"] = {12.0, 24.0, -1}
scenesTime["Rome"] = {12.0, 24.0, -1}
scenesTime["Greece"] = {12.0, 24.0, -1}
scenesTime["Troy"] = {12.0, 24.0, -1}

function SetArtefactScene(sceneNum)

	currentMult = sceneNum-1

	if sceneNum == 1 then
		currentAnimationName = "Phoenicia"
		Phoenicia.Artefact.Artefact:Do("0")
	elseif sceneNum == 2 then
		currentAnimationName = "Babylon"
		Babylon.Artefact.Artefact:Do("1")
	elseif sceneNum == 3 then
		currentAnimationName = "Egypt"
		Egypt.Artefact.Artefact:Do("2")
	elseif sceneNum == 4 then
		currentAnimationName = "Carthage"
		Carth.Artefact.Artefact:Do("3")
	elseif sceneNum == 5 then
		currentAnimationName = "Rome"
		Rome.Artefact.Artefact:Do("4")
	elseif sceneNum == 6 then
		currentAnimationName = "Greece"
		Greece.Artefact.Artefact:Do("5")
	elseif sceneNum == 7 then
		currentAnimationName = "Troy"
		Troy.Artefact.Artefact:Do("6")
	end
	
	local multCaption = GUI:getLayer("Mult"):getWidget("zText2")
	multCaption:AcceptMessage(Message("SetString", currentAnimationName))

end

function EndAnimation()

	if cycleMult then
		currentScene = 0
		AnimationReset()
	else
		Sound:FadeOutTagTracks("Animation", 0.5)

		currentScene = 0

	        local widget = GUI:getLayer("Mult"):getWidget("Panel")
		local fadeWidget = GUI:getLayer("Fade"):getWidget("Fade")
		local animationWidget = GUI:getLayer("Mult"):getWidget("Mult")

		animationWidget:AcceptMessage(Message("Active", 0))
		animationWidget:AcceptMessage(Message("BlackScreen", 1))
		animationWidget:AcceptMessage(Message("ReleaseResources"))

		local param = VariableSet()
		param:setWidget("Widget", fadeWidget)
		param:setColor("To", Color(0, 0, 0, 0))
		param:setBool("PopLayer", true)

		kernel:addController(controlFactory:Create("Fader", param))

		param = VariableSet()
		param:setWidget("Widget", widget)
		param:setColor("To", Color(0, 0, 0, 0))
		param:setBool("PopLayer", true)

		kernel:addController(controlFactory:Create("Fader", param))
		
		if needShieldTip then
			needShieldTip = false
			GUI:getLayer("Map"):getWidget("Map"):AcceptMessage(Message("ShowArtefactTip"))
		end

		RunFlagMover()
	end
end

function __SkipScene()
end

function SkipScene()
	currentScene = currentScene+1
	local sceneTime = scenesTime[currentAnimationName][currentScene]
	if not (sceneTime == -1) then
		time = sceneTime
	else
		EndAnimation()
	end
end

local scene1 = true
local scene2 = true
local scene3 = true
local scene4 = true
local scene5 = true

-- *************************
-- Phoenicia animation
-- *************************
function PhoeniciaAnimationReset()

	time = 0.0

	Phoenicia.Fade.Fade.isVisible = false
	Phoenicia.Fade.Fade.x = 150
	Phoenicia.Fade.Fade.y = 125

	Phoenicia.Ship.WaterEffect.y = 51.0
	Phoenicia.Ship.BackEffect.y = 51.0
	Phoenicia.Ship.Ship.rotX = 0.0
	Phoenicia.Ship.Ship.rotY = -70.0
	Phoenicia.Ship34.Ship.rotY = -70.0

	Phoenicia.Ship.WaterEffect.isVisible = true
	Phoenicia.Ship.BackEffect.isVisible = true
	Phoenicia.Ship.WaterEffect:Do("Reset")
	Phoenicia.Ship.BackEffect:Do("Reset")
	Phoenicia.Ship34.BackEffect:Do("Reset")

	Phoenicia.Water.Ostrov.y = 132.0
	Phoenicia.Water.Ostrov.scale = 0.6

	Phoenicia.Water.Road:Do("Additive")
	
	Phoenicia.Water.layer.isVisible = true
	Phoenicia.Nebo.layer.isVisible = true
	Phoenicia.Oblako.layer.isVisible = true

	PhoeniciaAnimationDo(0.0)
	Phoenicia.Artefact.Artefact:Do("0")
	
	scene1 = true
	scene2 = true
	scene3 = true
	scene4 = true
	
	currentScene = 0
	
	Sound:FadeOutTagTracks("Animation", 0.5)

end

function PhoeniciaAnimationDo(dt)
	time = time + animationSpeed*dt

	local angleTime = getPeriod(time, 1.9)/1.9
	local angle = 0

	if angleTime < 0.5 then
		local factor = ease(angleTime/0.5, 0.05, 0.05)
		angle = lerp(-1, 1, factor)
	else
		local factor = ease((angleTime-0.5)/0.5, 0.05, 0.05)
		angle = lerp(1, -1, factor)
	end
	
	local angleFishTime = getPeriod(time, 0.4)/0.4
	local angleFish = 0

	if angleFishTime < 0.5 then
		local factor = ease(angleFishTime/0.5, 0.05, 0.05)
		angleFish = lerp(-1, 1, factor)
	else
		local factor = ease((angleFishTime-0.5)/0.5, 0.05, 0.05)
		angleFish = lerp(1, -1, factor)
	end


	-- Корабль в профиль
	if time < 12.0 then
		local timeScene = time/12.0

		if scene1 then
			scene1 = false
			Phoenicia.set:setText("Phoenicia1")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Phoenicia1", 0.5, true)
		end
		
		if time < 0.7 then
			local fadeTime = time/0.7
			Phoenicia.Fade.Fade.isVisible = true
                        Phoenicia.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Phoenicia.Fade.Fade.isVisible = false
                end

		if time > 11.3 then
			local fadeTime = (time-11.3)/0.7
			Phoenicia.Fade.Fade.isVisible = true
                        Phoenicia.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

                Phoenicia.Fish.layer.isVisible = true

		Phoenicia.Ship.WaterEffect.isVisible = true
		Phoenicia.Ship.BackEffect.isVisible = true

		Phoenicia.Water.ShipRefl.isVisible = true
		Phoenicia.Water.Ship34Refl.isVisible = false

		Phoenicia.Ship34.layer.isVisible = false
		Phoenicia.Ship.layer.isVisible = true
		Phoenicia.Water.Ostrov.isVisible = false

		Phoenicia.Water.PortBack.isVisible = false
		Phoenicia.PortFront.PortFront.isVisible = false

		Phoenicia.Oblako.Oblako1.x = lerp(130, 80, timeScene)
		Phoenicia.Oblako.Oblako1.y = 170.0

                Phoenicia.Oblako.Oblako1.isVisible = true
		Phoenicia.Oblako.Oblako2.isVisible = false
		Phoenicia.Artefact.layer.isVisible = false

		Phoenicia.Ship.Ship.angle = angle
		Phoenicia.Water.ShipRefl.angle = -angle
		Phoenicia.Ship.Ship.x = lerp(50.0, 200.0, timeScene)
		Phoenicia.Ship.WaterEffect.x = lerp(50.0+70.0, 200.0+70.0, timeScene) --220.0
		Phoenicia.Ship.BackEffect.x = lerp(50.0-50.0, 200.0-50.0, timeScene) --220.0

                Phoenicia.Ship.Ship.scale = 1.0
                Phoenicia.Water.ShipRefl.scale = 1.0
		Phoenicia.Ship.Ship.y = 120.0
		Phoenicia.Water.ShipRefl.x = lerp(50.0, 200.0, timeScene)
		Phoenicia.Water.ShipRefl.y = -20.0
		Phoenicia.Water.Road.y = 50
		Phoenicia.Water.Road.x = 220
		
		Phoenicia.Nebo.Sun.x = 220
		Phoenicia.Nebo.Sun.y = 200
		
		Phoenicia.Glow.Glow.isVisible = true
		Phoenicia.Glow.Glow.x = 220
		Phoenicia.Glow.Glow.y = 200

		Phoenicia.Fish.Akula.x = lerp(-350.0, 550.0, timeScene)
		Phoenicia.Fish.Akula.y = 25+angleFish*0.5
		Phoenicia.Fish.Akula.scale = 0.7
		Phoenicia.Fish.Akula.angle = angleFish

		Phoenicia.Fish.Akula2.x = lerp(-450.0, 650.0, timeScene)
		Phoenicia.Fish.Akula2.y = 15+angleFish*0.5
		Phoenicia.Fish.Akula2.scale = 1.0
		Phoenicia.Fish.Akula2.angle = angleFish


		Phoenicia.Fish.AkulaBack.x = lerp(-400.0, 520.0, timeScene)
		Phoenicia.Fish.AkulaBack.y = 15
		Phoenicia.Fish.AkulaBack.scale = 0.8
		Phoenicia.Fish.AkulaBack.angle = angleFish+2.5
		
		Phoenicia.Fish.AkulaBack2.x = lerp(-310.0, 620.0, timeScene)
		Phoenicia.Fish.AkulaBack2.y = 10
		Phoenicia.Fish.AkulaBack2.scale = 0.6
		Phoenicia.Fish.AkulaBack2.angle = angleFish+1.5
		
		Phoenicia.Fish.AkulaBack3.x = lerp(-440.0, 489.0, timeScene)
		Phoenicia.Fish.AkulaBack3.y = 20
		Phoenicia.Fish.AkulaBack3.scale = 0.4
		Phoenicia.Fish.AkulaBack3.angle = angleFish+3.5



		Phoenicia.Water.Water.x = 0
		Phoenicia.Water.Water.y = 0
		

	end
	
	if time >= 12.0 and time < 24.0 then
		local timeScene = (time-12.0)/12.0
		
		if scene2 then
			scene2 = false
			currentScene = 1
			Phoenicia.set:setText("Phoenicia2")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Phoenicia2", 0.5, true)
		end

		if time < 12.7 then
			local fadeTime = (time-12.0)/0.7
			Phoenicia.Fade.Fade.isVisible = true
                        Phoenicia.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Phoenicia.Fade.Fade.isVisible = false
                end

		if time > 23.3 then
			local fadeTime = (time-23.3)/0.7
			Phoenicia.Fade.Fade.isVisible = true
                        Phoenicia.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

		Phoenicia.Fish.layer.isVisible = false

		Phoenicia.Water.ShipRefl.isVisible = false
		Phoenicia.Water.Ship34Refl.isVisible = true
		Phoenicia.Ship.WaterEffect.isVisible = false
		Phoenicia.Ship.BackEffect.isVisible = false
		Phoenicia.Water.Ostrov.isVisible = true
		Phoenicia.Artefact.layer.isVisible = false
		
		Phoenicia.Water.Road.y = 50
		Phoenicia.Water.Road.x = 57
		
		Phoenicia.Nebo.Sun.x = 57
		Phoenicia.Nebo.Sun.y = 210
		
		Phoenicia.Glow.Glow.isVisible = true
		Phoenicia.Glow.Glow.x = 57
		Phoenicia.Glow.Glow.y = 210

		
		Phoenicia.Oblako.Oblako2.x = lerp(220, 267, timeScene)
		Phoenicia.Oblako.Oblako2.y = 179.0

                Phoenicia.Oblako.Oblako2.isVisible = true
		Phoenicia.Oblako.Oblako1.isVisible = false

		Phoenicia.Water.PortBack.isVisible = false
		Phoenicia.PortFront.PortFront.isVisible = false

		timeScene = (time-12.0)/12.0
		Phoenicia.Ship.layer.isVisible = false
		Phoenicia.Ship34.layer.isVisible = true
		Phoenicia.Ship34.Ship.angle = angle

		local moveFactor = ease(timeScene, 0.0, 0.0)
		Phoenicia.Ship34.Ship.x = lerp(80, 180, moveFactor)
		Phoenicia.Ship34.Ship.y = lerp(100, 110, moveFactor)
		Phoenicia.Ship34.Ship.scale = lerp(1.0, 0.5, timeScene)

		Phoenicia.Ship34.ShipFade.x = Phoenicia.Ship34.Ship.x
		Phoenicia.Ship34.ShipFade.y = Phoenicia.Ship34.Ship.y
		Phoenicia.Water.Ship34Refl.x = Phoenicia.Ship34.Ship.x
		Phoenicia.Water.Ship34Refl.y = Phoenicia.Ship34.Ship.y-179.0*Phoenicia.Ship34.Ship.scale
		Phoenicia.Water.Ship34Refl.scale = Phoenicia.Ship34.Ship.scale
		Phoenicia.Water.Ship34Refl.angle = -Phoenicia.Ship34.Ship.angle
		Phoenicia.Ship34.ShipFade.scale = Phoenicia.Ship34.Ship.scale
		Phoenicia.Ship34.ShipFade.angle = Phoenicia.Ship34.Ship.angle

		Phoenicia.Ship34.ShipFade.color = Color(255, 255, 255, lerp(0, 125, timeScene))
		Phoenicia.Ship34.BackEffect.x = Phoenicia.Ship34.Ship.x+52.0*Phoenicia.Ship34.Ship.scale
		Phoenicia.Ship34.BackEffect.y = Phoenicia.Ship34.Ship.y-71.0*Phoenicia.Ship34.Ship.scale
		
		Phoenicia.Water.Ostrov.x = lerp(230, 189, timeScene)
		Phoenicia.Water.Ostrov.y = 105.0
		Phoenicia.Water.Ostrov.scale = lerp(0.7, 0.8, timeScene)



	end
	
	if time >= 24.0 and time < 36.0 then
		local timeScene = (time-24.0)/12.0
		
		if scene3 then
			scene3 = false
			currentScene = 2
			Phoenicia.set:setText("Phoenicia3")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Phoenicia3", 0.5, true)
		end

		if time < 24.7 then
			local fadeTime = (time-24.0)/0.7
			Phoenicia.Fade.Fade.isVisible = true
                        Phoenicia.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Phoenicia.Fade.Fade.isVisible = false
                end

		if time > 35.3 then
			local fadeTime = (time-35.3)/0.7
			Phoenicia.Fade.Fade.isVisible = true
                        Phoenicia.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

		Phoenicia.Fish.layer.isVisible = false

		Phoenicia.Ship.WaterEffect.isVisible = false
		Phoenicia.Ship.BackEffect.isVisible = true

		Phoenicia.Water.ShipRefl.isVisible = true
		Phoenicia.Water.Ship34Refl.isVisible = false

		Phoenicia.Ship34.layer.isVisible = false
		Phoenicia.Ship.layer.isVisible = true
		Phoenicia.Water.Ostrov.isVisible = false
		Phoenicia.Artefact.layer.isVisible = false
		
		Phoenicia.Water.PortBack.isVisible = true
		Phoenicia.PortFront.PortFront.isVisible = true

		local shx = lerp(50.0, 100, timeScene)
		local shy = 100.0
		local shs = 0.37

		Phoenicia.Ship.Ship.x = shx
		Phoenicia.Ship.Ship.y = shy
		Phoenicia.Ship.Ship.scale = shs
		Phoenicia.Ship.BackEffect.x = lerp(50, 100, timeScene)+20
		Phoenicia.Ship.BackEffect.y = 75

		Phoenicia.Water.ShipRefl.x = shx
		Phoenicia.Water.ShipRefl.y = shy-145.0*shs
		Phoenicia.Water.ShipRefl.scale = shs


		Phoenicia.Water.PortBack.y = 100
		Phoenicia.Water.PortBack.x = lerp(190, 170, timeScene)

		Phoenicia.PortFront.PortFront.x = lerp(370, 270, timeScene)
	end
	
	-- Сцена с артефактом
	if time >= 36.0 and time < 48.0 then
		local timeScene = (time-36.0)/12.0

		if scene4 then
			scene4 = false
			currentScene = 3
			Phoenicia.set:setText("Phoenicia4")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Phoenicia4", 0.5, true)
		end

		Phoenicia.Artefact.layer.isVisible = true

		Phoenicia.Fish.layer.isVisible = false
		Phoenicia.Ship.WaterEffect.isVisible = false
		Phoenicia.Ship.BackEffect.isVisible = false
		Phoenicia.Water.ShipRefl.isVisible = false
		Phoenicia.Water.Ship34Refl.isVisible = false
		Phoenicia.Ship34.layer.isVisible = false
		Phoenicia.Ship.layer.isVisible = false
		Phoenicia.Water.Ostrov.isVisible = false
		Phoenicia.Water.PortBack.isVisible = false
		Phoenicia.PortFront.PortFront.isVisible = false
		Phoenicia.Water.layer.isVisible = false
		Phoenicia.Nebo.layer.isVisible = false
		Phoenicia.Oblako.layer.isVisible = false
		Phoenicia.Glow.Glow.isVisible = false


		
		if time < 36.7 then
			local fadeTime = (time-36.0)/0.7
			Phoenicia.Fade.Fade.isVisible = true
                        Phoenicia.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Phoenicia.Fade.Fade.isVisible = false
                end

		if time > 47.3 then
			local fadeTime = (time-47.3)/0.7
			Phoenicia.Fade.Fade.isVisible = true
                        Phoenicia.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end


		Phoenicia.Artefact.Artefact.x = timeScene
	end

	if time >= 48.0 then
		EndAnimation()
	end


end


-- *************************
-- Babylon animation
-- *************************
function BabylonAnimationReset()

	time = 0.0

	Babylon.Vorota.StenaLeft:Do("WrapH")
	Babylon.City2.DomRight:Do("WrapH")
	Babylon.City2.DomRight2:Do("WrapH")

	Babylon.Vorota.layer.isVisible = true
	Babylon.City2.layer.isVisible = false
	Babylon.CityTower.layer.isVisible = false
	Babylon.City1.layer.isVisible = false
	--Babylon.Nebo.Sun.isVisible = false
	Babylon.Scene3.layer.isVisible = false
	Babylon.Artefact.Artefact.isVisible = false
	Babylon.Pavlin.layer.isVisible = false
	Babylon.Artefact.Artefact:Do("1")

	Babylon.Vorota.PalmLeft:Do("WrapH")

	--Babylon.Nebo.Sun.x = 50
	--Babylon.Nebo.Sun.y = 150
	--Babylon.Nebo.Sun:Do("Reset")

	Babylon.Fade.Fade.x = 150
	Babylon.Fade.Fade.y = 125
	
	Babylon.Pavlin.Pavlin.x = 0.0
	Babylon.Pavlin.Pavlin.y = 0.0

	Babylon.Pavlin.Pero1.x = 0.0
	Babylon.Pavlin.Pero1.y = 40.0
	Babylon.Pavlin.Pero1.rotY = -20.0
	Babylon.Pavlin.Pero1.angle = 0.0

	Babylon.Pavlin.Pero2.x = 0.0
	Babylon.Pavlin.Pero2.y = 40.0
	Babylon.Pavlin.Pero2.rotY = -20.0
	Babylon.Pavlin.Pero2.angle = 0.0

	Babylon.Pavlin.Pero3.x = 0.0
	Babylon.Pavlin.Pero3.y = 40.0
	Babylon.Pavlin.Pero3.rotY = -20.0
	Babylon.Pavlin.Pero3.angle = 0.0

	Babylon.Pavlin.Pero4.x = 0.0
	Babylon.Pavlin.Pero4.y = 40.0
	Babylon.Pavlin.Pero4.rotY = -20.0
	Babylon.Pavlin.Pero4.angle = 0.0

	Babylon.Pavlin.Pero5.x = 0.0
	Babylon.Pavlin.Pero5.y = 40.0
	Babylon.Pavlin.Pero5.rotY = -20.0
	Babylon.Pavlin.Pero5.angle = 0.0

	Babylon.Pavlin.Pero10.x = 0.0
	Babylon.Pavlin.Pero10.y = 40.0
	Babylon.Pavlin.Pero10.rotY = -20.0
	Babylon.Pavlin.Pero10.angle = 0.0

	Babylon.Pavlin.Pero20.x = 0.0
	Babylon.Pavlin.Pero20.y = 40.0
	Babylon.Pavlin.Pero20.rotY = -20.0
	Babylon.Pavlin.Pero20.angle = 0.0

	Babylon.Pavlin.Pero30.x = 0.0
	Babylon.Pavlin.Pero30.y = 40.0
	Babylon.Pavlin.Pero30.rotY = -20.0
	Babylon.Pavlin.Pero30.angle = 0.0

	Babylon.Pavlin.Pero40.x = 0.0
	Babylon.Pavlin.Pero40.y = 40.0
	Babylon.Pavlin.Pero40.rotY = -20.0
	Babylon.Pavlin.Pero40.angle = 0.0

	Babylon.Pavlin.Pero50.x = 0.0
	Babylon.Pavlin.Pero50.y = 40.0
	Babylon.Pavlin.Pero50.rotY = -20.0
	Babylon.Pavlin.Pero50.angle = 0.0
	
	Babylon.Pavlin.Pero.x = 0.0
	Babylon.Pavlin.Pero.y = 40.0
	
	scene1 = true
	scene2 = true
	scene3 = true
	scene4 = true

	currentScene = 0
	
	Sound:FadeOutTagTracks("Animation", 0.5)

	BabylonAnimationDo(0.0)

end

function BabylonAnimationDo(dt)

	time = time + animationSpeed*dt

        -- Сцена 1: приближение к воротам
	if time < 12.0 then

		if time < 0.7 then
			local fadeTime = time/0.7
			Babylon.Fade.Fade.isVisible = true
                        Babylon.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Babylon.Fade.Fade.isVisible = false
                end

		if time > 11.3 then
			local fadeTime = (time-11.3)/0.7
			Babylon.Fade.Fade.isVisible = true
                        Babylon.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
                
		if scene1 then
			scene1 = false
			Babylon.set:setText("Babylon1")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Babylon1", 0.5, true)
		end

		local timeScene = ease(time/12.0, 0.7, 0.0)
		local scale = lerp(0.19, 1.7, timeScene)

		Babylon.Nebo.Nebo.y = 179
		Babylon.Glow.Glow.isVisible = false
		Babylon.Nebo.Sun.x = 50
		Babylon.Nebo.Sun.y = 210

		Babylon.Vorota.City.x = 500
		Babylon.Vorota.City.y = lerp(163, 157, timeScene)
		Babylon.Vorota.City.scale = lerp(1.1, 1.0, timeScene)
		local cityCol = lerp(0, 255, timeScene)
		Babylon.Vorota.City.color = Color(cityCol, cityCol, cityCol, 255)


		Babylon.Vorota.layer.scale = scale
  		Babylon.Vorota.layer.x = 150-500*scale
  		Babylon.Vorota.layer.y = 100-170*scale

		Babylon.Vorota.Vorota.y = 240

		Babylon.Vorota.StenaRight.x = 980+(scale-0.2)*90
		Babylon.Vorota.StenaLeft.x = 20-(scale-0.2)*90
		Babylon.Vorota.StenaRight.scale = 1.0
		Babylon.Vorota.StenaLeft.scale = 1.0

		--Babylon.Vorota.Vorota.x = 275-(scale-0.5)*2*145

		Babylon.Vorota.Pesok.x = 490

		Babylon.Vorota.Pesok.scale = 2.0-scale
		Babylon.Vorota.Pesok.y = -70+100*scale
		Babylon.Vorota.StenaRight.y = 240
		Babylon.Vorota.StenaLeft.y = 240

		Babylon.Vorota.PalmLeft.scale = lerp(0.8, 1.4, timeScene)
		Babylon.Vorota.PalmLeft.x = lerp(350, 250, timeScene)
		Babylon.Vorota.PalmLeft.y = lerp(160, 170, timeScene)
		
		Babylon.Vorota.PalmRight.scale = lerp(0.8, 1.4, timeScene)
		Babylon.Vorota.PalmRight.x = lerp(660, 760, timeScene)
		Babylon.Vorota.PalmRight.y = lerp(160, 170, timeScene)

		--Babylon.Vorota.PalmRight.scale = 0.8
		--Babylon.Vorota.Pesok.y = 20
	end

	-- Сцена 2: панорама города с приближением
	if time >= 12.0 and time < 24.0 then
	
		if time < 12.7 then
			local fadeTime = (time-12.0)/0.7
			Babylon.Fade.Fade.isVisible = true
                        Babylon.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Babylon.Fade.Fade.isVisible = false
                end
                
		if time > 23.3 then
			local fadeTime = (time-23.3)/0.7
			Babylon.Fade.Fade.isVisible = true
                        Babylon.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
                
		if scene2 then
			scene2 = false
			currentScene = 1
			Babylon.set:setText("Babylon2")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Babylon2", 0.5, true)
		end

 		local timeScene = (time-12.0)/12.0
 		local scale = lerp(0.0, 0.83, timeScene)

		Babylon.Vorota.layer.isVisible = false

		Babylon.City2.layer.isVisible = true
		Babylon.CityTower.layer.isVisible = true
		Babylon.City1.layer.isVisible = true
		--Babylon.Nebo.Sun.isVisible = false
		Babylon.Pavlin.layer.isVisible = false
		
		Babylon.Glow.Glow.isVisible = true
		Babylon.Glow.Glow.x = lerp(70, 50, timeScene)
		Babylon.Glow.Glow.y = lerp(200, 210, timeScene)

		Babylon.Nebo.Sun.x = lerp(70, 50, timeScene)
		Babylon.Nebo.Sun.y = lerp(200, 210, timeScene)

		--Babylon.Nebo.Sun.x = 50
		--Babylon.Nebo.Sun.y = 150
 		Babylon.Nebo.Nebo.y = 190
 		Babylon.CityTower.Oblaka.y = 150
 		Babylon.CityTower.Oblaka.x = 350
 		Babylon.CityTower.Oblaka.scale = 2.0

		Babylon.City2.layer.scale = 0.38+scale
		Babylon.City2.layer.x = 150-400*(0.38+scale)
		Babylon.City2.layer.y = 0-360*(scale)

		Babylon.City2.DomLeft.scale = 0.6
		Babylon.City2.DomRight.scale = 0.6

		Babylon.City2.DomLeft2.scale = 0.78
		Babylon.City2.DomRight2.scale = 0.78

		Babylon.City2.DomLeft.x = 120-80*scale
		Babylon.City2.DomRight.x = 685+80*scale

		Babylon.City2.DomLeft.y = 200
		Babylon.City2.DomRight.y = 200

		Babylon.City2.DomLeft2.x = 190-50*scale
		Babylon.City2.DomRight2.x = 625+50*scale

		local scale2 = scale/5.5
		Babylon.City1.layer.scale = 0.44+scale2
		Babylon.City1.layer.x = 150-350*(0.44+scale2)
		Babylon.City1.layer.y = 60-150*scale2

                local scale3 = scale/7.5
		Babylon.CityTower.layer.scale = 0.81+scale3*1.2
		Babylon.CityTower.layer.y = 95
		Babylon.CityTower.layer.x = 170-350*(0.44+scale3*0.6)

	end
	
	-- Сцена 3: панорама города
	if time >= 24.0 and time < 34.0 then
	
		--time = 17.0

		local timeScene = ease((time-24.0)/10.0, 0.0, 0.6)
		local offset = lerp(0, 190, timeScene)

		if time < 24.7 then
			local fadeTime = (time-24.0)/0.7
			Babylon.Fade.Fade.isVisible = true
                        Babylon.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Babylon.Fade.Fade.isVisible = false
                end
                
		if scene3 then
			scene3 = false
			currentScene = 2
			Babylon.set:setText("Babylon3")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Babylon3", 0.5, true)
		end

		Babylon.Glow.Glow.isVisible = true
		Babylon.Glow.Glow.x = 50
		Babylon.Glow.Glow.y = 210

		Babylon.Nebo.Sun.x = 50
		Babylon.Nebo.Sun.y = 210

		Babylon.Scene3.Water.x = lerp(900.0, 150.0, timeScene)+105
		Babylon.Scene3.Water.y = 27
		
		Babylon.Vorota.layer.isVisible = false
		Babylon.City2.layer.isVisible = false
		Babylon.CityTower.layer.isVisible = false
		Babylon.City1.layer.isVisible = false
		--Babylon.Nebo.Sun.isVisible = false
		Babylon.Scene3.layer.isVisible = true
		Babylon.Pavlin.layer.isVisible = true

		Babylon.Nebo.Nebo.y = 179

		Babylon.Scene3.Tower.scale = 1.0
		Babylon.Scene3.Tower.y = 139
		Babylon.Scene3.Tower.x = 190-offset*0.3

		Babylon.Scene3.Garden.x = 500-offset*1.7
		Babylon.Scene3.Sad.x = lerp(900.0, 150.0, timeScene)
		Babylon.Scene3.Sad.y = 125.0

		Babylon.Scene3.Bereg.scale = 1.0
		Babylon.Scene3.Bereg.x = 260-offset*1.3

		Babylon.Scene3.City.scale = 1.0
		Babylon.Scene3.City.y = 74.0
		Babylon.Scene3.City.x = 250-offset*0.7

		Babylon.Pavlin.layer.x = lerp(900.0, 150.0, timeScene)-20.0
		Babylon.Pavlin.layer.y = 50.0
		
		if time >= 30.0 then
			local pavTime = (time-30.0)/4.0
			local f = ease(pavTime, 0.3, 0.3)
			
			Babylon.Pavlin.Pero1.angle = lerp(0, 150, f)
			Babylon.Pavlin.Pero2.angle = lerp(0, 120, f)
			Babylon.Pavlin.Pero3.angle = lerp(0, 90, f)
			Babylon.Pavlin.Pero4.angle = lerp(0, 60, f)
			Babylon.Pavlin.Pero5.angle = lerp(0, 30, f)
			Babylon.Pavlin.Pero10.angle = lerp(0, -150, f)
			Babylon.Pavlin.Pero20.angle = lerp(0, -120, f)
			Babylon.Pavlin.Pero30.angle = lerp(0, -90, f)
			Babylon.Pavlin.Pero40.angle = lerp(0, -60, f)
			Babylon.Pavlin.Pero50.angle = lerp(0, -30, f)
		

			Babylon.Pavlin.Pero.x = 0.0
			Babylon.Pavlin.Pero.y = 40.0
		end
	end
	
	if time >= 34.0 and time < 36.0 then
		if time > 35.3 then
			local fadeTime = (time-35.3)/0.7
			Babylon.Fade.Fade.isVisible = true
                        Babylon.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
	end
	
	-- Сцена с артефактом
	if time >= 36.0  and time < 48.0 then

		if scene4 then
			scene4 = false
			currentScene = 3
			Babylon.set:setText("Babylon4")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Babylon4", 0.5, true)
		end

                Babylon.Glow.Glow.isVisible = false
		Babylon.Scene3.layer.isVisible = false
		Babylon.Pavlin.layer.isVisible = false

		Babylon.Artefact.Artefact.isVisible = true
		Babylon.Artefact.layer.x = 0
		Babylon.Artefact.Artefact.x = (time-36.0)/12.0
		
		if time < 36.7 then
			local fadeTime = (time-36.0)/0.7
			Babylon.Fade.Fade.isVisible = true
                        Babylon.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Babylon.Fade.Fade.isVisible = false
                end

		if time > 47.3 then
			local fadeTime = (time-47.3)/0.7
			Babylon.Fade.Fade.isVisible = true
                        Babylon.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

	end


	if time >= 48.0 then
		EndAnimation()
	end

end

-- *************************
-- Egypt animation
-- *************************
function EgyptAnimationReset()

	time = 0.0
	
	Egypt.Pyramids.layer.isVisible = true
	Egypt.Pyramids.PalmLeft:Do("WrapH")

	--Egypt.Phar.Palm:Do("WrapH")
	Egypt.Phar.Palm.x = 30
	Egypt.Phar.Palm.y = 60
	Egypt.Phar.Palm.scale = 0.7
	
	Egypt.Pyramids.PalmRight.scale = 0.8
	Egypt.Pyramids.PalmLeft.scale = 0.8

	Egypt.City.City.scale = 0.7
	Egypt.City.City.x = 130
	Egypt.City.City.y = 110
	Egypt.City.Cloud.scale = 1.5
	Egypt.City.layer.y = 160

	Egypt.Fade.Fade.x = 150
	Egypt.Fade.Fade.y = 125

	Egypt.Walls.WallRight0:Do("WrapH")
	Egypt.Walls.WallRight1:Do("WrapH")
	Egypt.Walls.LampaRight:Do("WrapH")
	Egypt.Walls.Potolok0:Do("WrapV")
	Egypt.Walls.Potolok1:Do("WrapV")
	Egypt.Freska.Up:Do("WrapV")

	Egypt.Walls.WallLeft0.x = 35
	Egypt.Walls.WallLeft0.y = 125

	Egypt.Walls.WallLeft1.x = 90
	Egypt.Walls.WallLeft1.y = 125
	Egypt.Walls.WallLeft1.scale = 0.592

	Egypt.Walls.WallRight0.x = 300-35
	Egypt.Walls.WallRight0.y = 125

	Egypt.Walls.WallRight1.x = 300-90
	Egypt.Walls.WallRight1.y = 125
	Egypt.Walls.WallRight1.scale = 0.592

	Egypt.Walls.LampaLeft.x = 76
	Egypt.Walls.LampaLeft.y = 115
	Egypt.Walls.LampaLeft.scale = 0.6

	Egypt.Walls.LampaRight.x = 300-76
	Egypt.Walls.LampaRight.y = 115
	Egypt.Walls.LampaRight.scale = 0.6
	
	Egypt.Walls.Potolok0.y = 221
	Egypt.Walls.Potolok1.y = 250-67
	Egypt.Walls.Potolok1.scale = 0.592

	Egypt.Walls.Pol1.scale = 0.592
	Egypt.Walls.Pol1.y = 65

	Egypt.Freska.Freska.x = 150
	Egypt.Freska.Freska.y = 136
	Egypt.Freska.Freska.scale = 0.4
	Egypt.Freska.Pol.y = 90
	Egypt.Freska.Pol.scale = 0.7

	Egypt.Glow.Glow:Do("Additive")

	Egypt.Nebo.Sun.x = 220
	Egypt.Nebo.Sun.y = 200

	Egypt.Artefact.Artefact.isVisible = false

	--Egypt.Phar.CatRight:Do("WrapH")
	
	scene1 = true
	scene2 = true
	scene3 = true
	scene4 = true
	
	currentScene = 0
	
	Sound:FadeOutTagTracks("Animation", 0.5)

	EgyptAnimationDo(0.0)


end

function EgyptAnimationDo(dt)

	time = time+animationSpeed*dt

	-- Сцена с городом и пирамидами
	if time < 12.0 then
		local timeScene = ease(time/12.0, 0.2, 0.0)
		Egypt.Pyramids.layer.isVisible = true
		Egypt.City.layer.isVisible = true
		Egypt.Phar.layer.isVisible = false
		Egypt.Ground.layer.isVisible = false
		Egypt.Walls.layer.isVisible = false
		Egypt.Freska.layer.isVisible = false
		Egypt.Artefact.Artefact.isVisible = false
		Egypt.Glow.Glow.isVisible = false
		
		if scene1 then
			scene1 = false
			Egypt.set:setText("Egypt1")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Egypt1", 0.5, true)
		end

		if time < 0.7 then
			local fadeTime = time/0.7
			Egypt.Fade.Fade.isVisible = true
                        Egypt.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Egypt.Fade.Fade.isVisible = false
                end

		if time > 11.3 then
			local fadeTime = (time-11.3)/0.7
			Egypt.Fade.Fade.isVisible = true
                        Egypt.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
                
                Egypt.Pyramids.Pyramid.x = lerp(80, 30, timeScene)
                Egypt.Pyramids.Pyramid.y = lerp(340, 330, timeScene)


		Egypt.Pyramids.PalmRight.x = lerp(260, 420, timeScene)
		Egypt.Pyramids.PalmLeft.x = lerp(40, -120, timeScene)

		Egypt.Pyramids.PalmLeft.y = lerp(80, 340, timeScene)
		Egypt.Pyramids.PalmRight.y = lerp(80, 340, timeScene)

		Egypt.Pyramids.PalmLeft.angle = lerp(-10, 25, timeScene)
		Egypt.Pyramids.PalmRight.angle = lerp(10, -25, timeScene)

		Egypt.Pyramids.layer.y = -lerp(0, 770, timeScene)
		Egypt.Pyramids.layer.scale = lerp(1, 1.9, timeScene)
		Egypt.Pyramids.layer.x = lerp(0, -120, timeScene)
		
		Egypt.Pyramids.Trava.y = lerp(40, 100, timeScene)

		Egypt.City.layer.y = 130-lerp(0, 280, timeScene)
		cityScale = lerp(1, 1.1, timeScene)
		Egypt.City.layer.scale = cityScale
		Egypt.City.layer.x = -150*(cityScale-1.0)
		Egypt.City.Cloud.y = lerp(160, 50, timeScene)

	end

	-- Сцена приближения к храму
	if time >= 12.0  and time < 24.0 then
		local timeScene = (time-12.0)/12.0
		Egypt.Pyramids.layer.isVisible = false
		Egypt.City.layer.isVisible = false
		Egypt.Phar.layer.isVisible = true
		Egypt.Ground.layer.isVisible = true
		Egypt.Walls.layer.isVisible = false
		Egypt.Freska.layer.isVisible = false
		Egypt.Artefact.Artefact.isVisible = false

		if scene2 then
			scene2 = false
			currentScene = 1
			Egypt.set:setText("Egypt2")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Egypt2", 0.5, true)
		end


		if time < 12.7 then
			local fadeTime = (time-12.0)/0.7
			Egypt.Fade.Fade.isVisible = true
                        Egypt.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Egypt.Fade.Fade.isVisible = false
                end

		if time > 23.3 then
			local fadeTime = (time-23.3)/0.7
			Egypt.Fade.Fade.isVisible = true
                        Egypt.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
                
		Egypt.Phar.Palm.x = lerp(270, 290, timeScene)
		Egypt.Phar.Palm.y = lerp(60, 80, timeScene)
		Egypt.Phar.Palm.scale = lerp(0.7, 1.0, timeScene)

                Egypt.Phar.Pyr.x = lerp(50, 60, timeScene)
		Egypt.Phar.Pyr.y = lerp(165, 150, timeScene)
		Egypt.Phar.Pyr.scale = lerp(1.5, 1.0, timeScene)


		Egypt.Ground.layer.y = -220-lerp(0, 340, timeScene)
		Egypt.Ground.layer.scale = lerp(1, 2, timeScene)
		Egypt.Ground.layer.x = lerp(0, -150, timeScene)
		
		Egypt.Glow.Glow.isVisible = true
		Egypt.Glow.Glow.scale = 6.0
		Egypt.Glow.Glow.color = Color(255, 255, 100, 120)
		Egypt.Glow.Glow.angle = lerp(0, 60, timeScene)
		
       		Egypt.Glow.Glow.x = 220
		Egypt.Glow.Glow.y = 200

		
		if time > 20.0 and time < 23.0 then
			local fadeTime = (time-20.0)/3.0
			Egypt.Glow.Glow.color = Color(255, 255, 100, lerp(120, 0, fadeTime))
		elseif time >= 23.0 then
			Egypt.Glow.Glow.isVisible = false
		end


		Egypt.Phar.layer.scale = 0.5+lerp(0, 0.5, timeScene)
		Egypt.Phar.layer.x = 80-lerp(0, 70, timeScene)
		Egypt.Phar.layer.y = 70-lerp(0, 50, timeScene)

		--Egypt.Phar.CatLeft.x = 50-lerp(0, 35, timeScene)
		Egypt.Phar.CatRight.x = 70-lerp(0, 15, timeScene)

		--Egypt.Phar.CatLeft.y = 90
		Egypt.Phar.CatRight.y = 40

		--Egypt.Phar.CatLeft.scale = 0.7
		Egypt.Phar.CatRight.scale = 0.3


	end

	-- Сцена в храме
	if time >= 24.0 and time < 36.0 then
	
		local timeScene = (time-24.0)/12.0
		
		if scene3 then
			scene3 = false
			currentScene = 2
			Egypt.set:setText("Egypt3")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Egypt3", 0.5, true)
		end

		
		if time < 24.7 then
			local fadeTime = (time-24.0)/0.7
			Egypt.Fade.Fade.isVisible = true
                        Egypt.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Egypt.Fade.Fade.isVisible = false
                end

		if time > 35.3 then
			local fadeTime = (time-35.3)/0.7
			Egypt.Fade.Fade.isVisible = true
                        Egypt.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

		Egypt.Pyramids.layer.isVisible = false
		Egypt.City.layer.isVisible = false
		Egypt.Phar.layer.isVisible = false
		Egypt.Ground.layer.isVisible = false
		Egypt.Walls.layer.isVisible = true
		Egypt.Freska.layer.isVisible = true
		Egypt.Artefact.Artefact.isVisible = false

		Egypt.Walls.Fire1.x = 75
		Egypt.Walls.Fire1.y = 180
		
		Egypt.Walls.Fire2.x = 225
		Egypt.Walls.Fire2.y = 180

		Egypt.Glow.Glow.isVisible = true
       		Egypt.Glow.Glow.x = 150
		Egypt.Glow.Glow.y = lerp(140, 150, timeScene)
		Egypt.Glow.Glow.scale = lerp(1.0, 3.0, timeScene)
		
		Egypt.Glow.Glow.angle = lerp(0, -50, timeScene)

		if time < 34.0 then
			local fadeTime = (time-24.0)/10.0
			Egypt.Glow.Glow.color = Color(255, 255, 100, lerp(160, 0, fadeTime))
		else
			Egypt.Glow.Glow.isVisible = false
		end



		local wallFactor = 1.7
		Egypt.Walls.layer.scale = lerp(1.0, wallFactor, timeScene)
		Egypt.Walls.layer.x = lerp(0, (-150*(wallFactor-1.0)), timeScene)
		Egypt.Walls.layer.y = lerp(0, (-100*(wallFactor-1.0)), timeScene)
		
		Egypt.Freska.Freska.scale = lerp(0.5, 0.7, timeScene)
		Egypt.Freska.Freska.y = lerp(136, 150, timeScene)

		Egypt.Freska.Fade.x = 150
		Egypt.Freska.Fade.y = lerp(136, 140, timeScene)
		Egypt.Freska.Fade.scale = lerp(1.0, 1.4, timeScene)
		Egypt.Freska.Fade.color = Color(0, 0, 0, lerp(255, 50, timeScene))

		Egypt.Freska.Pol.y = lerp(90, 80, timeScene)
		Egypt.Freska.Pol.scale = 0.8
		
		Egypt.Freska.Up.y = lerp(190, 200, timeScene)
		Egypt.Freska.Up.scale = 0.8

	end
	
	-- Сцена с артефактом
	if time >= 36.0 and time < 48.0 then
	
		local timeScene = (time-36.0)/12.0

		Egypt.Pyramids.layer.isVisible = false
		Egypt.City.layer.isVisible = false
		Egypt.Phar.layer.isVisible = false
		Egypt.Ground.layer.isVisible = false
		Egypt.Walls.layer.isVisible = false
		Egypt.Freska.layer.isVisible = false
		Egypt.Artefact.Artefact.isVisible = true
		Egypt.Glow.Glow.isVisible = false
		
		if scene4 then
			scene4 = false
			currentScene = 3
			Egypt.set:setText("Egypt4")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Egypt4", 0.5, true)
		end

		
		Egypt.Artefact.Artefact.x = timeScene

		if time < 36.7 then
			local fadeTime = (time-36.0)/0.7
			Egypt.Fade.Fade.isVisible = true
                        Egypt.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Egypt.Fade.Fade.isVisible = false
                end

		if time > 47.3 then
			local fadeTime = (time-47.3)/0.7
			Egypt.Fade.Fade.isVisible = true
                        Egypt.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
	end

	if time >= 48.0 then
		EndAnimation()
	end



end

-- *************************
-- Carthage animation
-- *************************
function CarthAnimationReset()

	time = 0.0
	
	Carth.Fade.Fade.x = 150
	Carth.Fade.Fade.y = 125
	
	Carth.Night.Fade.x = 150
	Carth.Night.Fade.y = 125
	Carth.Night.Sun:Do("Additive")

	Carth.Artefact.Artefact.isVisible = false

	scene1 = true
	scene2 = true
	scene3 = true
	scene4 = true

	currentScene = 0
	
	Sound:FadeOutTagTracks("Animation", 0.5)

	CarthAnimationDo(0.0)

end

function CarthAnimationDo(dt)
	time = time+animationSpeed*dt

	if time < 12.0 then
		local timeScene = time/12.0

		Carth.Mechet.layer.isVisible = true
		Carth.Ground.layer.isVisible = true
		Carth.Nebo.layer.isVisible = true
		Carth.Komnata.layer.isVisible = false
		Carth.Artefact.Artefact.isVisible = false
		Carth.Fontan.layer.isVisible = false
		
		if scene1 then
			scene1 = false
			Carth.set:setText("Carthage1")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Carthage1", 0.5, true)
		end

		if time < 0.7 then
			local fadeTime = time/0.7
			Carth.Fade.Fade.isVisible = true
                        Carth.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Carth.Fade.Fade.isVisible = false
                end

		if time > 11.3 then
			local fadeTime = (time-11.3)/0.7
			Carth.Fade.Fade.isVisible = true
                        Carth.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
                
		if time < 9.0 then
			local fadeTime = time/9.0
			Carth.Night.Fade.isVisible = true
                        Carth.Night.Fade.color = Color(0, 0, 60, lerp(60, 0, fadeTime))
                        
                        local nightColor = Color(lerp(20, 255, fadeTime), lerp(0, 255, fadeTime), lerp(55, 255, fadeTime), 255)

                        Carth.Nebo.NightNebo.isVisible = true
                        Carth.Nebo.NightNebo.color = Color(255, 255, 255, lerp(255, 0, fadeTime))

                        Carth.Nebo.Nebo.color = nightColor
                        Carth.Ground.Ground.color = nightColor
                        Carth.Mechet.Mechet.color = nightColor
                        Carth.Mechet.Pesok.color = nightColor
                        Carth.Mechet.Palm.color = nightColor
                else
                	local fullColor = Color(255, 255, 255, 255)

                        Carth.Nebo.Nebo.color = fullColor
                        Carth.Ground.Ground.color = fullColor
                        Carth.Mechet.Mechet.color = fullColor
                        Carth.Mechet.Pesok.color = fullColor
                        Carth.Mechet.Palm.color = fullColor

                        Carth.Nebo.NightNebo.isVisible = false
	                Carth.Night.Fade.isVisible = false
                end
                
		if time < 6.0 then
			local fadeTime = time/6.0
                        Carth.Nebo.Sun.color = Color(255, lerp(0, 255, fadeTime), lerp(0, 255, fadeTime), lerp(0, 255, fadeTime))
                else
	                Carth.Nebo.Sun.color = Color(255, 255, 255, 255)
                end
                
                Carth.Mechet.Palm.x = lerp(260, 280, timeScene)
                Carth.Mechet.Palm.y = lerp(100, 110, timeScene)
                Carth.Mechet.Palm.angle = 10
                Carth.Mechet.Palm.scale = lerp(0.8, 1.1, timeScene)

		Carth.Mechet.layer.x = 0
		Carth.Ground.layer.x = 0
		Carth.Nebo.layer.x = 0

		Carth.Nebo.Sun.x = lerp(40, 130, timeScene)
		Carth.Nebo.Sun.y = lerp(60, 240, timeScene)
		Carth.Nebo.Sun.scale = lerp(2.3, 1.5, timeScene)

		if time < 3.0 then
			Carth.Night.Sun.isVisible = false
                elseif time < 9.0 then
                	Carth.Night.Sun.isVisible = true
     			local fadeTime = (time-3.0)/6.0
                        Carth.Night.Sun.color = Color(255, 255, 255, lerp(0, 75, fadeTime))
                        Carth.Night.Sun.scale = lerp(0.3, 4.5, fadeTime)
	        else
	        	Carth.Night.Sun.isVisible = true
	        	Carth.Night.Sun.color = Color(255, 255, 255, 75)
	        	Carth.Night.Sun.scale = 4.5
                end


		Carth.Night.Sun.x = lerp(40, 130, timeScene)
		Carth.Night.Sun.y = lerp(60, 240, timeScene)
		--Carth.Night.Sun.scale = lerp(2.3, 2.5, timeScene)

		Carth.Mechet.layer.y = 0
		Carth.Ground.layer.y = 0
		Carth.Nebo.layer.y = 0

		Carth.Mechet.layer.scale = 1
		Carth.Ground.layer.scale = 1
		Carth.Nebo.layer.scale = 1

		Carth.Nebo.layer.x = lerp(-4, 0, timeScene)
		Carth.Nebo.layer.y = 10

		Carth.Mechet.Mechet.y = 120
		Carth.Mechet.Mechet.x = 90-lerp(0, 20, timeScene)
		Carth.Ground.layer.x = lerp(-9, 0, timeScene)
		Carth.Mechet.Pesok.x = 96-lerp(0, 40, timeScene)
		Carth.Mechet.Pesok.y = 46-lerp(0, 4, timeScene)
	end

	if time >=12.0 and time < 24.0 then
		
		--time = 13.0

		local timeScene = (time-12.0)/12.0

		Carth.Mechet.layer.isVisible = true
		Carth.Ground.layer.isVisible = true
		Carth.Nebo.layer.isVisible = true
		Carth.Komnata.layer.isVisible = true
		Carth.Artefact.Artefact.isVisible = false
		Carth.Night.Fade.isVisible = false
		Carth.Nebo.NightNebo.isVisible = false
		Carth.Night.Fade.isVisible = false
		Carth.Night.Sun.isVisible = false
		Carth.Fontan.layer.isVisible = true
		
                local fullColor = Color(255, 255, 255, 255)

                Carth.Nebo.Nebo.color = fullColor
                Carth.Ground.Ground.color = fullColor
                Carth.Mechet.Mechet.color = fullColor
                Carth.Mechet.Pesok.color = fullColor
                Carth.Mechet.Palm.color = fullColor

		
		if scene2 then
			scene2 = false
			currentScene = 1
			Carth.set:setText("Carthage2")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Carthage2", 0.5, true)
		end


		if time < 12.7 then
			local fadeTime = (time-12.0)/0.7
			Carth.Fade.Fade.isVisible = true
                        Carth.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Carth.Fade.Fade.isVisible = false
                end

		if time > 23.3 then
			local fadeTime = (time-23.3)/0.7
			Carth.Fade.Fade.isVisible = true
                        Carth.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
                
                Carth.Fontan.Fontan.x = 150
                Carth.Fontan.Fontan.y = 91
                
                Carth.Fontan.FontanSmall.x = 150
                Carth.Fontan.FontanSmall.y = 104
                
                Carth.Fontan.FontanSpark.x = 150
                Carth.Fontan.FontanSpark.y = 91
                
                Carth.Fontan.FontanUp.x = 150
                Carth.Fontan.FontanUp.y = 122

		Carth.Nebo.layer.x = -4
		Carth.Nebo.layer.y = 10

		Carth.Mechet.Mechet.y = 120
		Carth.Mechet.Mechet.x = 90
		Carth.Ground.layer.x = 9
		Carth.Mechet.Pesok.x = 96
		Carth.Mechet.Pesok.y = 46

		Carth.Mechet.Palm.x = 340
		Carth.Mechet.Palm.y = 90
		Carth.Mechet.Palm.scale = 1.0

		Carth.Nebo.Sun.x = 130
		Carth.Nebo.Sun.y = 240

		local xOff = 50
		local yOff = 120

		Carth.Mechet.layer.scale = 0.5
		Carth.Ground.layer.scale = 0.5
		Carth.Nebo.layer.scale = 0.5

		Carth.Mechet.layer.x = xOff
		Carth.Ground.layer.x = xOff
		Carth.Nebo.layer.x = xOff

		Carth.Mechet.layer.y = yOff
		Carth.Ground.layer.y = yOff
		Carth.Nebo.layer.y = yOff

		Carth.Komnata.Komnata.scale = lerp(1.0, 1.2, timeScene)
		
		Carth.Fontan.TFontan.x = 150
		Carth.Fontan.TFontan.y = 95

		Carth.Fontan.layer.scale = lerp(1.0, 1.5, timeScene)
		Carth.Fontan.layer.x = lerp(0, -74, timeScene)
		Carth.Fontan.layer.y = lerp(0, -50, timeScene)-5

	end

	if time >= 24.0 and time < 36.0 then

		Carth.Mechet.layer.isVisible = false
		Carth.Ground.layer.isVisible = false
		Carth.Nebo.layer.isVisible = false
		Carth.Komnata.layer.isVisible = false
		Carth.Artefact.Artefact.isVisible = true
		Carth.Night.Fade.isVisible = false
		Carth.Fontan.layer.isVisible = false

		if scene3 then
			scene3 = false
			currentScene = 2
			Carth.set:setText("Carthage3")
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Carthage3", 0.5, true)
		end

		
		local timeScene = (time-24.0)/12.0

		if time < 24.7 then
			local fadeTime = (time-24.0)/0.7
			Carth.Fade.Fade.isVisible = true
                        Carth.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Carth.Fade.Fade.isVisible = false
                end

		if time > 35.3 then
			local fadeTime = (time-35.3)/0.7
			Carth.Fade.Fade.isVisible = true
                        Carth.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

                Carth.Artefact.Artefact.x = timeScene
	end

	if time >= 36.0 then
		EndAnimation()
	end

end

-- *************************
-- Rome animation
-- *************************
function RomeAnimationReset()

	time = 0.0
	Rome.Fade.Fade.x = 150
	Rome.Fade.Fade.y = 125
	Rome.Fade.Fade.isVisible = false

	Rome.Columns.Column1.x = 0
	Rome.Columns.Column2.x = 300
	Rome.Columns.Column3.x = 600
	Rome.Columns.Column4.x = 900
	Rome.Columns.Column5.x = 1200
	Rome.Artefact.Artefact.isVisible = false
	
	scene1 = true
	scene2 = true
	scene3 = true
	scene4 = true
	
	currentScene = 0
	
	Sound:FadeOutTagTracks("Animation", 0.5)

	RomeAnimationDo(0.0)

end

function RomeAnimationDo(dt)

	time = time + animationSpeed*dt
	
	--time = 12.7
	
	-- Приближение к колизею
	if time < 12.0 then
		local timeScene = time/12.0

		Rome.Nebo.layer.isVisible = true
		Rome.Ground.layer.isVisible = true
		Rome.Galery.layer.isVisible = false
		Rome.Columns.layer.isVisible = false
		Rome.Artefact.Artefact.isVisible = false
		Rome.Glow.layer.isVisible = true

		if scene1 then
			scene1 = false
			Rome.set:setText("Rome1")

			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Rome1", 0.5, true)
		end

		if time < 0.7 then
			local fadeTime = time/0.7
			Rome.Fade.Fade.isVisible = true
                        Rome.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Rome.Fade.Fade.isVisible = false
                end

		if time > 11.3 then
			local fadeTime = (time-11.3)/0.7
			Rome.Fade.Fade.isVisible = true
                        Rome.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end


		Rome.Ground.Kolizey.scale = lerp(0.6, 1.1, timeScene)
		Rome.Ground.Kolizey.x = lerp(170, 150, timeScene)
		Rome.Ground.Kolizey.y = lerp(90, 80, timeScene)

		Rome.Ground.Gorod.x = lerp(140, 200, timeScene)
		Rome.Ground.Gorod.y = lerp(47, -40, timeScene)
		Rome.Ground.Gorod.scale = lerp(0.5, 1.2, timeScene)

		Rome.Ground.Ground.y = lerp(110, 106, timeScene)
		Rome.Ground.Ground.scale = lerp(1.0, 1.1, timeScene)

		local sunX = lerp(70, 80, timeScene)
		local sunY = lerp(190, 230, timeScene)

		Rome.Nebo.Sun.x = sunX
		Rome.Nebo.Sun.y = sunY
		Rome.Nebo.Sun.scale = 0.6
		Rome.Glow.Glow.x = sunX
		Rome.Glow.Glow.y = sunY
		Rome.Glow.Aura.x = sunX
		Rome.Glow.Aura.y = sunY

	end

	-- Горизонтальная панорама с колоннами
	if time >= 12.0 and time < 24.0 then

		local timeScene = ease((time-12.0)/12.0, 0.0, 0.3)

		Rome.Nebo.layer.isVisible = false
		Rome.Ground.layer.isVisible = false
		Rome.Galery.layer.isVisible = true
		Rome.Columns.layer.isVisible = true
		Rome.Artefact.Artefact.isVisible = false
		Rome.Glow.layer.isVisible = false

		if scene2 then
			scene2 = false
			currentScene = 1
			Rome.set:setText("Rome2")
			
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Rome2", 0.5, true)
		end

		if time < 12.7 then
			local fadeTime = (time-12.0)/0.7
			Rome.Fade.Fade.isVisible = true
                        Rome.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Rome.Fade.Fade.isVisible = false
                end

		if time > 24.3 then
			local fadeTime = (time-24.3)/0.7
			Rome.Fade.Fade.isVisible = true
                        Rome.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
                
                Rome.Galery.Fire1.y = 200
                Rome.Galery.Fire1.x = 480
                
                Rome.Galery.Fire2.y = 200
                Rome.Galery.Fire2.x = 255

                Rome.Galery.Fire3.y = 200
                Rome.Galery.Fire3.x = 40

                Rome.Galery.Fontan.y = 100
                Rome.Galery.Fontan.x = 587


		Rome.Columns.layer.x = lerp(-1000, 0, timeScene)
		Rome.Galery.layer.x = lerp(-420, 0, timeScene)

	end

	-- Сцена с артефактом
	if time >= 24.0 and time < 36.0 then

		local timeScene = (time-24.0)/12.0

		Rome.Nebo.layer.isVisible = false
		Rome.Ground.layer.isVisible = false
		Rome.Galery.layer.isVisible = false
		Rome.Columns.layer.isVisible = false
		Rome.Artefact.Artefact.isVisible = true
		Rome.Glow.layer.isVisible = true

		if scene3 then
			scene3 = false
			currentScene = 2
			Rome.set:setText("Rome3")
			
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Rome3", 0.5, true)
		end

		if time < 24.7 then
			local fadeTime = (time-24.0)/0.7
			Rome.Fade.Fade.isVisible = true
                        Rome.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Rome.Fade.Fade.isVisible = false
                end

		if time > 35.3 then
			local fadeTime = (time-35.3)/0.7
			Rome.Fade.Fade.isVisible = true
                        Rome.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end
                
                Rome.Artefact.Artefact.x = timeScene

	end


	if time >= 36.0 then
		EndAnimation()
	end



end


-- *************************
-- Greece animation
-- *************************
function GreeceAnimationReset()
	Greece.Fade.Fade.x = 150
	Greece.Fade.Fade.y = 125
	time = 0
	--Greece.Ground.Plane1.color = Color(255, 255, 255)
	
	Greece.Artefact.Artefact.isVisible = false
	
	scene1 = true
	scene2 = true
	scene3 = true
	scene4 = true
	
	Greece.Nebo.Sun.x = 220
	Greece.Nebo.Sun.y = 200

	currentScene = 0
	
	Sound:FadeOutTagTracks("Animation", 0.5)

	GreeceAnimationDo(0.0)

end

function GreeceAnimationDo(dt)

	time = time + animationSpeed*dt
	
	--time = 11.6

	-- Горизонтальная панорама
	if time < 12.0 then
	
		Greece.Nebo.layer.isVisible = true
		Greece.Ground.layer.isVisible = true
		Greece.Artefact.Artefact.isVisible = false
		
		if scene1 then
			scene1 = false
			Greece.set:setText("Greece1")

			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Greece1", 0.5, true)
		end

		local timeScene = ease(time/12.0, 0.0, 0.3)

		if time < 0.7 then
			local fadeTime = time/0.7
			Greece.Fade.Fade.isVisible = true
                        Greece.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Greece.Fade.Fade.isVisible = false
                end


		--Greece.Nebo.Nebo.x = 0 --25+lerp(0, 25, timeScene)

		Greece.Ground.Olymp.x = -145+lerp(0, 240, timeScene)
		Greece.Ground.Olymp.y = 96
		Greece.Ground.Olymp.scale = 1.0

		Greece.Ground.Valley.x = -195+lerp(0, 340, timeScene)
		Greece.Ground.Valley.y = 45
		Greece.Ground.Valley.scale = 1.0

		Greece.Ground.Ground.x = -200+lerp(0, 500, timeScene)
		Greece.Ground.Ground.y = 89
		Greece.Ground.Kolonna.x = -620+lerp(0, 730, timeScene)
		Greece.Ground.Kolonna.y = 64

                Greece.Ground.Vino.x = lerp(-900, 80, timeScene)
		Greece.Ground.Vino.y = 185
		Greece.Ground.Vino.scale = 1.0

		Greece.Ground.Ground.scale = 1.0
		Greece.Ground.Kolonna.scale = 1.0

	end

	-- Приближение к олимпу
	if time >= 12.0 and time < 24.0 then
		local timeScene = ease((time-12.0)/12.0, 0.3, 0.0)

		Greece.Nebo.layer.isVisible = true
		Greece.Ground.layer.isVisible = true
		Greece.Artefact.Artefact.isVisible = false

		if scene2 then
			scene2 = false
			currentScene = 1
			Greece.set:setText("Greece2")
			
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Greece2", 0.5, true)
		end

		if time > 23.3 then
			local fadeTime = (time-23.3)/0.7
			Greece.Fade.Fade.isVisible = true
                        Greece.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                else
	                Greece.Fade.Fade.isVisible = false
                end


		Greece.Ground.Olymp.x = 95
		Greece.Ground.Olymp.y = 96+lerp(0, 3, timeScene)
		Greece.Ground.Olymp.scale = lerp(1.0, 1.1, timeScene)

		Greece.Ground.Valley.x = 145-lerp(0, 20, timeScene)
		Greece.Ground.Valley.y = 45-lerp(0, 5, timeScene)
		Greece.Ground.Valley.scale = lerp(1.0, 1.2, timeScene)

		Greece.Ground.Ground.x = 300+lerp(0, 90, timeScene)
		Greece.Ground.Ground.y = 89-lerp(0, 100, timeScene)
		Greece.Ground.Kolonna.x = 110+lerp(0, 190, timeScene)
		Greece.Ground.Kolonna.y = 64-lerp(0, 220, timeScene)
		
                Greece.Ground.Vino.x = lerp(80, -80, timeScene)
		Greece.Ground.Vino.y = 185
		Greece.Ground.Vino.scale = lerp(1.0, 2.0, timeScene)

		Greece.Ground.Ground.scale = lerp(1, 1.4, timeScene)
		Greece.Ground.Kolonna.scale = lerp(1, 1.9, timeScene)
	end
	
	if time >= 24.0 and time < 36.0 then
		
		local timeScene = (time-24.0)/12.0
		
		if scene3 then
			scene3 = false
			currentScene = 2
			Greece.set:setText("Greece3")
			
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Greece3", 0.5, true)
		end

		
		if time < 24.7 then
			local fadeTime = (time-24.0)/0.7
			Greece.Fade.Fade.isVisible = true
                        Greece.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Greece.Fade.Fade.isVisible = false
                end

		if time > 35.3 then
			local fadeTime = (time-35.3)/0.7
			Greece.Fade.Fade.isVisible = true
                        Greece.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

		Greece.Nebo.layer.isVisible = true
		Greece.Ground.layer.isVisible = true
		Greece.Artefact.Artefact.isVisible = true
		
		Greece.Artefact.Artefact.x = timeScene

	end

	if time >= 36.0 then
		EndAnimation()
	end



end

-- *************************
-- Troy animation
-- *************************
function TroyAnimationReset()

	time = 0.0

	Troy.Ground.Ground.x = 435
	Troy.Ground.Door.y = 56
	Troy.Ground.Door.x = 120
	
	Troy.Ground.layer.x = -496
	
	Troy.Ground.Horse.x = 200
	Troy.Ground.Horse.y = 50
	Troy.Ground.Rock.x = 690
	Troy.Artefact.Artefact.isVisible = false
	
	Troy.Fade.Fade.x = 150
	Troy.Fade.Fade.y = 125

	Troy.Fade.Fade.isVisible = false
	
	scene1 = true
	scene2 = true
	scene3 = true
	scene4 = true
	
	currentScene = 0
	
	Troy.Nebo.Sun.x = 80
	Troy.Nebo.Sun.y = 200
	
	Troy.Nebo.Road.x = 80
	Troy.Nebo.Road.y = 60

	Troy.Glow.Glow.isVisible = true
	Troy.Glow.Glow.x = 80
	Troy.Glow.Glow.y = 200
	
	Troy.Ground.Kust.x = 20
	Troy.Ground.Kust.y = -20
	Troy.Ground.Kust.scale = 0.75
	Troy.Ground.Kust.angle = -15
	
	Troy.Ground.Kust2.x = 320
	Troy.Ground.Kust2.y = -30
	Troy.Ground.Kust2.scale = 0.55
	Troy.Ground.Kust2.angle = 0

	Troy.Ground.Kust3.x = 160
	Troy.Ground.Kust3.y = -30
	Troy.Ground.Kust3.scale = 0.65
	Troy.Ground.Kust3.angle = 5


	Troy.City.Kust1.x = 20
	Troy.City.Kust1.y = -20
	Troy.City.Kust1.scale = 0.75
	Troy.City.Kust1.angle = -15
	
	Troy.City.Kust2.x = 350
	Troy.City.Kust2.y = -20
	Troy.City.Kust2.scale = 0.8
	Troy.City.Kust2.angle = 25

	Troy.Nebo.Road:Do("Additive")
	
	Sound:FadeOutTagTracks("Animation", 0.5)

	TroyAnimationDo(0.0)
end

function TroyAnimationDo(dt)
	time = time+animationSpeed*dt
	
	--time = 9.0

	-- Сцена с движением коня
	
	if time < 8.0 then

		local timeScene = time/8.0

		if scene1 then
			scene1 = false
			Troy.set:setText("Troy1")

			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Troy1", 0.5, true)
		end

		Troy.Ground.layer.isVisible = true
		Troy.Nebo.layer.isVisible = true
		Troy.City.layer.isVisible = false
		Troy.Artefact.Artefact.isVisible = false
		Troy.Glow.Glow.isVisible = true

		Troy.Ground.layer.x = lerp(-496, 0, ease(timeScene, 0.2, 0.6))
		Troy.Ground.Horse.x = lerp(750.0, 200.0, ease(timeScene, 0.0, 0.3))
		Troy.Ground.Rock.x = lerp(690.0, 900.0, ease(timeScene, 0.2, 0.6))
		
		Troy.Ground.Kust.x = lerp(-160, 20, ease(timeScene, 0.2, 0.6))
		Troy.Ground.Kust2.x = lerp(-160, 20, ease(timeScene, 0.2, 0.6))+360
		Troy.Ground.Kust3.x = lerp(-160, 20, ease(timeScene, 0.2, 0.6))+650

		if time < 0.7 then
			local fadeTime = time/0.7
			Troy.Fade.Fade.isVisible = true
                        Troy.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Troy.Fade.Fade.isVisible = false
                end

		if timeScene < 0.4 then
			local downTime = timeScene/0.4
			--Troy.Ground.Horse.x = lerp(750.0, 450.0, downTime)
			Troy.Ground.Horse.y = lerp(114.0, 50.0, downTime)
			Troy.Ground.Horse.angle = 10
			if downTime < 0.2 then
				local angleTime = downTime/0.2
				Troy.Ground.Horse.angle = lerp(0, 12, angleTime)
			end
			if downTime > 0.8 then
				local angleTime = (downTime-0.8)/0.2
				Troy.Ground.Horse.angle = lerp(12, 0, angleTime)
			end
		else
			local moveTime = (timeScene-0.4)/0.6
			--Troy.Ground.Horse.x = lerp(450.0, 200.0, ease(moveTime, 0.0, 0.8) )
			Troy.Ground.Horse.y = 50.0
		end

	end
	-- Продолжение сцены с конем (открывание ворот и въезд в город)
	if time >= 8.0 and time < 12.0 then

		local timeScene = (time-8.0)/4.0

		Troy.Ground.layer.x = 0.0
		Troy.Ground.Horse.x = 200.0
		Troy.Ground.Horse.y = 50.0
		Troy.Ground.Horse.angle = 0
		Troy.Ground.Kust.x = 20

		Troy.Ground.layer.isVisible = true
		Troy.Nebo.layer.isVisible = true
		Troy.City.layer.isVisible = false
		Troy.Artefact.Artefact.isVisible = false
		Troy.Glow.Glow.isVisible = true
		
		if time > 11.3 then
			local fadeTime = (time-11.3)/0.7
			Troy.Fade.Fade.isVisible = true
                        Troy.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                else
	                Troy.Fade.Fade.isVisible = false
                end
		if timeScene < 0.2 then
			local upTime = timeScene/0.2
			Troy.Ground.Door.x = lerp(120.0, 90.0, upTime)
		end

		if timeScene >= 0.2 then
			Troy.Ground.Horse.x = lerp(200.0, -100, ease(timeScene-0.2, 0.3, 0.3))
        	end

		if timeScene >= 0.8 then
			local upTime = (timeScene-0.8)/0.2
			Troy.Ground.Door.x = lerp(90.0, 120.0, upTime)
		end
	end

	-- Сцена в городе
	if time >= 12.0 and time < 24.0 then

		local timeScene = (time-12.0)/12.0
		
		if scene2 then
			scene2 = false
			currentScene = 1
			Troy.set:setText("Troy2")
			
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Troy2", 0.5, true)
		end

		if time < 12.7 then
			local fadeTime = (time-12.0)/0.7
			Troy.Fade.Fade.isVisible = true
                        Troy.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Troy.Fade.Fade.isVisible = false
                end

		if time > 24.3 then
			local fadeTime = (time-24.3)/0.7
			Troy.Fade.Fade.isVisible = true
                        Troy.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

		Troy.Ground.layer.isVisible = false
		Troy.Nebo.layer.isVisible = true
		Troy.Artefact.Artefact.isVisible = false
		Troy.City.layer.isVisible = true
		Troy.Glow.Glow.isVisible = true

		Troy.City.layer.scale = lerp(0.85, 1.1, timeScene)
		Troy.City.layer.x = -lerp(0, 50.0, timeScene)
		Troy.City.layer.y = -lerp(0, 35.0, timeScene)
		
		Troy.City.Kust1.x = lerp(20, -80, timeScene)
		Troy.City.Kust2.x = lerp(350, 450, timeScene)

		Troy.City.Horse.x = 190
		Troy.City.Horse.y = 110+lerp(0, 10, timeScene)
		Troy.City.Horse.scale = lerp(0.7, 0.85, timeScene)

		Troy.City.BuildLeft.x = 50-lerp(0, 20, timeScene)
		Troy.City.BuildLeft.y = 120

		Troy.City.BuildRight.x = 310+lerp(0, 20, timeScene)
		Troy.City.BuildRight.y = 120

	end

	if time >= 24.0 and time < 36.0 then

		Troy.Ground.layer.isVisible = false
		Troy.Nebo.layer.isVisible = false
		Troy.City.layer.isVisible = false
		Troy.Artefact.Artefact.isVisible = true
		Troy.Glow.Glow.isVisible = false
		
		local timeScene = (time-24.0)/12.0
		
		if scene3 then
			scene3 = false
			currentScene = 2
			Troy.set:setText("Troy3")
			
			Sound:FadeOutTagTracks("Animation", 0.5)
			Sound:FadeInTrack("Troy3", 0.5, true)
		end


		if time < 24.7 then
			local fadeTime = (time-24.0)/0.7
			Troy.Fade.Fade.isVisible = true
                        Troy.Fade.Fade.color = Color(0, 0, 0, lerp(255, 0, fadeTime))
                else
	                Troy.Fade.Fade.isVisible = false
                end

		if time > 35.3 then
			local fadeTime = (time-35.3)/0.7
			Troy.Fade.Fade.isVisible = true
                        Troy.Fade.Fade.color = Color(0, 0, 0, lerp(0, 255, fadeTime))
                end

                Troy.Artefact.Artefact.x = timeScene

	end

	if time >= 36.0 then
		EndAnimation()
	end

end
