Here are the instructions on how to open it up:
http://www.mazdas247.com/forum/attachment.php?attachmentid=123901
I assume that you will be looking on ebay. When doing so, just keep the dealer's price in mind which is about $180 for the transponder plus key (switchblade style).
http://www.trademotion.com/partlocator/index.cfm?siteid=214264
CC43675RYC, $141.36 (transponder)
G2YA762GXB, $39.01 (blank key for transponder, with chip)
KRTT09001, $0.49 key ring
and if you want a third key without a transponder: F1Y1762GX, $22.58 (blank key with chip, no transponder). This is a "real" key, smaller than the transponder and what I now keep on my key ring since the Mazda5 is primarily my wife's car at this point - with summer coming up I don't want the bulky transponder in my pants pocket. "Are you happy to see me, or do you drive a Mazda5?"
Keys come pre-cut if you provide your VIN.
And for the bad news - since you only have one working key and one working transponder, you will need to pay the dealer to program the new ones for you, it will cost about $80.