Need Help with a PSTN/VOIP design

I will be connecting two offices … Office “1” has a legacy proprietary hardware PBX connected to a telephone line coming from the telco and it’s integrating a number analog phones … On the other side lies Office “2” containing an asterisk server connected to a number of analog phones through ATA’s … and the asterisk server is also connected to a telephone line coming from the telco.

Here is a diagram that I cooked in 2 minutes just to show how will the system look like.

Now, what I want to do is as follows:

A phone from office “1” calls office “2” … The call should be directed through the Internet using VOIP … In case the Internet connection is down … The call should be transmitted through the PSTN instead.

What device do I need in office “1” to do this particular task … I believe the device should have 3 ports … The first connected to the telephone line from the telco and the second to the Legacy PBX and the third to the Network Switch … What’s the device needed ?

An FXO <-> SIP gateway, like Audiocodes MP FXO for example.

Regards.

Marco Bruni