The mess resulted during the transition from early Hebraic beliefs, which are still reflected in the story of Job, where Satan was seen as a member of the Divine Elohim, a plural word in Hebrew which refers to the Divine Counsel in Heaven, a body of appointed spirit beings who served on Jehovah's Team, under his leadership.
The word 'Satan' was NOT a name (i.e. a personal pronoun), but in Hebrew is a title, lit. 'the accuser', perhaps analogous to some being who served as Jehovah's chief tester who challenged and tempted mortals with various tests in order to prove their worthiness (Jews believed all humans had yetzers, intrinsic tendencies towards both good and evil actions, where the latter must be restrained; Satan tested the evil tendency, called the yetzer hara, of humans).
Of course, the presence of Satan in Heaven should raise some troublesome questions in the minds of the reader in the first place, eg what is the arch-enemy doing serving on the staff? That would be like Bin Laden waltzing into the White House in 2003 and sitting down at a cabinet-level staff meeting, with the POTUS or chief of staff asking him to deliver a report on what he's been up to lately!
However, note in the book of Job that Satan is acting under the direct authority of Jehovah, as seen in the account when Satan requests Jehovah's permission to put the screws to Job (and God signs off on the request). So God ADMITS to being the Divine authorizer of evil, which wasn't an eyebrower raiser to Jews: that was their understanding of the way the World worked, and they didn't see any moral problems with the arrangement.
Only centuries later, after syncretism of Judaism's philosophies with Zoroastrian dualistic beliefs (where the good God named Ahura Mazda fought the bad god named Angra Mainyu, and the good god won in the end) under the fledgling name of Xianity occurred, Satan then morphed into this independent entity who was the arch-enemy and nemesis of Jehovah, the very personification of evil.
Of course, the associated concepts of Satan challenging God's Authority to rule in the Garden of Eden is a late development, too, which emerged in the intertestimental literature (i.e. the non-Biblical writings of the period between the OT and NT). But the story in Xianity hops back and forth to God being control of the Earth, Satan is in control (after being given the Earth by God), etc. God appoints secular authorities to rule on scripture, then they're all under the control of Satan. Hence Xianity shot-guns a theology, and the believers are allowed to cherry-pick scriptures which they want, and ignore those that contradict their desired interpretation.
Adam
EDIT: here's a video called "the evolution of the Devil", worth the 50 minutes:
http://www.youtube.com/watch?v=g8XQbqZUkms