LOS ANGELES - Less than eight months after an epic meltdown that led to a court taking away her children, Britney Spears is reclaiming her role as a mother -- to the point where she may be with her boys nearly half the time.

Attorneys for the pop singer and ex-husband Kevin Federline reached an agreement Friday that allows Spears three visits a week from Sean Preston and Jayden James, including two overnights with potential for more. If all goes well, she could have 2-year-old Sean Preston and 1-year-old Jayden James roughly 40 percent of the time, her attorney, Laura Wasser, told The Associated Press.

The agreement not only increases Spears' time with her sons, but also removed need for a trial scheduled for next month to resolve lingering visitation and financial issues.

The positive change on the home front comes as Spears' career also seems to be rebounding. She is spending the summer working on a new album, recently taped an appearance that will be shown during Madonna's upcoming tour, and made a couple of well-received cameos on the television show "How I Met Your Mother" earlier this year.

Spears' increased involvement in her boys' lives was almost unimaginable in January, when the 26-year-old twice had to be removed from her home by authorities and was committed to a psychiatric ward.

Federline was awarded full custody shortly thereafter and Spears did not see her sons for nearly two months.

Since then, Spears has gradually been granted longer visits. In late June, she was was alotted one overnight visit a week with her sons, Wasser said.

Spears will gain more overnight visits between now and the end of the year, Wasser said. The agreement also includes a "slight increase" in child support payments to Federline and covers his attorney's fees.

"The fact is, it's a win for the family," Wasser said.

Federline's attorney, Mark Kaplan, whose fees have been paid by Spears and have been the subject of disputes, also lauded the outcome Friday.

"This has been a long ordeal and to have that over is something that makes him extremely happy," Kaplan said in a brief statement after the courthouse meeting.

The couple were married in 2004 and finalized their divorce last July and have wrangling over custody issues for several months since then.

Kaplan declined to discuss specifics of the agreement, which still needs to be filed to Los Angeles Superior Court Commissioner Scott Gordon. Gordon met with Wasser and Kaplan for more than 40 minutes Friday, but did not issue any rulings or take up the case in open court.

Friday's agreement is fairly typical of custody disputes even if the parties are not, said Charlotte Goldberg, a family law professor at Loyola Law School in Los Angeles.

"The courts do like parties to agree to custody rather than go through a trial," she said.

A trial would have almost certainly garnered throngs of reporters and photographers, which Goldberg said could have stymied Spears' progress.

"I think for Britney's sake, it would be better to avoid more publicity," Goldberg said.

The scene Friday was in stark contrast to previous court appearances, when Spears has been mobbed by photographers and in one incident, set foot in the courthouse in cocktail party attire only to suddenly leave before attending her hearing.

The cameras came Friday. Spears did not.

Wasser said Spears has been motivated in recent months by her children and re-establishing her career, which eight months ago seemed to be as teetering as her personal life.

Her legal woes, however, are not over.

A hearing has been scheduled for July 31 about whether her father, James Spears, will continue to control her personal and financial affairs. Once that is resolved, a misdemeanor driving without a license charge can dealt with.

But Wasser acknowledged that Spears has come a long way in eight months.

"The difference from the beginning of this year to now is astonishing," Wasser said