function IsSolvedSides()
    local currModule = _G[self:GetName()]
    local right = true
    
    for i = 1, 13 do
        local name = "spr_s03_0119_item_"..i
        local pName = "snd_point_"..i
        local angle = bkg.elements[name]:GetAngle()
        local pos = currModule[name].self:GetPosition()
        local pPos = currModule[pName].self:GetPosition()
        local lenght = (pPos - pos):length() 
        if angle ~= 0 or lenght>0.03  then
            right = false
        end
    end
    
    return right
end

function SolvedEvent()
    s.s03_0119_luggage_solved=1
	Delete("i_things")
    Talk("com_s03_0119_01_hero")
end

function OnUpdate()
    if s.s03_0119_luggage_solved == 1 then
        return
    end
    local currModule = _G[self:GetName()]
 
    local attName = Cursors:GetAttachmentName()
    local att = currModule[attName]
    if att~=nil and not IsMouseButtonDown(0) then
        Cursors:DetachSprite(false) 
        local pos = att.self:GetPosition()
        if pos.x>0.9 then
            pos.x = 0.9
        end
        if pos.y>0.74 then
            pos.y = 0.74
        end
        if pos.x<0.05 then
            pos.x = 0.05
        end
        if pos.y<0.02 then
            pos.y = 0.02
        end
        att.self:SetPosition(pos)
        local pointName = "snd_point_"..string.sub(attName,19, string.len(attName))

        local point = currModule[pointName]
            
        if point == nil then
            return
        end
        local pPos = point.self:GetPosition()
        local ang = bkg.elements[attName]:GetAngle()
        local lenght = (pPos - pos):length()
        if lenght<0.03 and ang == 0 then
            att.self:SetPosition(pPos)
            if IsSolvedSides() then
               SolvedEvent()
            end
            PlaySound("snd_s03_0119_right_position")
        end
    end

end


function OnSceneEnter()
    local currModule = _G[self:GetName()]
    OldInterfaceMap.SetCuttentModule(currModule)

    indexed = {}
    for i = 1, 13 do
        indexed[#indexed+1] = "spr_s03_0119_item_"..i
    end    
    
    indexed[#indexed + 1] = "spr_s03_0119_top"
    
    OldInterfaceMap.SetIndexedElements(indexed)
    Load()
    
    SetMinigameResolver(function()        
            s.s03_0119_luggage_solved=1
			Delete("i_things")
			Talk("com_s03_0119_01_hero")
            
        local currModule = _G[self:GetName()]
        
        for i = 1, 13 do
            local name = "spr_s03_0119_item_"..i
            local pName = "snd_point_"..i
            local angle = bkg.elements[name]:GetAngle()
           
            local pPos = currModule[pName].self:GetPosition()
            currModule[name].self:SetPosition(pPos)
        end
    
    end)
end

function Save()
    local sT = OldSavableTable("s03_0119_luggage")
    for i = 1, 13 do
         sT["item_"..i.."_x"], sT["item_"..i.."_y"] = bkg.elements["spr_s03_0119_item_"..i]:GetPosition()
    end 
end

function Load()
    if SavableTableExists("s03_0119_luggage") then
        local sT = OldSavableTable("s03_0119_luggage")
        for i = 1, 13 do
             bkg.elements["spr_s03_0119_item_"..i]:SetPosition(sT["item_"..i.."_x"], sT["item_"..i.."_y"])
        end         
    end
end

function OnSave()
    Save()
end

function OnLoad()
    Load()
end

function OnSceneExit()
    Save()
end