Why does a cork float to the side of a glass? Why does a cork ball float to the side of a glass as illustrated in the following GIF? What is the physical phenomenon behind this observation and why does it happen?

 A: Fascinating! I suspect the cork is attracted to the side of the glass, as it minimizes the surface tension of the water.  Edit for clarification: by going to the side of the glass, the cork minimizes the length of the interface between the water and the other materials contacting the water. 
A: It's a combination of two effects: buoyancy and adhesion.
Buoyancy lifts the cork up as much as possible, until it displaces its own weight of water (Archimedes' principle). For this reason, the cork will seek the highest point of the water level.
Because of adhesion between the water molecules and the glass, the water level is highest at the edges (the water level is concave). As a result, the cork moves to the sides.
If you'd fill up the glass to the brim, the water level becomes convex (due to surface tension), and the cork will stay in the middle.
See also this site and this youtube video.

Extra Info
By coincidence, a very similar question came up yesterday on a Dutch science program, and I learned there's actually a name for this phenomenon: the Cheerios effect. The name is derived from the fact that small floating objects on a liquid, like bubbles on water or cheerios on milk, tend to clump together, or stick to the walls.
The reason is the same as my answer above: there are two forces acting on a floating object: the buoyancy (which tries to push the object out of the liquid) and the surface tension (which tries to keep the object in the liquid). The result is a compromise, where the object is pushed partially out of the liquid, causing the surface to deform: it forms a small hill.
Nearby floating objects are affected by this deformation: a floating object seeks the highest point in a liquid (the buoyancy causes it to rise and move
upward along the surface), so it will move towards the 'hill' formed by the other object. Therefore, bubbles (or cheerios) will cluster together.
A similar effect happens with objects that are denser than the liquid, but are not too heavy, so that they don't sink thanks to the surface tension. Paper clips are an example. These objects actually push down the liquid, creating a small 'valley' in the surface around them. But such object will also seek the lowest point on the surface, which means that nearby dense objects will again be attracted to each other. So paper clips also cluster together.
What happens when an object less dense than the liquid (e.g. a cheerio) is next to an object denser than the liquid (e.g. a paper clip)? The first creates a hill and seeks the highest point, the second creates a valley and seeks the lowest point. So the result is that they will repel each other!
There's a very nice paper that explains these effects in more detail:
The 'Cheerios effect' (Vella & Mahadevan, 2004).
A: What seems to be happening is that capillary effects in the presence of gravity create a situation in which the cork being maximally decentralized in the glass corresponds to a minimum energy configuration. 
My guess is that the cork is non-wetting, and therefore surrounded by a water surface that bends down in the proximity of the cork, thereby creating a minute overall increase of water level in the glass. With the cork resting against the edge of the glass, this water level increase gets minimized. 
If all of this is right, the effect should disappear if the cork is replaced by a floating material that is water wet.
A: I looked up the answer to this one in a book published in 1914 - you don't get many citations 99 years old! For the interested, the book is "A Textbook of Physics Vol 1" by J. H. Poynting and J. J. Thompson, page 188 in my copy. Incidentally that's the same J. J. Thompson who discovered the electron - Poynting has a vector named after him though only physicists are likely to have heard of it.
Anyhow, suppose you have two parallel plates partially immersed in a liquid. In our case one plate is the wall of the beaker and the other is the side of the cork (they aren't exactly parallel but it's a reasonable approximation.

The liquid between the plates rises up due to capillary action. The height of the rise is given by:
$$ h = \frac{2\gamma \cos\theta}{d\rho g} $$
Where $\gamma$ is the surface tension of the fluid and $\theta$ is the contact angle, $\rho$ is the density of the fluid and $g$ the acceleration due to gravity. It's the capillary rise that causes the attractive force between the plates, or in this case between the cork and the beaker, but the explanation for this force is probably not what you think.
It's tempting to think that it's the surface tension that pulls the plates together, but Poynting shows that the surface tension on the two sides of each plate always balances out i.e. the surface tension causes no net force on the plate. The argument for this is subtle and I'm not going to reproduce it here - check Poynting's book for the gory details.
The force is created because the region of raised water between the plates is at a pressure less than atmospheric pressure, so outside the two plates the pressure is 1 atm but in the fluid between the plates the pressure is less than 1 atm. The result is a net force that pulls the plates together. This pressure reduction happens because the curvature of the meniscus at the top of the raised water exerts a tension on the water, which is obvious because that's what pulls the water up. The average pressure difference between the raised film between the plates and the atmosphere outside is simply:
$$ \Delta P = \rho g h/2 $$
So using our equation for $h$ above we get:
$$ \Delta P = -\frac{\gamma \cos\theta}{d} $$
where the minus sign indicates the pressure is lower between the plates.
So there is always an attractive force between the plates, and this force is proportional to $d^{-1}$, which is why the cork accelerates as it gets closer to the side of the beaker.
