WASHINGTON (AP) _ Anti-homosexual protests outside a gay murder victim's funeral: It sounds like a prescription for trouble, or at least a major lawsuit.

Court fights have raged for years over limits on picketing at abortion clinics. But when officials in Casper, Wyo., adopted a 50-foot no-protest zone for beating victim Matthew Shepard's funeral, even the demonstrators were pleased.

The goal was to protect public safety and ``the First Amendment rights of not only those protesting, but those wanting to go into the church,'' said Jack Stewart, the city attorney. ``We had to strike a balance, and frankly, it worked well.''

``It was an ideal arrangement,'' said the Rev. Fred Phelps, pastor of Westboro Baptist Church in Topeka, Kan. He and his followers engage in anti-homosexual picketing around the country with the central message: ``God hates fags.''

Phelps' group sent Stewart a letter of thanks after the Oct. 16 funeral.

Stewart said officials knew emotions would be high. Shepard had been pistol-whipped and tied to a fence in near-freezing temperatures. Police said robbery was the main motive, but he also was singled out because of his homosexuality.

Members of Phelps' church announced they would picket. So Stewart's office made a quick study of court rulings on previous attempts to limit anti-abortion and anti-homosexual protests.

``During that week we were living in a constitutional exam in law school,'' he said.

Here is what they found:

_In 1994, the Supreme Court upheld a 36-foot no-protest zone around a Florida abortion clinic but said protesters could not be barred from approaching patients within 300 feet of the clinic.

_Last year, the justices upheld a 15-foot buffer zone around New York abortion clinics but threw out a provision that required demonstrators to stay 15 feet away from clinic patients or staff members even outside that zone.

_In 1995, a federal judge threw out a Kansas law that prohibited picketing outside funerals, on the ground that it was too vague. State legislators later enacted a new law that spelled out the time period when such picketing is barred.

Stewart's office also studied a Topeka ordinance, enacted because of Phelps' previous protests, that prohibits picketing on public property within 50 feet of places where funerals are held.

The day before Shepard's funeral, the Casper City Council adopted the 50-foot no-protest zone for all funerals in the city. That kept the 17 protesters, and a group of counterprotesters, across the street from the Episcopal church.

Without the ordinance, ``I believe we would have had a lot of physical injury and a melee would have broken out,'' Stewart said.

Phelps said members of his group worried about their own safety and that the no-protest zone was ``altogether constitutional when the distance is so minuscule.''

Not everyone agrees.

There should be no ``funeral exception to the First Amendment,'' said Jay Sekulow, chief counsel of the American Center for Law and Justice. He represents anti-abortion protesters in challenging limits on demonstrations.

Sekulow said he strongly opposes anti-homosexual protests at funerals but contended they nonetheless are constitutionally protected free speech.

``I don't think that a speech-free zone (at a funeral) is any more constitutional than a buffer zone around an abortion clinic,'' Sekulow said.

Nonetheless, the Supreme Court has allowed some limits, and Stewart said Casper officials tried to follow the precedents.

``The city's mission in this was to ensure that the proper dignity and respect that happens in a funeral occurs, and at the same time to respect everybody's First Amendment rights,'' Stewart said.

___

EDITOR'S NOTE _ Laurie Asseo covers the Supreme Court and legal issues for The Associated Press.