function OnSceneLoad(screen)
    game_state = {}    
    LoadData(screen)
    local pf = play_field
    local level = pf:GetLevelScreen()
    game_state.custom_cursors = {}
    game_state.locked_objects = {}
    --level:AddTaskSafe(CreateTask('', '', ''))
    --zone = CreateZoomZone('')
    game_state.locker = ReferenceCounter()
    game_state.active_zone = nil
    game_state.inventory_zones = {}
	game_state.active_objects = {}
	
	local object = pf:GetObject('coinslot');
	
	inventory_coinslot = CreateInventory(object:GetX(),
                                        object:GetY() + 50,
                                        object:GetZ() + 500,
                                        "coinslot",
                                        CreateItem('coin1_tool', 'coin1_scaledcoin3_scaledcoin4_scaled'),
                                        CreateItem('coin4_tool', 'coin1_scaledcoin3_scaledcoin4_scaled'),
                                        CreateItem('coin3_tool', 'coin1_scaledcoin3_scaledcoin4_scaled'),
                                        play_field:GetTimer(),
										"INVENTORY_TASK_11_2");
										
	inventory_coinslot.state_changer = "OnCoinslotFilled"
	
	local t = CreateTool('coin1', 'coin1_scaled')
	CreateTool('coin4', 'coin4_scaled')
--[[	t.OnSuccess = function()
	    play_field:GetObject('coin1'):SetOpacity(0)
		zoom_callbox.RemoveObject('coin1')		
	end]]
	--CreateTool('coin2', 'coin2')
	local t = CreateTool('coin3', 'coin3_scaled')
--[[	t.OnSuccess = function()
	    play_field:GetObject('coin3'):SetOpacity(0)
		zoom_callbox.RemoveObject('coin3')		
	end]]
	
	--[[inventory_coinslot.OnCompleteImmediate = function()
		zoom_callbox.close_button:SetEnabled(false)
	end]]
	
	inventory_coinslot.OnCompleteImmediate = function()
	    GetProfileManager():GetCurrentProfile():AddStateChanger('OnMinigameConditionsComplete')
	end
	
	inventory_coinslot.OnComplete = function()
		TimerDo(play_field:GetTimer(), 0.01, load_screen, 'data/Scenes/Minigames/11_chain.lua')
        --load_screen('data/Scenes/Minigames/11_chain.lua');    
	end
	
	local object = pf:GetObject('phone_over');
	
	inventory_phone_over = CreateInventory(object:GetX(),
                                        object:GetY() + 50,
                                        object:GetZ() + 301,
                                        "phone_over",
                                        nil,
                                        CreateItem('bat1_tool', 'bat1_scaled'),
                                        nil,
                                        play_field:GetTimer(),
										"INVENTORY_TASK_11_3");
									
	inventory_phone_over.state_changer = 'OnPhoneOverSmashed'
    
    inventory_phone_over.OnComplete = function()
        play_field:GetObject('coin3'):SetVisible(true)
        play_field:GetObject('coin3'):ChangeOpacity(0, 1, 0.3)
        inventory_coinslot:Unlock();
		local s = CreateSoundEntity("11_BatApplied")
		s:AttachTo(play_field)
		s:Play(false)
    end
    
    object:GetAnimation():SetColor('0x01FFFFFF')
	
	local t = CreateTool('bat1', 'bat1_scaled')	
	--[[t.OnSuccess = function()
		zoom_callbox.RemoveObject('bat1')	
	end]]
	
	play_field:GetObject('coin3'):SetVisible(false)
	
	play_field:IgnoreOnTestPoint('sprait_knigi')
	game_state.locked_objects['radio'] = true
	
	level:AddTaskSafe(CreateTask('WALKIE_TALKIE', '', 'radio'));
	
	
	InitChain3(screen)
	InitChain4(screen)
	game_state.chain4.final = true
	AddSheriffEyeLogic()
	
	local af = CreateAnimationEffector()
	af:AttachTo(play_field:GetObject('lamp01_light'))
	af:SetMode(_ANIM_PINGPONG);
	af:SetKey(_TRACK_O, 0, 0)
	af:SetKey(_TRACK_O, 1, 1)
	af:Play()
	
	game_state.OnPhoneOverSmashed = function()
	    if play_field:HasObject('coin3') then
            play_field:GetObject('coin3'):SetVisible(true)
            play_field:GetObject('coin3'):ChangeOpacity(0, 1, 0.3)
        end
        inventory_coinslot:Unlock();
	end
	
	game_state.OnCoinslotFilled = function()
		local o = {}	    
		table.insert(o, 'bat1')
		table.insert(o, 'coinslot')
		table.insert(o, 'phone_over')
		table.insert(o, 'phone_closed')
		table.insert(o, 'coin1')    
		table.insert(o, 'coin3')
		table.insert(o, 'sprait_knigi')        
		
		for i,v in ipairs(o) do
		    if play_field:HasObject(v) then
			    play_field:GetObject(v):SetVisible(false)        
			end
		end
		
		game_state.locked_objects['radio'] = false
	end
	
	game_state.OnMinigameConditionsComplete = function()
	    if game_state.do_not_load_mini_game then
	        return
	    end
	    
	    load_screen('data/Scenes/Minigames/11_chain.lua');
	end	
	game_state.CheckWinConditions = function()
		if IsNotebookClosed() and ArePanelTasksComplete() then
			game_state.chain4.Start()
			play_field:GetObject('lamp01_light'):SetVisible(false)
		end
	end
end

function InitChain3(screen)
    local comics1 = CreateComics(screen,                                 
                                 'Sheriff',
								 'eyes')
    
    game_state.chain3 = CreateChain('pixel3',
                                    screen,
                                    comics1, GetString("COMICS_11_3"))
end

function InitChain4(screen)
    local comics1 = CreateComics(screen,                                 
                                 'Sheriff',
								 'eyes')

    comics1.OnHidden = function()
        OnWin()
    end
    
    game_state.chain4 = CreateChain('pixel4',
                                    screen,
                                    comics1, GetString("COMICS_11_4"))
end

function OnMinigameCompleted()
	local s = CreateSoundEntity("11_OpenPhone")
	s:AttachTo(play_field)
	s:Play(false)
    local o = {}	    
    table.insert(o, 'bat1')
    table.insert(o, 'coinslot')
    table.insert(o, 'phone_over')
    table.insert(o, 'phone_closed')
    table.insert(o, 'coin1')    
    table.insert(o, 'coin3')
    table.insert(o, 'sprait_knigi')        
    
    for i,v in ipairs(o) do
        if play_field:HasObject(v) then
            play_field:GetObject(v):SetVisible(false)
        end
    end
	
	game_state.locked_objects['radio'] = false
end


function OnSceneFree(screen)
    FreeData(screen)
end

function OnNotebookClosed()
	game_state.chain4.Start()
end

function OnUpdate(dt)
end

function OnScreenShown()
	OnSceneStateChanged(play_field)    
	inventory_phone_over.Unlock()
end

function OnExit()
end

function OnObjectMouseEnter(object)
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    DefaultOnObjectMouseLeave(object)
end

function OnObjectMouseDown(object)
    obj_name = object:GetName()
    local pf = play_field
    local is_wrong_click = true

    is_wrong_click = DefaultOnObjectMouseDown(object)

    if is_wrong_click then
        --pf:ShowWrongObjectEffect()
    end

    return is_wrong_click;    
end

function OnObjectMouseUp(object)
end

function OnObjectWillBeFound(object)
    if object:GetName() == 'radio' then
        play_field:GetObject('lamp01_light'):SetVisible(false)
    end
    if not play_field:GetLevelScreen():HasTaskObjects() then
		GetProfileManager():GetCurrentProfile():AddStateChanger('CheckWinConditions')
	end
end

function OnObjectWasFound(object)
    if object:GetName() == 'radio' then
        game_state.chain3.Start()
    end
end

function OnToolFound(tool)
end

function OnToolApply(tool, object)
    DefaultOnToolApply(tool, object)
end

function OnObjectReachPanel(object)
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
end

function CanBeHinted(obj)
    if locked_object[obj] ~= true then
        return true
    else
        return false
    end
end

-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/phone_opened_1.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('phone_opened_1',anim,512,384,115,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/radio.png',0,0,154,49,1,0)
	anim:SetHotSpot(77,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('radio',anim,483,528,116,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/phone_closed.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('phone_closed',anim,512,384,120,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin1.png',0,0,48,29,1,0)
	anim:SetHotSpot(24,14)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin1',anim,784,421,121,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin2.png',0,0,44,45,1,0)
	anim:SetHotSpot(22,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin1_tool',anim,512,384,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin2.png',0,0,44,45,1,0)
	anim:SetHotSpot(22,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin3_tool',anim,512,384,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin2.png',0,0,44,45,1,0)
	anim:SetHotSpot(22,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin3_scaled',anim,529,453,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/sprait_knigi.png',0,0,228,145,1,0)
	anim:SetHotSpot(114,72)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sprait_knigi',anim,845,409,123,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/bat.png',0,0,77,314,1,0)
	anim:SetHotSpot(38,157)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bat1',anim,301,751,122,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/bat.png',0,0,77,314,1,0)
	anim:SetHotSpot(38,157)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bat1_scaled',anim,317,734,122,-135,0.25,0.25)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/bat.png',0,0,77,314,1,0)
	anim:SetHotSpot(38,157)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bat1_tool',anim,168,123,100,-135,0.25,0.25)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin2.png',0,0,44,45,1,0)
	anim:SetHotSpot(22,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin1_scaled',anim,784,421,122,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin3.png',0,0,35,33,1,0)
	anim:SetHotSpot(17,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin3',anim,528,453,124,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('phone_over',anim,532,376,121,0,40,30)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('pixel3',anim,512,384,401,0,128,96)
	local anim = CreateAnimation('data/Texture/Comics/Sheriff.dds',0,0,530,636,1,0)
	anim:SetHotSpot(266,256)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Sheriff',anim,505,390,400,0,1,1)
	local anim = CreateAnimation('data/Texture/Comics/eyes.png',0,0,79,33,1,0)
	anim:SetHotSpot(39,16)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('eyes',anim,499,212,500,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('pixel4',anim,512,384,401,0,128,96)
	local anim = CreateAnimation('data/Texture/Scenes/9_ room_telephone_operator_4/Layers/lamp01_light.png',0,0,81,75,1,0)
	anim:SetHotSpot(40,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('lamp01_light',anim,531,522,117,0,0.2,0.2)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coinslot.png',0,0,90,131,1,0)
	anim:SetHotSpot(45,65)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coinslot',anim,614,139,140,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin4.png',0,0,59,61,1,0)
	anim:SetHotSpot(29,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin4',anim,361,373,130,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/sprajt_moneta03.png',0,0,47,74,1,0)
	anim:SetHotSpot(23,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sprajt_moneta03',anim,371,371,140,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin4.png',0,0,59,61,1,0)
	anim:SetHotSpot(29,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin4_tool',anim,363,99,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coin4.png',0,0,59,61,1,0)
	anim:SetHotSpot(29,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coin4_scaled',anim,362,374,130,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/11_call_box_5/zoom/coinslot.png',0,0,90,131,1,0)
	anim:SetHotSpot(45,65)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('coinslot2',anim,614,139,120,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
