Opening night at the Montgomery County Agricultural Fair in Gaithersburg last Friday was a study in contrasts.

There was the tent featuring a 71/2-foot-long boar weighing 1,000 pounds. There were four piglets racing round a landscaped track in pursuit of an Oreo cookie at the finish line. There was the ubiquitous smell of cattle and the sounds of lambs being bedded down for the night.

But there were also backyard deck merchants, a rabbit barn and a karaoke stage. Jeff Leaman, of Screamin' Leaman LLC in Gaithersburg, demonstrated his new game, Viking King Kubb (that last word is pronounced KOOB), a 1,000-year-old Swedish lawn game that he hopes will become the county's new croquet.

"My wife's Swedish. I played this over there three years ago and couldn't find it in the U.S.," he said. His booth "is a first time ever adventure," he said, an effort to sell, at $40 each, the wooden games he makes.

It's a different county fair these days. As Montgomery, Frederick and other rapidly urbanizing counties turn from farm to bedroom communities, county fair organizers have found that they must adjust or go bust. (Montgomery's fair ends Saturday, while Frederick's is Sept. 17-25.)

The quest has spawned a burst of creativity -- and creative tension -- between farm-oriented folks, who want county fairs to continue as an agricultural event, and suburbanite newcomers, who may not necessarily understand, or be interested in, the fine points of livestock judging.

Gene Walker is a part-time farmer and board vice president of the Montgomery County Agricultural Center Inc., a nonprofit group that stages the Montgomery County Agricultural Fair. He says changes have been "minimal to none" in the fair's 56 years.

"We don't like to change. One of our goals is to educate the public as to how agriculture functions," Walker said. "We don't go at it on the boutique end, that kind of politically correct stuff."

Yet even he acknowledges that accommodating the fair's greater variety of patrons "is a matter of survival. It costs a lot of money to put this on. If we have a year we're not in the red, we're feeling pretty good about it."

As a break-even operation run mostly by volunteers, the fair depends on gate admissions to maintain the fairgrounds and buildings, book entertainment and hire ride and attractions vendors. That has led to a slow, negotiated evolution that has retained the fair's classic elements while introducing a few twists: a monarch butterfly exhibit, technology-oriented shows, pet and backyard livestock competitions and cooperative programs with local schools.

A potential new offering weighing on Walker, who also serves as the Montgomery fair's horse superintendent, is an equestrian show. Not many farmers want their agricultural fair inundated with horse people. But riding horses now outnumber cattle 2-to-1 in Montgomery County. A horse show could draw Maryland's fastest-growing segment of livestock owners, plus plenty of spectators. Even cow-friendly Frederick will introduce a two-day equine exposition at its fair this year.

Walker plans to pursue one, but "let's not talk about that too much," he said.

Montgomery's 59-acre fairgrounds are a rural island in an ever-expanding suburbia. The midway overlooks a Chinese fast-food place and a Borders bookstore. The sound of traffic from Route 355 blends with the sound of livestock.

Riding in a golf cart past the livestock barns, Randy Fox, executive director of the Montgomery fair, explained its newer features: the home-brewed beer competition; a comedy cooking show; sandboxes filled with soybeans and corn for kids to play in; a toilet-decorating contest (most people turn them into planters); and Old MacDonald's Farm, which gives many suburban children their first look at a Brahma bull or a bison. The number of small-animal entries has doubled in the past several years -- the rabbit barn was full this year.

"Agriculture is who we are and what we're about. But at the same time we're looking at trends that will attract more patrons," Fox said.

Along with county fairs across the nation, county fairs in this region have weathered plenty in recent years. The Sept. 11, 2001, terrorist attacks fell in the middle of fair season. In 2002 it was drought. And last year it was Hurricane Isabel. The disasters of the past three years "have had a direct financial impact on us," said Becky Brashear, executive assistant with the Frederick fair.

Locally, those problems are compounded by a more basic threat. According to the U.S. Department of Agriculture, there are only 526 farms left in Montgomery County, down from 667 in 1982 despite efforts to protect agricultural land. Although Frederick County remains the state's largest producer of dairy products, it has lost nearly half its dairy farms since 1990, according to the University of Maryland Cooperative Extension Office. U.S. Department of Agriculture estimates show that Frederick County has lost about 15,000 acres of farmland over the past decade.

The Great Frederick Fair, one of the region's largest, historically attracts about 250,000 people, compared with about 225,000 in Montgomery. But Frederick's paying admissions have dropped sharply in the past three years. "Your expenses are the same if one or 500,000 come through the gate," Brashear said.

The fair and its sponsor, the nonprofit Frederick County Agriculture Society, have had to come up with new ways to attract patrons. "We have a progressive staff and a supportive board, and that's the key," Brashear said. "We're doing a lot to partner with the school system and young participants. We need to develop more and more programs that kids and young folks are interested in these days. That's our future."

This year, the fair and Pizza Hut are sponsoring "Let's Grow a Pizza," where third-grade students -- who have already prepared for the activity in school -- visit several stations at the fair to gather the ingredients for making their own pizzas, along with information on where each of those ingredients comes from. Kindergartners through second-grade students can create a Spuddy Buddy, a decorated potato a la Mr. Potato Head that will serve as their entree into vegetable judging. (Details are available at www.thegreatfrederickfair.com.) Spuddy Buddy participants are also given a card that directs them to fair exhibits focusing on the five senses -- taste, for example, takes them to the preserves judging in the Farm and Garden Building. For middle and high school students, there's a multimedia program, with competitions in videography, feature photography and journalism, Web design and PowerPoint presentations.

But perhaps the Equine Expo has the greatest potential to attract more fairgoers.

"The equine industry is just exploding," Brashear said. Though Frederick is still Maryland's top-producing dairy county, horses there now rival dairy cows in population. On Sept. 23, the focus is on "light," or riding-oriented breeds; on Sept. 24, the event features draft horses -- that's in addition to the traditional draft horse and mule show, scheduled this year for Sept. 19.

The fair isn't all livestock and rides: Lee LeCaptain of St. Cloud, Fla., saws through a log Saturday during a lumberjack demonstration. LeCaptain performs at more than 30 county and state fairs nationwide. The rides at the Montgomery County Agricultural Fair run through Saturday. Below, from left, Eddie Gregg, Tom McClain and Bob Allnutt talk about tractors. Bottom, Patrick Thompson of Clarksville catches some shut-eye.Saturday's rainy forecast didn't deter the crowd at the fairgrounds, but regional and national events in recent years have hurt gate receipts. Below, Jordan Rupard, 12, waits to perform in an agility competition with her llama, Isabella.A mother and daughter stroll through a sheep barn at the Montgomery County Agricultural Fair, which has increased its animal exhibits.