local tool_to_set_on_next_update = nil

if not game_state then  
    game_state = {}
end
game_state.is_inventory_opened = false

local inventory_info
if not inventory_info then
    inventory_info = {}
end
inventory_info.nrotates = 0
inventory_info.angle_to_rotate = 0

inventory_info.hint_text = CreateTextEntity("data/Font/comics.fnt", 'EMPTY')
inventory_info.hint_text:SetTextAlignment(0)
inventory_info.hint_text:Hide()
--inventory_info.hint_text:SetScale(0.8)
--inventory_info.hint_text:SetTracking(-4.)

function InventoryOnSceneLoad(screen)

    screen:SetLayer(2);

end

function InventoryOnUpdate(dt)
    local inv = play_field:GetLevelScreen():GetInventory()
    if tool_to_set_on_next_update then
        --Log("if tool_to_set_on_next_update then")
        local info = inv:GetToolInfo(tool_to_set_on_next_update)
        info.m_tool:SetVisible(true)
        if info.m_icon then
            info.m_icon:SetVisible(false)
        end
        game_state.tool = info.m_tool
        play_field:SetTool(tool_to_set_on_next_update)

        if game_state.tools[tool_to_set_on_next_update].on_get then
            game_state.tools[tool_to_set_on_next_update].on_get(tool_to_set_on_next_update)
        end

        inventory_info.bleft:Stop()
        inventory_info.bright:Stop()

        local eff = CreateAnimationEffector()
        eff:AttachTo(game_state.tool)
        eff:SetMode(_ANIM_LOOP)
        eff:SetKey(_TRACK_S, 0, 1.)
        eff:SetKey(_TRACK_S, 0.65, 1.1)
        eff:SetKey(_TRACK_S, 1., 1.)
        eff:Play()

        if InteractiveHelpBeingShown()
        then
            TutorialToolTaken(tool_to_set_on_next_update)
        end
        
        tool_to_set_on_next_update = nil
        --[[
        while math.abs(inventory_info.nrotates) > 0 do
            RotateInventory(inventory_info.nrotates > 0, false)
        end
        ]]
    end
    if game_state.tool then
        local mouse_pos = GetMousePos()
        game_state.tool:SetScrXY(mouse_pos.x, mouse_pos.y)
        --Log('game_state.tool:SetScrXY(mouse_pos.x, mouse_pos.y)') -----
    end

    if math.abs(inventory_info.angle_to_rotate) > 0. then
        local rotate_speed = 2.
        local dangle = rotate_speed * dt

        if math.abs(inventory_info.angle_to_rotate) > dangle then
            if inventory_info.angle_to_rotate < 0. then
                dangle = -dangle
            end
            inventory_info.angle_to_rotate = inventory_info.angle_to_rotate - dangle
        else
            dangle = inventory_info.angle_to_rotate
            inventory_info.angle_to_rotate = 0
        end

        for i, v in ipairs(inventory_info.objects_to_rotate) do
            v:SetAngle(v:GetAngle() + dangle)
        end
    end

    if game_state.level_mode == 'quest' then
        if CanRotateRight() then
            inventory_info.bleft:SetEnabled(true)
        else
            inventory_info.bleft:SetEnabled(false)
        end
        if CanRotateLeft() then
            inventory_info.bright:SetEnabled(true)
        else
            inventory_info.bright:SetEnabled(false)
        end
    end

    local obj_under_mouse = inv:GetObjectUnderMouse()
    if obj_under_mouse and
       inv:IsTool(obj_under_mouse) and
       not inv:IsToolMoving(inv:GetToolName(obj_under_mouse)) and
       play_field:GetTool() == ''
    then
        inventory_info.hint_text:SetXY(GetMousePos().x + 28., GetMousePos().y + 0.)
        inventory_info.hint_text:Show()
        inventory_info.hint_text:SetLayer(obj_under_mouse:GetLayer() + 1)
        if game_state.created_tools then
            local info = game_state.created_tools[obj_under_mouse:GetName()]
            if info then
                inventory_info.hint_text:SetText(GetString(info.hint_text))
            end
        end
    else
        inventory_info.hint_text:Hide()
    end
end

function InventorySetButtonsEnabled()
    inventory_info.bleft:Go()
    inventory_info.bright:Go()
end

function DropTool(custom_move_time)
    game_state.tool:DestroyChildren()
    game_state.tool:SetScale(1.)
    local tool_name = play_field:GetLevelScreen():GetInventory():GetToolName(game_state.tool)
    local move_time = 0.3
    if custom_move_time then
        move_time = custom_move_time
    end
    play_field:GetLevelScreen():GetInventory():MoveToolToFreeSlot(tool_name, move_time)
    play_field:SetTool('')
    game_state.tool = nil
    if game_state.tools[tool_name].on_drop then
        game_state.tools[tool_name].on_drop(tool_name)
    end

    local inv = play_field:GetLevelScreen():GetInventory()
    TimerDoString('InventorySetButtonsEnabled()', 0.3, inv:GetTimer())
end

function InventoryOnObjectMouseDown(object)
    if game_state.tool then
        --game_state.tool = nil
        --Log("game_state.tool = nil")
    else
        local inv = play_field:GetLevelScreen():GetInventory()
        if inv:IsTool(object) and
           play_field:GetTool() == '' and
           not inv:IsToolLocked(object)
        then
            tool_to_set_on_next_update = play_field:GetLevelScreen():GetInventory():GetToolName(object)
            --Log("tool_to_set_on_next_update = object")
        else
            --Log("already has tool")
        end
    end

    UpdateComicsRequest()
end

function LoadInventoryData(screen)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel01.png',0,0,299,299,1,0)
	anim:SetHotSpot(149,149)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel01',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel02.png',0,0,133,133,1,0)
	anim:SetHotSpot(66,66)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel02_1',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel02.png',0,0,133,133,1,0)
	anim:SetHotSpot(66,66)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel02_2',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel02.png',0,0,133,133,1,0)
	anim:SetHotSpot(66,66)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel02_3',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel03.png',0,0,184,185,1,0)
	anim:SetHotSpot(92,92)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel03',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel04.png',0,0,57,57,1,0)
	anim:SetHotSpot(28,28)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel04',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel05.png',0,0,184,184,1,0)
	anim:SetHotSpot(92,92)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel05',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel06.png',0,0,32,33,1,0)
	anim:SetHotSpot(16,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel06_1',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel06.png',0,0,32,33,1,0)
	anim:SetHotSpot(16,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel06_2',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel07.png',0,0,53,54,1,0)
	anim:SetHotSpot(26,27)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel07_1',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel07.png',0,0,53,54,1,0)
	anim:SetHotSpot(26,27)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel07_2',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel08.png',0,0,57,57,1,0)
	anim:SetHotSpot(28,28)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel08_1',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel08.png',0,0,57,57,1,0)
	anim:SetHotSpot(28,28)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel08_2',anim,1512,384,251,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryWheel08.png',0,0,57,57,1,0)
	anim:SetHotSpot(28,28)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryWheel08_3',anim,1512,384,251,0,1,1)
	----[[
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan0',anim,1512,384,260,0,1,1)
	--]]
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan1',anim,1512,384,261,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan2',anim,1512,384,262,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan3',anim,1512,384,263,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan4',anim,1512,384,264,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan5',anim,1512,384,265,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan6',anim,1512,384,266,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan7',anim,1512,384,267,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan8',anim,1512,384,268,0,1,1)
	local anim = CreateAnimation('data/Texture/GUI/Inventory/InventoryFan.png',0,0,121,404,1,0)
	anim:SetHotSpot(60,202)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('InventoryFan9',anim,1512,384,269,0,1,1)

	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(0)
	anim:SetColor('0xFF000000')
	screen:CreateObject('tools_anchor',anim,15,745,270,0,1,1)
	screen:GetObject('tools_anchor'):SetLayer(3);
	screen:SetToolsAnchor(screen:GetObject('tools_anchor'))

	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_bleft',anim,20,418,100,0,6,6)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_bright',anim,350,745,100,0,5,5)
	screen:GetObject("area_bleft"):SetOpacity(0.)
	screen:GetObject("area_bright"):SetOpacity(0.)

	inventory_info.bleft = CreateButton('ButtonInventoryLeftUp',
                                        'ButtonInventoryLeftOver',
                                        'ButtonInventoryLeftDown',
                                        'InventoryLeft',
                                        play_field:GetLevelScreen():GetInventory())
	inventory_info.bleft:AttachTo(play_field:GetLevelScreen():GetInventory())
	inventory_info.bleft:SetMouseOverScale(1.)
	inventory_info.bleft:SetX(20.)
	inventory_info.bleft:SetY(411.)
	inventory_info.bleft:SetZ(310)
	inventory_info.bleft:SetRect(-25, -25, 50, 50)
	inventory_info.bleft:SetOpacity(0.)

	inventory_info.bright = CreateButton('ButtonInventoryRightUp',
                                         'ButtonInventoryRightOver',
                                         'ButtonInventoryRightDown',
                                         'InventoryRight',
                                         play_field:GetLevelScreen():GetInventory())
	inventory_info.bright:AttachTo(play_field:GetLevelScreen():GetInventory())
	inventory_info.bright:SetMouseOverScale(1.)
	inventory_info.bright:SetX(345.)
	inventory_info.bright:SetY(740.)
	inventory_info.bright:SetZ(310)
	inventory_info.bright:SetRect(-25, -25, 50, 50)
	inventory_info.bright:SetOpacity(0.)

	inventory_info.objects_to_rotate = {}
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan0"))--
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan1"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan2"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan3"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan4"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan5"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan6"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan7"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan8"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("InventoryFan9"))
    table.insert(inventory_info.objects_to_rotate, screen:GetObject("tools_anchor"))
end

function CycleObjectRotation(obj_name, angle_step, time, start_angle)
    local inventory = play_field:GetLevelScreen():GetInventory()
    local eff = CreateAnimationEffector()
    eff:AttachTo(inventory:GetObject(obj_name))
    eff:SetMode(_ANIM_LOOP)
    if not start_angle then
        start_angle = angle_step
    end
    eff:SetKey(_TRACK_A, 0, start_angle)
    eff:SetKey(_TRACK_A, time, start_angle + angle_step)
    eff:Play()
end

function HideInventory()
    local inventory = play_field:GetLevelScreen():GetInventory()

    inventory:GetTimer():Clear()
    inventory:UnlockTools()

    inventory:GetObject("InventoryFan0"):DestroyChildren()--
    inventory:GetObject("InventoryFan1"):DestroyChildren()
    inventory:GetObject("InventoryFan2"):DestroyChildren()
    inventory:GetObject("InventoryFan3"):DestroyChildren()
    inventory:GetObject("InventoryFan4"):DestroyChildren()
    inventory:GetObject("InventoryFan5"):DestroyChildren()
    inventory:GetObject("InventoryFan6"):DestroyChildren()
    inventory:GetObject("InventoryFan7"):DestroyChildren()
    inventory:GetObject("InventoryFan8"):DestroyChildren()
    inventory:GetObject("InventoryFan9"):DestroyChildren()
    inventory:GetObject("InventoryFan9"):DestroyChildren()
    inventory_info.bleft:DestroyChildren()
    inventory_info.bright:DestroyChildren()

    inventory:GetObject("InventoryFan0"):ChangeOpacity(1., 0., 0.2)--
    inventory:GetObject("InventoryFan1"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryFan2"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryFan3"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryFan4"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryFan5"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryFan6"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryFan7"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryFan8"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryFan9"):ChangeOpacity(1., 0., 0.2)

    inventory:GetObject("InventoryWheel01"):DestroyChildren()
    inventory:GetObject("InventoryWheel02_1"):DestroyChildren()
    inventory:GetObject("InventoryWheel02_2"):DestroyChildren()
    inventory:GetObject("InventoryWheel02_3"):DestroyChildren()
    inventory:GetObject("InventoryWheel03"):DestroyChildren()
    inventory:GetObject("InventoryWheel05"):DestroyChildren()
    inventory:GetObject("InventoryWheel06_1"):DestroyChildren()
    inventory:GetObject("InventoryWheel06_2"):DestroyChildren()
    inventory:GetObject("InventoryWheel07_1"):DestroyChildren()
    inventory:GetObject("InventoryWheel07_2"):DestroyChildren()
    inventory:GetObject("InventoryWheel08_1"):DestroyChildren()
    inventory:GetObject("InventoryWheel08_2"):DestroyChildren()
    inventory:GetObject("InventoryWheel08_3"):DestroyChildren()

    inventory:GetObject("InventoryWheel01"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel02_1"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel02_2"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel02_3"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel03"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel05"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel06_1"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel06_2"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel07_1"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel07_2"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel08_1"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel08_2"):ChangeOpacity(1., 0., 0.2)
    inventory:GetObject("InventoryWheel08_3"):ChangeOpacity(1., 0., 0.2)

	inventory:GetObject("area_bleft"):SetOpacity(0.)
	inventory:GetObject("area_bright"):SetOpacity(0.)

    inventory_info.bleft:SetOpacity(0.)
    inventory_info.bright:SetOpacity(0.)

    while math.abs(inventory_info.nrotates) > 0 do
        RotateInventory(inventory_info.nrotates > 0, true)
    end

    if game_state.created_tools then
		for i, v in pairs(game_state.created_tools) do
			if not HasGameState('ToolApplied', v.name) then
				v.tool:DestroyChildren()
				play_field:GetLevelScreen():GetInventory():MoveToolToFreeSlot(v.name, 0.)
			end
        end
    end

    inventory:SetToolsVisible(false, 0.2)
end

--[[
function FixToolsPositions() -- fix mean 'repair' and 'make fixed' (by children destroying)
end
]]

function ShowInventory()
    if not play_field.inventoryOpenSound
    then
        play_field.inventoryOpenSound = MakeSoundEntity('inventory_open');
    end
    
    play_field.inventoryOpenSound:StopSound();
    play_field.inventoryOpenSound:Play(false);
    
    local inventory = play_field:GetLevelScreen():GetInventory()
    local timer = inventory:GetTimer()
    local effectors = {}

    TimerDoString('play_field:GetLevelScreen():GetInventory():SetToolsVisible(true, 0.2)', 1., timer)

    local fans_anchor = CreateAutoRegisterEntity()
    fans_anchor:AttachTo(inventory)
    fans_anchor:SetXY(-320, 300)
    inventory:GetObject("InventoryFan0"):AttachTo(fans_anchor)--
    inventory:GetObject("InventoryFan1"):AttachTo(fans_anchor)
    inventory:GetObject("InventoryFan2"):AttachTo(fans_anchor)
    inventory:GetObject("InventoryFan3"):AttachTo(fans_anchor)
    inventory:GetObject("InventoryFan4"):AttachTo(fans_anchor)
    inventory:GetObject("InventoryFan5"):AttachTo(fans_anchor)
    inventory:GetObject("InventoryFan6"):AttachTo(fans_anchor)
    inventory:GetObject("InventoryFan7"):AttachTo(fans_anchor)
    inventory:GetObject("InventoryFan8"):AttachTo(fans_anchor)
    inventory:GetObject("InventoryFan9"):AttachTo(fans_anchor)

    ----[[
    inventory:GetObject("InventoryFan0"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan0"] = CreateAnimationEffector()
    effectors["InventoryFan0"]:AttachTo(inventory:GetObject("InventoryFan0"))
    effectors["InventoryFan0"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan0"]:SetKey(_TRACK_Y, 0, 447.5);
    effectors["InventoryFan0"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan0"]:SetKey(_TRACK_A, 0, 2.44346);
    --]]

    inventory:GetObject("InventoryFan1"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan1"] = CreateAnimationEffector()
    effectors["InventoryFan1"]:AttachTo(inventory:GetObject("InventoryFan1"))
    effectors["InventoryFan1"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan1"]:SetKey(_TRACK_Y, 0, 447.5);
    effectors["InventoryFan1"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan1"]:SetKey(_TRACK_A, 0, 2.1118483925);

    inventory:GetObject("InventoryFan2"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan2"] = CreateAnimationEffector()
    effectors["InventoryFan2"]:AttachTo(inventory:GetObject("InventoryFan2"))
    effectors["InventoryFan2"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan2"]:SetKey(_TRACK_Y, 0, 446.5);
    effectors["InventoryFan2"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan2"]:SetKey(_TRACK_A, 0, 2.1118483925);
    effectors["InventoryFan2"]:SetKey(_TRACK_A, 0.16666666666667, 1.780235835);

    inventory:GetObject("InventoryFan3"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan3"] = CreateAnimationEffector()
    effectors["InventoryFan3"]:AttachTo(inventory:GetObject("InventoryFan3"))
    effectors["InventoryFan3"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan3"]:SetKey(_TRACK_Y, 0, 446.5);
    effectors["InventoryFan3"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan3"]:SetKey(_TRACK_A, 0, 2.1118483925);
    effectors["InventoryFan3"]:SetKey(_TRACK_A, 0.33333333333333, 1.4486232775);

    inventory:GetObject("InventoryFan4"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan4"] = CreateAnimationEffector()
    effectors["InventoryFan4"]:AttachTo(inventory:GetObject("InventoryFan4"))
    effectors["InventoryFan4"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan4"]:SetKey(_TRACK_Y, 0, 446.5);
    effectors["InventoryFan4"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan4"]:SetKey(_TRACK_A, 0, 2.1118483925);
    effectors["InventoryFan4"]:SetKey(_TRACK_A, 0.5, 1.11701072);

    inventory:GetObject("InventoryFan5"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan5"] = CreateAnimationEffector()
    effectors["InventoryFan5"]:AttachTo(inventory:GetObject("InventoryFan5"))
    effectors["InventoryFan5"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan5"]:SetKey(_TRACK_Y, 0, 446.5);
    effectors["InventoryFan5"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan5"]:SetKey(_TRACK_A, 0, 2.1118483925);
    effectors["InventoryFan5"]:SetKey(_TRACK_A, 0.66666666666667, 0.7853981625);

    inventory:GetObject("InventoryFan6"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan6"] = CreateAnimationEffector()
    effectors["InventoryFan6"]:AttachTo(inventory:GetObject("InventoryFan6"))
    effectors["InventoryFan6"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan6"]:SetKey(_TRACK_Y, 0, 446.5);
    effectors["InventoryFan6"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan6"]:SetKey(_TRACK_A, 0, 2.1118483925);
    effectors["InventoryFan6"]:SetKey(_TRACK_A, 0.75, 0.453785605);

    inventory:GetObject("InventoryFan7"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan7"] = CreateAnimationEffector()
    effectors["InventoryFan7"]:AttachTo(inventory:GetObject("InventoryFan7"))
    effectors["InventoryFan7"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan7"]:SetKey(_TRACK_Y, 0, 446.5);
    effectors["InventoryFan7"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan7"]:SetKey(_TRACK_A, 0, 2.1118483925);
    effectors["InventoryFan7"]:SetKey(_TRACK_A, 0.91666666666667, 0.1221730475);

    inventory:GetObject("InventoryFan8"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan8"] = CreateAnimationEffector()
    effectors["InventoryFan8"]:AttachTo(inventory:GetObject("InventoryFan8"))
    effectors["InventoryFan8"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan8"]:SetKey(_TRACK_Y, 0, 446.5);
    effectors["InventoryFan8"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan8"]:SetKey(_TRACK_A, 0, 2.1118483925);
    effectors["InventoryFan8"]:SetKey(_TRACK_A, 1.08333333333333, -0.20943951);

    inventory:GetObject("InventoryFan9"):GetAnimation():SetHotSpot(60.5, 346)
    effectors["InventoryFan9"] = CreateAnimationEffector()
    effectors["InventoryFan9"]:AttachTo(inventory:GetObject("InventoryFan9"))
    effectors["InventoryFan9"]:SetKey(_TRACK_X, 0, 333);
    effectors["InventoryFan9"]:SetKey(_TRACK_Y, 0, 445.5);
    effectors["InventoryFan9"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryFan9"]:SetKey(_TRACK_A, 0, 2.1118483925);
    effectors["InventoryFan9"]:SetKey(_TRACK_A, 1.25, -0.5410520675);

    local wheels_anchor = CreateAutoRegisterEntity()
    wheels_anchor:AttachTo(inventory)
    wheels_anchor:SetXY(-220, 230)
    inventory:GetObject("InventoryWheel01"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel02_1"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel02_2"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel02_3"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel03"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel05"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel06_1"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel06_2"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel07_1"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel07_2"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel08_1"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel08_2"):AttachTo(wheels_anchor)
    inventory:GetObject("InventoryWheel08_3"):AttachTo(wheels_anchor)

    inventory:GetObject("InventoryWheel01"):GetAnimation():SetHotSpot(149.5, 149.5)
    effectors["InventoryWheel01"] = CreateAnimationEffector()
    effectors["InventoryWheel01"]:AttachTo(inventory:GetObject("InventoryWheel01"))
    effectors["InventoryWheel01"]:SetKey(_TRACK_X, 0, 95);
    effectors["InventoryWheel01"]:SetKey(_TRACK_Y, 0, 691);
    effectors["InventoryWheel01"]:SetKey(_TRACK_X, 0.20833333333333, 282);
    effectors["InventoryWheel01"]:SetKey(_TRACK_Y, 0.20833333333333, 485);
    effectors["InventoryWheel01"]:SetKey(_TRACK_X, 2.29166666666667, 282);
    effectors["InventoryWheel01"]:SetKey(_TRACK_Y, 2.29166666666667, 471);
    effectors["InventoryWheel01"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel01"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel01"]:SetKey(_TRACK_A, 6.66666666666667, -6.2657320075);
    TimerDoString("CycleObjectRotation('InventoryWheel01', -6.2657320075, 6.66666666666667)", 6.66666666666667, timer)

    inventory:GetObject("InventoryWheel02_1"):GetAnimation():SetHotSpot(66.5, 66.5)
    effectors["InventoryWheel02_1"] = CreateAnimationEffector()
    effectors["InventoryWheel02_1"]:AttachTo(inventory:GetObject("InventoryWheel02_1"))
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_X, 0, -44);
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_Y, 0, 519);
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_X, 0.20833333333333, 291);
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_Y, 0.20833333333333, 731);
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_X, 0.66666666666667, 473);
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_Y, 0.66666666666667, 534);
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel02_1"]:SetKey(_TRACK_A, 6.625, 43.9736809176266);
    TimerDoString("CycleObjectRotation('InventoryWheel02_1', 43.9736809176266, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel02_2"):GetAnimation():SetHotSpot(66.5, 66.5)
    effectors["InventoryWheel02_2"] = CreateAnimationEffector()
    effectors["InventoryWheel02_2"]:AttachTo(inventory:GetObject("InventoryWheel02_2"))
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_X, 0, -44);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_Y, 0, 519);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_X, 0.20833333333333, 291);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_Y, 0.20833333333333, 731);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_X, 0.41666666666667, 473);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_Y, 0.41666666666667, 534);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_X, 0.54166666666667, 412.989824783864);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_Y, 0.54166666666667, 336.64278090692);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_X, 0.66666666666667, 243);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_Y, 0.66666666666667, 291);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel02_2"]:SetKey(_TRACK_A, 6.625, 43.9736809176266);
    TimerDoString("CycleObjectRotation('InventoryWheel02_2', 43.9736809176266, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel02_3"):GetAnimation():SetHotSpot(66.5, 66.5)
    effectors["InventoryWheel02_3"] = CreateAnimationEffector()
    effectors["InventoryWheel02_3"]:AttachTo(inventory:GetObject("InventoryWheel02_3"))
    effectors["InventoryWheel02_3"]:SetKey(_TRACK_X, 0, -44);
    effectors["InventoryWheel02_3"]:SetKey(_TRACK_Y, 0, 318);
    effectors["InventoryWheel02_3"]:SetKey(_TRACK_X, 0.41666666666667, 117);
    effectors["InventoryWheel02_3"]:SetKey(_TRACK_Y, 0.41666666666667, 375);
    effectors["InventoryWheel02_3"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel02_3"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel02_3"]:SetKey(_TRACK_A, 6.625, 43.9736809176266);
    TimerDoString("CycleObjectRotation('InventoryWheel02_3', 43.9736809176266, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel03"):GetAnimation():SetHotSpot(92, 92.5)
    effectors["InventoryWheel03"] = CreateAnimationEffector()
    effectors["InventoryWheel03"]:AttachTo(inventory:GetObject("InventoryWheel03"))
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.125, 191.5);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.125, 665);
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.33333333333333, 262.453743169798);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.33333333333333, 621.171910658987);
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.54166666666667, 262.529109063289);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.54166666666667, 621.314096481687);
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.625, 321.540919164841);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.625, 615.85405268693);
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.66666666666667, 368.939826128448);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.66666666666667, 590.01083538504);
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.70833333333333, 394.987949482092);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.70833333333333, 567.799256354744);
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.75, 411.801673952421);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.75, 537.704986425313);
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.79166666666667, 421.925698565749);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.79166666666667, 506.327278209201);
    effectors["InventoryWheel03"]:SetKey(_TRACK_X, 0.83333333333333, 420.5);
    effectors["InventoryWheel03"]:SetKey(_TRACK_Y, 0.83333333333333, 476);
    effectors["InventoryWheel03"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel03"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel03"]:SetKey(_TRACK_A, 6.625, 10.5243353775);
    TimerDoString("CycleObjectRotation('InventoryWheel03', 10.5243353775, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel05"):GetAnimation():SetHotSpot(92, 92)
    effectors["InventoryWheel05"] = CreateAnimationEffector()
    effectors["InventoryWheel05"]:AttachTo(inventory:GetObject("InventoryWheel05"))
    effectors["InventoryWheel05"]:SetKey(_TRACK_X, 0, -43);
    effectors["InventoryWheel05"]:SetKey(_TRACK_Y, 0, 187);
    effectors["InventoryWheel05"]:SetKey(_TRACK_X, 0.16666666666667, 159.500263874562);
    effectors["InventoryWheel05"]:SetKey(_TRACK_Y, 0.16666666666667, 159.500084347001);
    effectors["InventoryWheel05"]:SetKey(_TRACK_X, 0.25, 298);
    effectors["InventoryWheel05"]:SetKey(_TRACK_Y, 0.25, 296);
    effectors["InventoryWheel05"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel05"]:SetKey(_TRACK_A, 0, 0);
    --effectors["InventoryWheel05"]:SetKey(_TRACK_A, 0.75, 16.54572129);
    effectors["InventoryWheel05"]:SetKey(_TRACK_A, 6.625, 6.70206432);
    TimerDoString("CycleObjectRotation('InventoryWheel05', 6.70206432, 6.625)", 6.625, timer)
    --TimerDoString("CycleObjectRotation('InventoryWheel05', 6.70206432-16.54572129, 6.625-0.75, 6.70206432)", 6.625, timer)

    inventory:GetObject("InventoryWheel06_1"):GetAnimation():SetHotSpot(15.375, 16)
    effectors["InventoryWheel06_1"] = CreateAnimationEffector()
    effectors["InventoryWheel06_1"]:AttachTo(inventory:GetObject("InventoryWheel06_1"))
    effectors["InventoryWheel06_1"]:SetKey(_TRACK_X, 0.70833333333333, 27);
    effectors["InventoryWheel06_1"]:SetKey(_TRACK_Y, 0.70833333333333, 292.5);
    effectors["InventoryWheel06_1"]:SetKey(_TRACK_X, 0.83333333333333, 181.5);
    effectors["InventoryWheel06_1"]:SetKey(_TRACK_Y, 0.83333333333333, 293);
    effectors["InventoryWheel06_1"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel06_1"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel06_1"]:SetKey(_TRACK_A, 6.625, 111.5090857825);
    TimerDoString("CycleObjectRotation('InventoryWheel06_1', 111.5090857825, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel06_2"):GetAnimation():SetHotSpot(15.375, 16)
    effectors["InventoryWheel06_2"] = CreateAnimationEffector()
    effectors["InventoryWheel06_2"]:AttachTo(inventory:GetObject("InventoryWheel06_2"))
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_X, 0.04166666666667, 298.5);
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_Y, 0.04166666666667, 719);
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_X, 0.45833333333333, 388.088137042444);
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_Y, 0.45833333333333, 510.647403181339);
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_X, 0.75, 401.5);
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_Y, 0.75, 358);
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel06_2"]:SetKey(_TRACK_A, 6.625, 111.5090857825);
    TimerDoString("CycleObjectRotation('InventoryWheel06_2', 111.5090857825, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel07_1"):GetAnimation():SetHotSpot(25.5, 26.625)
    effectors["InventoryWheel07_1"] = CreateAnimationEffector()
    effectors["InventoryWheel07_1"]:AttachTo(inventory:GetObject("InventoryWheel07_1"))
    effectors["InventoryWheel07_1"]:SetKey(_TRACK_X, 0.58333333333333, 12);
    effectors["InventoryWheel07_1"]:SetKey(_TRACK_Y, 0.58333333333333, 267);
    effectors["InventoryWheel07_1"]:SetKey(_TRACK_X, 0.75, 199);
    effectors["InventoryWheel07_1"]:SetKey(_TRACK_Y, 0.75, 268);
    effectors["InventoryWheel07_1"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel07_1"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel07_1"]:SetKey(_TRACK_A, 6.625, 72.4486171675);
    TimerDoString("CycleObjectRotation('InventoryWheel07_1', 72.4486171675, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel07_2"):GetAnimation():SetHotSpot(25.5, 26.625)
    effectors["InventoryWheel07_2"] = CreateAnimationEffector()
    effectors["InventoryWheel07_2"]:AttachTo(inventory:GetObject("InventoryWheel07_2"))
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_X, 0, 288);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_Y, 0, 704);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_X, 0.29166666666667, 351.762009273086);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_Y, 0.29166666666667, 601.869049880324);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_X, 0.375, 348.999933450991);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_Y, 0.375, 562.000260005433);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_X, 0.75, 374);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_Y, 0.75, 368);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel07_2"]:SetKey(_TRACK_A, 6.625, 72.4486171675);
    TimerDoString("CycleObjectRotation('InventoryWheel07_2', 72.4486171675, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel08_1"):GetAnimation():SetHotSpot(27.8125, 27.8125)
    effectors["InventoryWheel08_1"] = CreateAnimationEffector()
    effectors["InventoryWheel08_1"]:AttachTo(inventory:GetObject("InventoryWheel08_1"))
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_X, 0.75, 36.5);
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_Y, 0.75, 250);
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_X, 0.83333333333333, 97.9999040456139);
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_Y, 0.83333333333333, 318.999937320119);
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_X, 0.91666666666667, 160.5);
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_Y, 0.91666666666667, 331);
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel08_1"]:SetKey(_TRACK_A, 6.625, 77.9987641825);
    TimerDoString("CycleObjectRotation('InventoryWheel08_1', 77.9987641825, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel08_2"):GetAnimation():SetHotSpot(27.8125, 27.8125)
    effectors["InventoryWheel08_2"] = CreateAnimationEffector()
    effectors["InventoryWheel08_2"]:AttachTo(inventory:GetObject("InventoryWheel08_2"))
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_X, 0.70833333333333, 52);
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_Y, 0.70833333333333, 208);
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_X, 0.79166666666667, 107.749924551995);
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_Y, 0.79166666666667, 279.499937320119);
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_X, 0.875, 149.5);
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_Y, 0.875, 289);
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel08_2"]:SetKey(_TRACK_A, 6.625, -76.4977810275);
    TimerDoString("CycleObjectRotation('InventoryWheel08_2', -76.4977810275, 6.625)", 6.625, timer)

    inventory:GetObject("InventoryWheel08_3"):GetAnimation():SetHotSpot(27.8125, 27.8125)
    effectors["InventoryWheel08_3"] = CreateAnimationEffector()
    effectors["InventoryWheel08_3"]:AttachTo(inventory:GetObject("InventoryWheel08_3"))
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_X, 0.5, 257.5);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_Y, 0.5, 727);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_X, 0.54166666666667, 324.267487722655);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_Y, 0.54166666666667, 707.739746696486);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_X, 0.66666666666667, 468.000133871845);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_Y, 0.66666666666667, 549.499725291878);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_X, 0.75, 480.991412354649);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_Y, 0.75, 457.269471180813);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_X, 0.83333333333333, 430.5);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_Y, 0.83333333333333, 372);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_O, 0, 1);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_A, 0, 0);
    effectors["InventoryWheel08_3"]:SetKey(_TRACK_A, 6.625, -76.4977810275);
    TimerDoString("CycleObjectRotation('InventoryWheel08_3', -76.4977810275, 6.625)", 6.625, timer)

    inventory_info.bleft:Go()
    inventory_info.bright:Go()

    effectors["bleft"] = CreateAnimationEffector()
    effectors["bleft"]:AttachTo(inventory_info.bleft)
    effectors["bleft"]:SetKey(_TRACK_O, 0., 0.);
    effectors["bleft"]:SetKey(_TRACK_O, 1., 0.);
    effectors["bleft"]:SetKey(_TRACK_O, 1.5, 1.);

    effectors["bright"] = CreateAnimationEffector()
    effectors["bright"]:AttachTo(inventory_info.bright)
    effectors["bright"]:SetKey(_TRACK_O, 0., 0.);
    effectors["bright"]:SetKey(_TRACK_O, 1., 0.);
    effectors["bright"]:SetKey(_TRACK_O, 1.5, 1.);

    for i, v in pairs(effectors) do
        v:Play()
    end

	inventory:GetObject("area_bleft"):SetOpacity(1.)
	inventory:GetObject("area_bright"):SetOpacity(1.)

    DefaultOnObjectMouseDown(inventory:GetObject("area_bleft"))

	if game_state.comics then
		game_state.comics.SetVisible(false)
	end
end

function InventoryOnButtonPress(title)
    if title == 'InventoryRight' then
        RotateInventory(true)
    end
    if title == 'InventoryLeft' then
        RotateInventory(false)
    end
end

function CanRotateLeft()
    return inventory_info.nrotates - (5 - play_field:GetLevelScreen():GetInventory():GetNTools()) > 0
end

function CanRotateRight()
    return inventory_info.nrotates < 0
end

-- rotate_left: true - left, false - right
function RotateInventory(rotate_left, immediate)
    if (not rotate_left and CanRotateRight()) or
       (rotate_left and CanRotateLeft())
    then
        local dangle = M_PI / 9.6
        inventory_info.nrotates = inventory_info.nrotates + 1

        if rotate_left then
            dangle = -dangle
            inventory_info.nrotates = inventory_info.nrotates - 2
        end

        if immediate then
            for i, v in ipairs(inventory_info.objects_to_rotate) do
                if immediate then
                    v:SetAngle(v:GetAngle() + dangle)
                else
                    v:Rotate(dangle, 0.3)
                end
            end
        else
            inventory_info.angle_to_rotate = inventory_info.angle_to_rotate + dangle
        end
    end
end

-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
