ATLANTA (AP) — With three seats open on the Pennsylvania Supreme Court and a chance to flip control of the judicial branch, a wave of campaign cash, independent expenditures and negative TV ads flooded the state in the weeks before the November election.

Six candidates combined for $12.2 million in contributions, with two independent groups spending $3.5 million. The record sum for a state judicial election serves as a hint of what lies ahead when voters in two dozen states will cast ballots for state supreme court justices in 2016.

The flow of money into state judicial races has been rising in recent years and shows no sign of slowing down. Races in a handful of states, including Ohio and North Carolina, are among those that will be watched closely.

"There is every indication it will be another record spending election, with more outside money in a smaller set of hands," said Scott Greytak of Justice at Stake, an advocacy group that pushes for various reforms, including public financing of judicial elections. "It's going to be bad news across all fronts."

The increase in political funding has raised questions about how courts can maintain their independence when campaign donors and interest groups spend so much money seeking influence on the bench.

The debate is not limited to a handful of states. Thirty-eight hold some form of election for their highest courts, whether it is a partisan, nonpartisan or retention election in which justices face an up-or-down vote.

"I'm not even sure raising a million dollars makes a difference anymore when you look at the people who were successful in the Supreme Court races in Pennsylvania," said Judy Olson, a Superior Court judge who raised $500,000 in her unsuccessful bid as a Republican for the Pennsylvania Supreme Court.

All three seats in Pennsylvania were claimed by Democratic candidates who combined for nearly $10 million in campaign contributions, with a big chunk of the money coming from trial lawyers and labor unions. Democrats took control of the court and will hold a 5-2 majority when the new justices are seated in January.

Although it was rare to have three open seats, court races in several states next year could draw similar attention.

In Ohio, two seats on the seven-member court, both held by Republicans, are open because of mandatory age limits. Democratic-leaning groups might see an opening to cut into the current 6-1 Republican majority. Chief Justice Maureen O'Connor also will be on the ballot in November, although she is running unopposed.

Earlier this year, North Carolina lawmakers voted to allow retention elections in some cases for the state Supreme Court in an effort to reduce political rancor and the influx of campaign cash. Whether that will work as intended remains to be seen, as Justice Bob Edmunds comes before voters in an up-or-down vote next November.

If Edmunds loses, he could be replaced by another Republican because GOP Gov. Pat McCrory probably would get to name his replacement at the end of 2016.

Although the state Supreme Court election is nonpartisan, four of the seven justices are registered Republican.

Florida, Iowa, Kansas, Mississippi and Montana are among other states in which court elections could draw attention and outside money next year.

In 2014, the last major election year, 19 states held elections for their top courts. Spending exceeded a combined $34.5 million, with much of the money coming from special interests, according to a report by Justice at Stake, the Brennan Center for Justice and the National Institute on Money in State Politics.

The report noted the effect of the U.S. Supreme Court's 2010 ruling in the Citizens United case, which opened the door for corporations, unions and other interest groups to spend unlimited amounts as long as they do not call specifically for the election or defeat of a candidate.

In 2014, outside groups represented a higher percentage of all spending than ever before in judicial elections, or nearly a third of all money spent, according to the report.

An emerging player is the Republican State Leadership Committee, which spent roughly $3.7 million on state judicial races in eight states during the 2014 election. The group is dedicated to electing conservatives at all levels of state government and launched its Judicial Fairness Initiative to ensure that Republican-backed legislation would not be derailed by "an activist judicial branch," said Matt Walter, the group's president.

"Where we have elections, it's important for the voters to have a balanced flow of information so they can make a decision about what judges they want to have," Walter said.

He pointed to the group's efforts in 2014 on behalf of Illinois Supreme Court Justice Lloyd Karmeier, whose retention election had largely flown under the radar until about three weeks before Election Day.

That's when a $3 million spending battle broke out, according to the report by the watchdog group. Much of that money was linked to interests in a multibillion-dollar lawsuit before the court.

A political action committee formed by a group of plaintiffs' lawyers and firms spent $2 million campaigning against Karmeier and portraying him as partial to corporate interests. Walter said the Republican State Leadership Committee contributed about $1 million to help Karmeier, who ultimately won re-election.

The leadership committee has nearly 150,000 donors and expects to spend $40 million total during the current election cycle. How much of that will be dedicated to state judicial races has yet to be determined.

The influx of big money into their races and the process of campaign fundraising can present challenges for judges and judicial candidates.

In one case, the U.S. Supreme Court decided in 2009 that a West Virginia judge should have recused himself from considering a lawsuit involving a campaign donor who had spent $3 million to help him win.

Judges are governed by codes of judicial conduct that offer detailed guidelines on maintaining impartiality and ethical standards. Some states, including Pennsylvania, also ban judicial candidates from directly asking for campaign contributions in an effort to insulate judges. There also is an effort by Pennsylvania lawmakers to replace elections with a merit selection process.

Judge David Wecht, one of the Democrats who won a seat on the Pennsylvania Supreme Court, said he believes being transparent and recusing himself from certain cases demonstrates his independence and builds trust with the public. Over his career, he said he has recused himself from several cases to avoid even an appearance of a conflict of interest and sees no "perfect system" for choosing judges.

"In Pennsylvania, at least the people who are elected to the judicial positions have had to get out there and meet people and get out there and know the state," Wecht said. "There is something to be said for that, and there is also an element of condescension, when in effect somebody says you aren't smart enough to pick your own judge and we're going to do it for you."

___

Associated Press writers Peter Jackson in Harrisburg, Pennsylvania; Gary Robertson in Raleigh, North Carolina; and Andrew Welsh-Huggins in Columbus, Ohio, contributed to this report.

___

Follow Christina Almeida Cassidy on Twitter: http://twitter.com/AP_Christina.