TIM CAHILL HAD A GOOD DAY in court on Thursday. The former state Treasurer looked at ease taking the stand to deny charges that he used state Lottery funds to prop up his failed 2010 bid for governor. He leaned forward, both elbows propped up on the witness stand, and insisted that the $1.5 million Lottery television ad campaign that had landed him in Suffolk Superior Court had nothing to do with his gubernatorial ambitions. He shifted ownership of the ad campaign away from himself, while still painting himself as a selfless public servant. He knew he’d take heat by running the ads, he said, but he ran them anyway because he wanted to do right by the Lottery. He built a solid firewall between himself and the criminal ethics charges he’s facing.

On Friday, through more than three hours of punishing questioning, prosecutors from the Attorney General’s office tore away at Cahill’s firewall, brick by brick. On Thursday, the Quincy politician had smiled broadly at the court officer who led him up to the witness stand, rocking back and forth with a nervous, excited energy as he raised his hand and swore to tell the truth. By midday Friday, he was alternately snipping at and shrugging off prosecutors, saying he had no memory of a mounting pile of documents that seemed to put his campaign in the middle of the taxpayer-funded Lottery spending spree.

Cahill and his former campaign manager, Scott Campbell, have pleaded not guilty to charges that they used a $1.5 million Lottery ad blitz to bolster Cahill’s flagging gubernatorial campaign. Attorney General Martha Coakley has alleged that Cahill used the Lottery ads to supplement his own campaign funds. Cahill has countered that the ads were needed to rebut a scorched earth anti-Cahill advertising attack from the Republican Governors Association (RGA). The group buried Cahill with a series of harshly negative ads that argued, in part, that Cahill had overseen a wasteful Lottery spending spree.

On Thursday, Cahill said the idea for the public ad campaign came from the Lottery’s former executive director, Mark Cavanagh. He said Cavanagh didn’t have the budget to rebut the RGA ads when they first appeared in the spring of 2010, but that Cavanagh was concerned the RGA attacks were damaging the Lottery’s brand. Cahill added that, by the time the ads hit the airwaves, his campaign was all but lost already. “I was still the treasurer of the Commonwealth,” he said. “I probably knew I wasn’t going to be the governor, but I still wanted to do right by the Lottery, right to the end.”

On Friday, prosecutors repeatedly attacked that contention. They pointed out that, while Cahill’s campaign had done extensive polling to measure the effect of the RGA attacks on Cahill as a candidate, the Lottery never tried to quantify the effect of the negative ads on the organization itself. In fact, Lottery sales held steady in the face of the initial wave of RGA attacks; they were down by less than 1.5 percent for the rough six-month period between the start of the RGA ads, in April 2010, and the start of the Lottery campaign in late September.

A second round of RGA attacks, which began in July, savaged Cahill personally, but never mentioned the Lottery by name. “I was the chair of the Lottery,” Cahill reasoned Friday. “They could have referred to anything I oversee, possibly.”

Prosecutors have repeatedly pointed to a late July set of campaign focus groups, which they claim cemented the Cahill campaign’s decision to promote their candidate’s ties to the Lottery. The day after one focus group, Cahill’s campaign media consultant urged him to push a positive Lottery-focused message more aggressively. After the conversation, the consultant, Dane Strother, emailed the campaign: “We just found a million for extra publicity, but Cahill can’t be in the ad. But we run ads about the Lottery being well run and putting money back in communities. I’m going to speak with an ad company about copy, Cahill agreed.”

A day later, Cahill was on the phone to the Lottery’s publicly funded ad agency, Hill Holliday, records show.

Cahill testified Friday that he couldn’t remember the specifics of his conversation with Strother, but confirmed that he’d told Strother the Lottery’s annual ad budget was $2 million, and that he had allowed Strother to reach out to Hill Holliday. A week later, Cahill had lunch with the ad company’s CEO, Mike Sheehan. Cahill remembers talking Lottery business, but couldn’t recall whether the gubernatorial campaign came up.

The day after the lunch, according to records produced by prosecutors, Strother called Sheehan to follow up on his lunch with Cahill; the two connected the next day, and within an hour, Hill Holliday was rewriting a Lottery ad script the agency had on file. That finished script was later emailed to a Cahill campaign operative from Sheehan’s private email account.

Cahill seemed sharp on the stand Thursday, but his memory failed him on several occasions Friday. He said he couldn’t recall reading, responding to, and forwarding several emails prosecutors showed him. He also said he didn’t remember taking online state ethics training, which, records show, he completed just months before the questionable Lottery ad buy. The ethics training specifically prohibits using state resources for political purposes.

He didn’t recall the circumstances that led Hill Holliday’s CEO, Sheehan, to email a colleague saying Cahill was ready to “rip [the] head off” a Lottery staffer who was stonewalling the ad campaign. Shown phone records that indicated Cahill received a call from Sheehan that day, and then immediately telephoned the potentially-headless Lottery staffer in question, Cahill said he didn’t recall those calls, either.

Cahill insisted on Friday that there was no duplicity in running a feel-good Lottery ad while also running for governor promoting his record at the Lottery, since “It’s the truth, so it should be echoed.” In downplaying the impact of Strother’s July focus groups, Cahill said the Lottery “was always something we focused on” at the campaign. On cue, the prosecution produced two drafts of a radio ad Cahill staffers were writing in June, before the focus groups. The draft Strother wrote talked up the Lottery; Cahill edited that reference out.