What is the cause of muscle cramps?
The quick and simple answer:

Cramps of a hypokalemic origin are much more common than those of a hyponatremic origin because the Na-K pump is more effective at moving potassium in comparison to sodium.
At the onset of a muscle contraction, the presence of calcium triggers the opening of the Na-K channels in the membrane. Potassium is a calcium inhibitor, so as the potassium flows out of the cell, it eventually reduces the presence of calcium. This causes the closure of the Na-K channel (negative feedback mechanism). In a hypokalemic state, the lack of sufficient K doesn't inhibit the calcium channel, and in turn doesn't properly terminate the muscle contraction at the cellular level. 

The continued presence of calcium, which has a lot to do with nerve impulses, means that the nerves keep firing, and in some cases such as a 'charlie horse', these impulses fire fast and continuously. The body at this point is reaching a small local state of metabolic acidosis resulting from the extremely high oxygen consumption, increasing levels of CO₂ (the acidosis component) and reducing blood partial oxygen levels. Since the oxygen is no longer as abundant as it was, it inhibits the bodies ability to locally produce the ribose and phosphate necessary for ATP. Less ATP = more myosin that can't be disconnected from actin = continued muscle cramp.