Media playback is unsupported on your device Media caption The county jail in Virginia Beach granted the BBC access to report on the difficulties of dealing with mentally ill inmates

Treating mental illness is always a challenge, but in the US, after decades of declining funding for mental health care, the burden is increasingly falling on the prison system. The BBC was granted access to a local jail in the state of Virginia to see first-hand how staff and inmates are coping.

In Virginia Beach, a city on America's east coast, 260 of the roughly 1,400 inmates in the county jail are being treated for mental illnesses.

The local sheriff, Ken Stolle, told the BBC that most weeks, he has more inmates in his jail suffering from mental illnesses than the state's system has beds.

That leaves Mr Stolle feeling as though he's in charge of the default mental institution for the area.

"Most sheriffs that I know feel like this is a problem that needs to be addressed by the state and that we shouldn't be the provider of last resort. That's what we feel like we are right now, " he says.

How it happened In the 1960s after shocking tales of filthy, abusive mental asylums surfaced, well-intentioned government officials decided patients should be freed and treated in a small, community settings The process was called "deinstitutionalization". Many state mental hospitals were shut down; the number of available beds dramatically reduced. But financially-squeezed local authorities were ill-equipped to handle the change. Mental healthcare became all but impossible to access. Many former patients ended up homeless, stigmatized and in poverty. And, throughout the country, many ended up in jail, mostly for minor offences like trespassing or indecent exposure.

"If the system fails to catch these people in a safety net, they end up in the jails."

The jail has its fair share of rowdy, unruly criminals. But it's the mentally ill inmates who Mr Stolle loses sleep over.

"Ninety percent of my assaults on deputies last year were committed by mentally ill inmates," Mr Stolle told the BBC.

"I've got a problem there in the security and the safety for my deputies."

Some inmates have thrown excrement and urine at staff, others rush the doors when they are opened, injuring staff in the process.

But Mr Stolle also worries about the harm these inmates do to themselves. The jail's small medical centre sees a shocking array of conditions.

One of the nurses, Nancy Brulet, told the BBC she's treated people who have tried to hang themselves and who have cut or otherwise harmed themselves.

Recently, Ms Brulet saw one man who had bitten a chunk of flesh out of his arm.

"He was very sad and very depressed," she said. "He went to the mental hospital for a while. He got medicated and he's back and he's doing much better."

Being sent to a mental hospital is a relatively rare occurrence, not just because of the lack of beds.

Isolation and restraints

Under US law, it's very difficult for the mentally ill to be sent to hospitals without their consent. When sick people needing medical help commit crimes, judges can really only sentence them to jail time rather than hospitals.

Image caption One troubled inmate was strapped to a restraining chair for 17 days

The jails are mostly overcrowded, under-funded and unprepared to provide the sort of care those perpetrators need to get well, and to prevent them from re-offending.

Amid budget constraints, the Virginia Beach jail has a psychiatrist visit for just 12 hours each week.

In the absence of medical professionals, the jail's methods of coping are far from ideal.

If the mentally ill inmates become suicidal or agitated, it is mostly up to the guards - who have received basic crisis training - to talk them down.

If offenders are violently aggressive, they can be strapped to crude restraining chairs, sometimes for days or weeks at a time.

The longest staff can recall an inmate being put in a restraining chair is 17 days.

If they are deemed a danger to themselves or others, the inmates are placed in tiny medical isolation cells.

These concrete cells are dank and hot, with blacked out windows and thin mattresses on the floor. Inmates are stripped of their clothes and given paper gowns so they have no materials they can use to hang themselves.

Some troubled inmates spend their entire stay in medical isolation. One inmate in the Virginia Beach jail has been walking in circles in his cell for weeks, leaving a noticeable trail of dead skin cells on the rough concrete floor.

"In my opinion, it's not a good area for somebody with mental health issues," Mr Stolle says of the isolation cells.

"I think we make the problems worse, but under the resources that we have, this is the only option."

Mr Stolle allowed us to speak with one mentally ill inmate who had been put in an isolation cell after assaulting a guard. To protect his identity, we will call him William.

William, whose hands and feet were shackled during the interview, has been suffering with mental illness over 10 years. He was bed-ridden for a period and has been in and out of jail for crimes stemming from his delusions.

He told the BBC that if he had been in isolation for any longer he "wouldn't have made it".

"There's no therapeutic benefit at all, in any way shape or form to those units," he said.

'Not a hospital'

Image caption Ms Thomson says that many mentally ill inmates are in and out of jail

It's no surprise William feels that way. The isolation cells are being used to house sick people now, but they were never intended for therapeutic purposes. They were built to handle criminals.

Carol Hepburn, a social worker at the jail, thinks they're coping as well as they can.

"We are limited. This is not a treatment facility, this is a correctional facility, so there is no parallel between us and a hospital," Ms Hepburn says.

The problems at the Virginia Beach jail aren't unique. Sheriff Stolle says his counterparts across the country are all struggling with the same problems.

The Commanding Officer of Corrections, Victoria Thomson, likened the jail to a revolving door, saying that in her 19 years there she has seen the same mentally ill offenders over and over.

Many don't understand what they've done or why they are there.

At least while they're inside his jail the sheriff can ensure they're being fed, clothed, and are taking the right medications.

But he has no control over their care when they leave. They just walk out of the front door, some without homes, families or doctors to go to.

Many offend again because they've stopped taking their medications.

Both Ms Thomson and Mr Stolle say improved access to mental health services in the community and follow up care to help ex-prisoners stay on their meds and out of jail would help with repeat offenders.

But until appropriate care is available on the outside, the sheriff and his staff will have to keep catching those who fall through the cracks.