I've heard it's just like with dogs. If you let a dog hump your leg, you let it assert its dominance. Next time he goes crazy just grab him by the scruff and try to hold him back without hurting him (or yelling). Just hold him back until he calms down, and after a few seconds, give him a treat.