gameLayer = "StageLayer_1"

CurrentTimeLogWrite("Fonts begin")
LoadResource("fonts.xml")
--LoadResource("Sound.xml")
--LoadResource("SoundBonusEffects.xml")
--LoadResource("Music.xml")
CurrentTimeLogWrite("Sounds begin")
Sound:Reload()

CurrentTimeLogWrite("All resources begin")
LoadResource("GUI_Resource.xml")
LoadResource("ISpyResources.xml")
LoadResource("GameResource.xml")
LoadResource("CountryResTrial.xml")
--LoadResource("MainMenuResource.xml")
--LoadResource("ChipsAnim.xml")
LoadResource("ChipsAnimNew.xml")
LoadResource("MainMenuRes.xml")
LoadResource("MapResource.xml")
CurrentTimeLogWrite("All resources end")

CurrentTimeLogWrite("All texts begin")
GUI:LoadText("NewText.xml")
GUI:LoadText("text.xml")
GUI:LoadText("text_artefacts.xml")
GUI:LoadText("text_tutorial.xml")
CurrentTimeLogWrite("All texts end")

CurrentTimeLogWrite("All effects begin")
LoadEffects("ChipInSun.xml")
LoadEffects("StatEffects.xml")
LoadEffects("Flames.xml")
LoadEffects("IspyEffects.xml")
LoadEffects("CarfagenFlame.xml")
LoadEffects("GreeceFlame.xml")
LoadEffects("BabylonFlame.xml")
LoadEffects("RomeFlame.xml")
LoadEffects("TroyFlame.xml")
LoadEffects("RomeWaterFall.xml")
LoadEffects("EgyptStorm.xml")
LoadEffects("Egypt2Flame.xml")
--LoadEffects("Lamp.xml")
LoadEffects("TimeSplash.xml")
LoadEffects("ChipDestroy.xml")
LoadEffects("ArtefactCollected.xml")
LoadEffects("ArtDustMy.xml")
--LoadEffects("Bubble.xml")
LoadEffects("StoneEffects.xml")
LoadEffects("MapEffects.xml")
LoadEffects("AQ3ISpyEffects.xml")
LoadEffects("LoadScreenEffect.xml")
LoadEffects("PressEffect.xml")
LoadEffects("HiScores.xml")
--LoadEffects("ISpyBonusEffects.xml")
--LoadEffects("LightLampOnField.xml")
LoadEffects("CrystalLightEffect.xml")
LoadEffects("MultFlame.xml")
LoadEffects("SunActive.xml")
LoadEffects("bonus-ispy-effects.xml")
LoadEffects("AltarStoneStar.xml")
LoadEffects("OneWildDot.xml")
LoadEffects("MenuEffects.xml")
LoadEffects("AmuletAppear.xml")


LoadParticles("RainParticleEffect.xml")
LoadEffects("RainParticleEffect.xml")

LoadParticles("country_effects.xml")
LoadEffects("country_effects.xml")

--LoadParticles("Sunset.xml")
--LoadEffects("Sunset.xml")

LoadParticles("effects.xml")
LoadEffects("effects.xml")

LoadParticles("StringEffects.xml")
LoadEffects("StringEffects.xml")
CurrentTimeLogWrite("All effects end")
CurrentTimeLogWrite("All Artefact begin")
LoadArtefacts()
CurrentTimeLogWrite("All Artefact end")

CurrentTimeLogWrite("Load Layers begin")
GUI:LoadLayers("Cross_GUI.xml")
GUI:LoadLayers("Stat_GUI.xml")
GUI:LoadLayers("LoadScreen_GUI.xml")
GUI:LoadLayers("MyMainMenuGUI.xml")
GUI:LoadLayers("GameField_GUITrial.xml")
--GUI:LoadLayers("Hint_GUI.xml")
--GUI:LoadLayers("Countries_GUI.xml")

GUI:LoadLayers("ISpyFieldControl_GUI.xml")
GUI:LoadLayers("MenuInGameAQ3_GUI.xml")
GUI:LoadLayers("Tutorial_GUI.xml")

CurrentTimeLogWrite("Load Layers end")

local sndVolume = gameInfo:getSoundVolume()
local musVolume = gameInfo:getMusicVolume()
local envVolume = gameInfo:getEnvironmentVolume()

Sound:SetSoundVolume(sndVolume)
Sound:SetMusicVolume(musVolume)
Sound:SetEnvironmentVolume(envVolume)

--Sound:SetSoundVolume(0)
--Sound:SetMusicVolume(0)
--Sound:SetEnvironmentVolume(0)

local iFullscreen = "0"
if gameInfo:getFullscreen() then
	iFullscreen = "1"
end

local iCCursor = "0"
if gameInfo:getCustomCursor() then
	iCCursor = "1"
end

function UploadGameIntro()
	UploadResourceGroup("Intro");
	UploadResourceGroup("IntroMenu");
	GUI:getLayer("JuleBook"):getWidget("JuleBook"):AcceptMessage( Message("StartIntro") )
end

function UploadGameIntroNewPlayer()
	UploadResourceGroup("Intro");
	UploadResourceGroup("IntroMenu");
	GUI:getLayer("JuleBook"):getWidget("JuleBook"):AcceptMessage( Message("StartIntroForNewPlayer") )
end

function SetShowHints()
	if gameInfo:getHintsEnabled() then
		GUI:getLayer("Options"):getWidget("ATips"):AcceptMessage(Message("SetState", "1"))
	else
		GUI:getLayer("Options"):getWidget("ATips"):AcceptMessage(Message("SetState", "0"))
	end
end

if not gameInfo:NoPlayers() then

	local namesWidget = GUI:getLayer("Profiles"):getWidget("Names")
	local numOfPlayers = gameInfo:getNumberOfPlayers()-1
	for i = 0, numOfPlayers do
		local playerName = gameInfo:getPlayerName(i)
		namesWidget:AcceptMessage(Message("Add", playerName))
	end

	namesWidget:AcceptMessage(Message("Select", gameInfo:getName()))
	--GUI:getLayer("MyMainMenu"):getWidget("profileButton"):AcceptMessage(Message("SetProfile", gameInfo:getName()))
	--SetShowHints()
end

if (false) then
	Screen:pushLayer( GUI:getLayer("ArtCutter"))
else
	CurrentTimeLogWrite("Init rain begin")
	InitPlaneRain()
	
	if (false) then
		UploadResourceGroup("Fon")
		GUI:getLayer("StageLayer_1"):getWidget("GameField"):AcceptMessage(Message("SetPreviewSSMode", 1))
		gameInfo:setScreensaver();
		gameInfo:setPreviewSSMode(true)

		local message = gameInfo:RunFirstScreensaverBG()

		param = VariableSet()
		param:setString("Layer1", message:getData())
		param:setString("CrossHandler", "UploadScreensaverBG")
		kernel:addController(controlFactory:Create("CrossFade", param))	
		Sound:FadeOutAllTracks(1.0)
	
	elseif (true) then
		CurrentTimeLogWrite("Upload begin")
		UploadResourceGroup("MainMenu")
		UploadResourceGroup("Altar")
		UploadResourceGroup("Fon")
		GUI:getLayer("LoadScreen"):getWidget("LoadScreen"):AcceptMessage(Message("SetMode"))	
		Screen:pushLayer( GUI:getLayer("LoadScreen"))		
	
		Sound:FadeInTrack("MainMenu", 2.0, true)
	elseif (true) then
		UploadResourceGroup("Altar")
		UploadResourceGroup("ISpy")
		UploadResourceGroup("Game")
		gameLayer = "PrepareAltarLevel"
		GUI:getLayer(gameLayer):getWidget("GameField"):AcceptMessage(Message("ReleaseResources"))
		gameInfo:setLevel(1)
		gameInfo:setNumber(1)
		gameInfo:setStage(0)
		GUI:getLayer(gameLayer):getWidget("GameField"):AcceptMessage(Message("InitLevel"))
		Screen:pushLayer( GUI:getLayer(gameLayer) )
	      
		Sound:FadeInTrack("Altar", 2.0, true)
      
	elseif (true) then
		UploadResourceGroup("Map")
		UploadResourceGroup("Fon")
		gameInfo:setStage(7)
		gameInfo:setLevel(4)
		gameInfo:setNumber(1)
		GUI:getLayer("Map"):getWidget("Map"):AcceptMessage( Message("SetFlag") )	
		GUI:getLayer("Map"):getWidget("Map"):AcceptMessage(Message("InitLevel"))
		Screen:pushLayer( GUI:getLayer("Map"))		
		Sound:FadeInTrack("Map", 2.0, true)		
		gameLayer = "Map"
	elseif (false) then
		gameInfo:setStage(1)
		gameInfo:setLevel(1)
		gameInfo:setNumber(1)
		UpdateGameLayerName()
		GUI:getLayer(gameLayer):getWidget("GameField"):AcceptMessage(Message("Editor"))
		UploadResourceGroup(gameLayer)
		UploadResourceGroup("Fon")
		UploadResourceGroup("Game")
		UploadResourceGroup("Match3")
		StartGame()
	--	local param = VariableSet()
	--	param:setString("Layer1", gameLayer)
	--	kernel:addController(controlFactory:Create("CrossFade", param))
	elseif (true) then
		UploadResourceGroup("MainMenu")
		UploadResourceGroup("Altar")
		UploadResourceGroup("Fon")		
		local param = VariableSet()	
		param:setString("Layer1", "MainMenuFon")
		--param:setString("Layer2", "MyMainMenu")
		kernel:addController(controlFactory:Create("CrossFade", param))	
	end
end

