I found what looks like a good dog site. This is taken from crazyfordogs.com
Why do dogs bark?:

Dogs bark to say that there is something strange happening and to be alert. In the wild the barking tells puppies to hide and calls the adults over for action. At home, our dog may bark at us or at a burglar. The barking signals that something is happening; once the new arrival has been identified, either a greeting takes place or an attack.