The earnest money deposit is a good faith deposit. The earnest money deposit serves to basically reassure the seller that you are serious about their property and willing to deposit that amount as a show of good faith.
The amount of the deposit can vary but its typically 3% in Los Angeles. The factors influencing it can be market conditions (so in a slower market you can probably negotiate it down), how much interest a property is generating (in a multiple offer situation a larger deposit could make your offer stronger) etc.
Usually your earnest money deposit is safe until you remove your buyer contingencies (loan, appraisal and buyer investigations). normally your contingencies would be active contingencies (which means that you as a buyer would have to remove them in writing) but a lot of REO addendums change that to a passive one - which means that once you pass the contingency deadline, your deposit might be at risk. your realtor should be able to advise you on how and when to release the contingencies in your purchase process.
Hope that helps