Gray‘s shares are +15% this morning after it unveiled the complicated agreements that involve several entities. The bottom line is that the company and Excalibur Broadcasting — a privately held firm closely allied with Gray — will pay $342.5M for 17 network affiliates including 4 with ABC, 8 with NBC, 2 with CBS and 3 with Fox in small to mid-sized markets. Gray agreed to pay $335M for stations owned by Hoak Media in eight markets. Gray will sell the ABC affiliate in Panama City, FL and the CBS station in Grand Junction-Montrose, CO (plus two of its satellite stations) in order to comply with federal ownership restrictions. As part of that deal, Excalibur will end up with four stations from Hoak and Parker Broadcasting  — and then unload a Fox affil in Grand Junction to comply with regulations. And separately, Excalibur agreed to pay $7.5M for the Fox affiliate (and a satellite station) owned by Prime Cities Broadcasting in Minot, ND. When the deals close — which Gray expects will happen by mid-2014 — the broadcaster will own or operate stations in 39 markets, and have the top rated station in 29 of them. “These transactions will yield impressive synergies, many of which are unique to Gray given how well the stations’ locations, operations and culture complement our own,” says Gray CEO Hilton Howell. Wells Fargo analyst Marci Ryvicker says the deals are “positive and potentially transformative” for the company.