Balls are made of ferromagnetic material, for this reason the magnet has an effect of an attractive force on them. By getting in contact with the magnet, they themselves become magnets, too; this is why they make a chain. By moving the magnet away, they lose their magnetism, they fall back separately, because they are made of soft ferromagnetic material, iron.
Hard ferromagnetic materials (e.g. steel) can be magnetized permanently. Of this material are made permanent magnets (rod magnet, horseshoe magnet).
With the help of repelling force between the same poles a phenomenon called magnetic levitation (floating) occurs.
Earth does not have only gravity (which can be overcome with magnets), but it has its own magnetic field, too. This is connected to the unbelievable ability for orientation of migrant animals. Sea turtles cross whole oceans, our storks get home flying over more thousands of kilometres every year.