Trunk failover for intra-company routes

Hi, I've been playing with our configuration for a bit, and thought I had a great idea going...

We have a total of 5 systems running across the state, and each location uses IAX trunks over a VPN to interconnect the systems. All works well, and extension dialing from one system to another is great - at least as long as the VPN tunnel is up. Since each location has its own tunnel to every other location, this has the downside that if one of the tunnels dies, the phone trunk is lost at the same time. As voice is usually the only traffic that will go through this, and since calls are infrequent, a tunnel failure is not always noticed immediately.

To avoid having calls go to a dead trunk, I thought it would be great to allow each location to get to another by going through any other location as well - thus location A calling B would initially go across the AB trunk, but failing that would allow the call to go A-C-B if that trunk was up as well. Recently I had to try to troubleshoot a partially related issue, when one location was trying to call another that was completely off the network for other reasons. What ended up happening was that A would try calling B, and with that failing, the call would go to C, which would try to call B. Since that failed, C then passed the call off to D, which repeated the process of trying to contact B. Since that now failed, the call was passed to E, which tried B and tried to pass it off to the next system in line... ie A. Granted, in this case the call actually failed at D for an unrelated problem in the routing logic, but you see the problem...

Is there any simple way to allow such logic, without the endless loop becoming a problem?