Well it measures in thousands of dollars, but it can go down to hundreds or even less if you use rented dedicated machines.
Here are the links:
Asterisk :: An Open Source PBX and telephony toolkit | http://www.digium.com/
and something for "real" hackers:
YXA
Ask questions at their forums/mailing lists...
Best of luck