Just a note of warning: Beta's response is somewhat strange. I'm a native English speaker and have never heard "fruitcake" used as a homosexual slur. (Calling someone a "fruit" is a gay slur, but "fruitcake" is only used to describe someone who is crazy.)
Also, it's generally in a light-hearted or fond term, not used in a serious mentally-ill kind of way. As you guessed, it comes from the phrase "he's nutty as a fruitcake", since "to be nuts" is slang for being crazy, and fruitcake generally has a lot of nuts in it.
As one last note, be careful with using the word "mad" to mean "crazy"! I think that might be fairly common British English usage, but without specific context, Americans will always assume you mean "angry" instead.