--        print("mouseleave", object,self.current)

        if (self.current == object) then
            
            --Maybe we drop down onto another object now?
            --We left, do we hover a different object?
            for key,rec in pairs(self.list) do
                
                
                
                if (key==self.current) then
                    continue --skip us
                end
                if (rec.screen ~= screen) then
                    continue
                end
                
                if (rec.hovering == true) then
                    --They're hovering but were not current, meaning they were waiting
                    
                    self.current = rec.object
                    rec.enterMethod()
                    rec.down = true
                    return
                end
            end
            self.current = nil
        end
        
    end)
    
end

function module:EnterHover(object)
    
    
    
    if (self.current == object) then
        module:LetUpAllOthers(object)
        return true
    end
    if (self.current == nil) then
        module:LetUpAllOthers(object)
        self.current = object
        return true
    end    
        
    if (object.ZIndex > self.current.ZIndex) then
        module:LetUpAllOthers(object)
        self.current = object
        return true
        
    end
    return false
end

function module:LetUpAllOthers(object) 
    
    
    local screen = object:FindFirstAncestorWhichIsA("ScreenGui")
    
    for key,rec in pairs(self.list) do
        
        if (rec.screen ~= screen) then
            continue
        end
        
        if (rec.hovering and rec.object ~= object) then
            if (rec.down == true) then
                if (rec.exitMethod) then
                    rec.exitMethod()
                end
                rec.down = false
            end
        end
    end
    
end

return module
