Offer + Acceptance + Consideration = enforceable Contract
The "earnest money" provision is usually the liquidated damages portion of the contract. Generally, the buyer contractually agrees to forfeit his earnest money deposit (usually held in the broker's or closing agent's escrow account) if the buyer refuses to perform for reasons other than the failure of a contingency clause. But, this is far from a simple issue.
The seller may be willing to release you from your contractual obligations. If he does release you, you should try to get the agreement to cancel the contract in writing. He might not agree to cancel the contract, so you should educate yourself concerning your options. There are many practical as well as legal considerations depending on the amount of the earnest money, the explicit language contained in your contract, and the law of your state.
You can research "real estate," "earnest money," and "liquidated damages" on the internet to obtain general knowledge concerning the issue. You should try to research general information and court decisions for your particular state.
Here are a few links:
http://tms.ecol.net/realestate/ofr_estl.htm
http://www.legalwiz.com/articles/earnest-rightframe.htm
http://www.dcba.org/brief/profresp/0698.htm
If the seller refuses to cancel the contract--CONSULT AN ATTORNEY who practices real estate law in your locality.