how old is this dog? you definately need to schedule a vet appt. asap! could be a number of things. kind of sounds like distemper which is very dangerous.
Well, this is weird! I am sorry you had to wait so long for a reply.
I don't know what this is all about. All I can think of is he is looking for some attention, and the chattering of teeth/foaming at the mouth could be reinforced by any attention he might receive whilst doing this (sounds strange I know, but if it happened once, and he got attention, then it could set up a pattern of repeat behaviour)
However, there might be some physical reason why this is happening. I would ask your vet about this.