Alabama police are outraged after photos of a detective beaten bloody by a suspect who stole his gun during a traffic stop were shared by witnesses and praised on social media.

The suspect, 34-year-old Janard Cunningham, is charged with attempted murder for allegedly assaulting the six-year veteran following a traffic stop at a shopping center in Roebuck around 11am Friday.

The plainclothes detective, who has not been identified, was taken to the hospital for treatment after the assault but has since been released and is recovering at home.

Scroll down for video

An Alabama man has been charged with attempted murder after allegedly beating a Birmingham police officer with his own gun until he didn't move

Birmingham police Sgt Heath Boackle, president of the Fraternal Order of Police took issue with those who those who sympathized with Cunningham. Above, a Facebook post of the officer's still body

Cunningham was taken into custody after the assault and is being held at Jefferson County Jail while police have released a second suspect who was apprehended without filing charges.

During the traffic stop, the detective pulled over Cunningham's SUV and told him to stay in the car while he waited for backup to arrive.

Cunningham is said to have fled the scene after beating the officer until he didn't move anymore. A second suspect was released without any charges

The suspect disobeyed that order, questioned why he had been stopped and then struck the officer in the head with his own weapon, AL.com reported.

The beating reportedly continued until the officer was no longer moving, with Cunningham then fleeing the scene.

While the detective was brought to the hospital, US Marshals and other officers tracked down the suspect and took him into custody.

After the arrest, photos of the bloodied detective began popping up on social media, with some commenters applauding what happened.

Other Alabama officers were angered by the outpouring of support for the suspect.

Birmingham police Sgt Heath Boackle, president of the Fraternal Order of Police, said: 'He was laying there lifeless and people were standing around taking pictures.

'If the tables were turned, and that was a suspect lying there, they would be rioting.'

Birmingham Police Chief AC Roper said that his department could have lost an officer at the shopping center (left) and was reminded of police death's in Tennessee and Louisiana

'The officer had every right to shoot him,' Boackle said.

The alleged attack followed strained relations between police and minorities that have been highlighted by recent high profile incidents involving the death of black men in incidents with authorities, according to Jefferson County District Attorney Brandon Falls.

Falls said: 'My understanding is, that he just, because of what was going on around the country he felt like had to act in an aggressive manner, did so, and unfortunately an officer was severely injured in the situation.'

Birmingham Police Chief AC Roper added: "This incident underscores the danger that our officers and others experience every day.

'I think about the recent murders of the Memphis and Shreveport police officers and recognize we too could have lost an officer today.

'We ask the community to keep this officer and his family in your thoughts and prayers.'

Cunningham previously pleaded guilty to an assault charge in 2006 and was also charged with attempted murder in 2004 before that case was dismissed, ABC 3340 reported.

He also has past convictions for robbery and unlawful breaking and entering a vehicle, according to WVTM 13.