Info from FairVote.org
How are electoral votes apportioned?
Each state can dole out its electoral votes in whatever way it sees fit. Currently, 48 of 50 states and the District of Columbia give all of their electoral votes to the candidate that receives the most votes in that state. The two exceptions are Maine and Nebraska. (Read more about Maine and Nebraska here.) Currently, 533 of the 538 electoral votes go to a candidate who wins a majority in a state or the District of Columbia.
Back to top
If I'm actually voting for an elector, then why did I see "Barack Obama" and "John McCain" on my 2008 presidential ballot?
Electors can theoretically vote for whomever they want-- however in practice they pledge to vote for a certain candidate. This has created a system in which the American people vote indirectly for the president by voting for an elector (or statewide slate of electors) who supports their candidate of choice. This is further streamlined by the fact that most states do not list the names of potential electors on a ballot, but rather the names of the candidates they've promised to vote for.
Back to top
Do electors ever vote for someone other than the person they've promised to vote for?
It happens surprisingly frequently. In fact, 2008 marked the 56th presidential election in the United States, and in those 56 elections, 19 times there has been one or more faithless elector. That's roughly 34%, or one-third of all elections involving the Electoral College. That includes faithless electors in 2000 and 2004. While 29 states have laws requiring electors to vote for the candidate they've promised to vote for, the legal consequences involved are usually minimal, and might not be much of a deterrent against a person who wants to change history.
______________________________________
http://www.fairvote.org/reforms/national-popular-vote/the-electoral-college/electoral-college-faqs/#8