In nightclubs and strip joints across the country, the song of the moment is Jamie Foxx's "Blame It (On the Alcohol)," a leering tale of bad boys, well, behaving badly. The hit certainly inspired a few smirks in Hollywood, where Foxx has become a respected star but also has a reputation for playing as hard as he works. So last year, on the set of " The Soloist," when there were whispers that the star was in a volatile place, many people assumed it was because he was having too much fun.

They could not have been more wrong, according to Foxx.

"I was in a bad place because I felt like I might be literally losing my mind," the Oscar-winning actor said of his immersion into the role of Nathaniel Ayers, a homeless man and former music prodigy lost in the mad muttering and slippery reality of schizophrenia. The film, opening Friday, explores the bond between the real-life Ayers and Los Angeles Times columnist Steve Lopez (portrayed by Robert Downey Jr.) and shines a compassionate light onto the indigent street life in downtown Los Angeles. But for Foxx, the subject matter became unsettling during the shoot because of very specific and personal resonance with his past.

"There's sort of a private thing for me, something I haven't really told many people about," Foxx said recently, sitting in a quiet corner of a Beverly Hills restaurant and talking fast. "When I was 18, somebody slipped something in my drink. And it ripped me apart. I had to go to the hospital. I mean, I was gone, it was the kind of trip that . . . you know you're losing your mind. I kept thinking, 'I can't live like this.' It didn't go away, either -- for 11 months, I had flashbacks. . . . "

Foxx looked rattled as he explained all of this, which is unusual considering his typical swagger and chiseled cool both on stage and in reputation. The 41-year-old is one of the biggest stars in America if you add it all up: His film success, the surprisingly potent music career, his own satellite radio channel and his persistent reputation in comedy, much of it earned with his popular namesake television show before he moved on in 2001.

On screen, Foxx has rarely looked truly vulnerable, even in his role as the ferociously talented and bitterly addicted Ray Charles in 2004's " Ray," which won him an Academy Award. But in the "The Soloist," there are points where an unsentimental camera lingers on his stricken face and the man on the screen seems very much like a person doubting the contents of his own brainpan. Now, if he is speaking without exaggeration, that is precisely what he brought to the role.

"I thought about just walking away from this movie," said Foxx, who suffered from panic attacks and bouts of paranoia during filming. Instead of bolting, he visited with psychiatrists, turned for help to the film's director, Joe Wright (" Atonement," "Pride & Prejudice"), and also educated himself on the mental-health realities versus the vaporous fears he felt as he studied Ayers in his element.

"I had gone and watched Nathaniel, I had a little bit of a disguise and I spent time following him and studying him when he didn't know I was there, and as I was dissecting and downloading, I got really worried, I felt all these things," Foxx said. "I went to a psychiatrist and I actually asked, 'Can I catch schizophrenia?' Now I know you can't, but I also knew I had this thing happen to me before, and it felt like it was going to happen again. . . . "

Actors are, by their nature, drawn to drama and all that goes with it, so a skeptic might wonder if Foxx is goosing his account to promote his film or slipping a bit into the voice of a fabulist. (He also inspires a roll of the eyes when he says things such as "Well, this one time I took too many energy pills" when asked about mistakes he's made or what he views as the public's misconceptions about his personal character.) But that's not the case, according to director Wright, who spoke in somber tones about the wrenching ordeal he watched the actor endure.

"First of all, the Jamie that I got to know is completely opposite to the public perception of who Jamie Foxx is, which is based on an image in comedy and music that he has created," the British filmmaker said. "That's an alter ego created as protection, and its wall of artifice is 6 feet deep. He is much more fragile than hisalter ego. In the making of this film, I felt I had a first priority to be a safety net for him. We all came to see the risk he was at -- or the risk as he felt it. We weren't going to lose him into that dark hole."

Foxx said Wright and costar Downey (who, of course, spent years sliding down the banisters of 12-step programs) did their best to help as Foxx tried to navigate choppy waters. But it soon became clear to Foxx that the problems he was having weren't a secret as filming began in early 2008. The actor acknowledged that Steven Spielberg, who had a vested interest in "The Soloist" through DreamWorks SKG, approached Foxx at a party with the careful diction of a hostage negotiator. The filmmaker and mogul told Foxx that movies about the mind can take an unexpected toll and that the actor shouldn't be afraid to seek help. All Foxx could think about was the symptoms that gave him away: "Does it show? People can tell?"

A complicated man

It may be an indelicate analogy considering the grim mental-health issues raised by "The Soloist," but Foxx's career has a split personality. The man who asked for a psychiatrist to be on call while he plumbed the depths of a scabby, heart-wrenching film role is also the same guy who used his satellite comedy show last week for a cringe-inducing attack on young Miley Cyrus in which he suggested she smoke crack, make a sex tape with her father and "catch chlamydia from a bicycle seat." (He later apologized to Cyrus during a "Tonight Show" appearance.)

The star shrugged when asked which of his fans are getting the real Foxx. "Who I am depends on where you see me."

If it's hard to pin down Foxx, it's because the man is a master imitator of others. "He is a brilliant mimic," Wright said. "That may be his most obvious talent. But if he wasn't also a gifted actor, it would just be empty imitation, no performance underneath."

Foxx was born Eric Marlon Bishop in December 1967 in Linden, Texas, and while his specific career path was a vague and ever-changing one, it was clear he was going to be someone whom others cheered. He was a football star in high school and an accomplished musician before that, but later he came to realize that deep down he longed most for the approval of his birth parents, who gave him away before his first birthday. Raised by his maternal grandmother, he scored touchdowns on Friday nights, sang in a Baptist church on Sundays and played the role of restless young buck in between.

A few years ago, when talking about his youth, Foxx said he had no regrets that his birth parents were around but, because of their lifestyles and the family physics, were not truly invested in his day-to-day life; his doting grandmother was so influential and supportive in his life that he said it was easy to shrug off the missing-in-action parents. Now he says he has learned that you can ignore wounds but that doesn't help them heal.

"My dad lived 28 miles away and I was quarterback of my high school team, and this is in Texas where football matters, and he never came to a game," Foxx said. Later he added, "I always had everything going, tight, why wouldn't anybody want somebody like me?"

A scholarship took him west to California. Foxx hinted that there was some history in the family of mental illness, but he also insisted that it was some mystery psychotropic drug dropped into a cocktail that sent him skittering along the edge of his psyche.