Will confess that I haven't read all of the above so what I'm about to say may already have been said.
There are a couple of likely reasons why you're cramping...a lack of sodium, a lack of potassium or a lack of condition. I'll take those in turn.
Lack of sodium: Salt. A bit (and I do mean a bit) of salt is good for you. Can't remember what it does but I do know that without it you get cramp. Check the packaging of your sports potions to see how much you're getting.
Lack of potassium. As above really. Bananas are a good source of potassium, and they're full of energy too...I actually quite like them as food for endurance sport.
Now...lack of condition. I've never met you, never been for a ride with you, never even seen you so take the general ideas that I'm about to suggest and then adapt and apply them to yourself. You cramped up at an event...at a guess you were probably hyped up on adrenaline (even if you didn't notice it) and trying to ride further and farther than you normally would. A cramp is your bodies way of saying to you "Hold on there fellah! My muscles have just created a whole LOAD of waste products and I can't get rid of them fast enough...you're going to have to stop until I can sort myself out." So if an event is coming up I'd suggest that you try and do something that mountain bikers seem to dislike doing: train. This might just be going for a ride...but when you get tired and want to stop and admire the view...don't. Push on. Get used to riding further...and if you're feeling really motivated maybe try doing some interval sessions to improve your cardio vascular system.
Finally...an idea for a fairly cheap and fairly effective sports drink:
500ml fruit juice (your choice) diluted with 500ml water. Add 1/5teaspoon of salt. Shake.
Hope something above was helpful and I didn't come accross as too much of an eejit.