A bank manager who pulled a gun on an ice cream seller as he tried to rob him of his takings - then sent him a Facebook message saying sorry - was jailed for the offence today.

The Facebook message Ian Hamilton, 30, sent to his victim, proved to be his undoing, as he admitted he was responsible and revealed his identity.

And today Hamilton was beginning a 26-month jail term after he was sentenced for the botched robbery. 

Hamilton, who was understood to be making around £26,000 in his job as an accounts manager with TSB, approached the ice cream van as it was parked in the Pennyburn area of Kilwinning, Ayrshire, at 3.30pm on July 3 last year.

Hamilton asked for "20 fags" while holding his hand behind his back, then pulled the gun out and said: "You're getting robbed."

Despite having the gun pointed in his face, the man remained ice-cool, grabbed hold of the weapon and tried to wrestle it from Hamilton's grasp while the panicked would-be robber repeatedly shouted: "Let go!"

Hamilton managed to keep hold of the weapon and made off, while the van drove away from the scene and called police.

An investigation was launched but it was not clear who was responsible as the victim only recognised Hamilton as someone local to the area and did not know him personally or know his name.

Hamilton was found asleep face-down on top of his bed, with the gun next to him, later that day by his girlfriend.

Never having seen the weapon before, she put it in the kitchen cupboard.

He had stolen the weapon, which was a ball-bearing gun, from his friend that morning during a drinking session.

But a sheepish Hamilton contacted his victim via Facebook the following morning to apologise - revealing his identity and admitting what he'd done.

His message, which he sent to the business page and read: "Alright bud. Just wanted to say soz for pointing that gun at you, it was only a toy.

"It's a bit daft, I know, but I had a bevvy in me and I thought it was funny.

"I know it's not, though.

"I've got rid of it now so it doesn't cause any problems."

The man was able to inform police probing the attempted robbery of the message and Hamilton was arrested over the offence.

The case was originally prosecuted at Kilmarnock Sheriff Court but was transferred to Dumbarton Sheriff Court to be heard.

Last month Hamilton pleaded guilty to a charge of assault with intent to rob and the case was adjourned for background reports. 

When he returned to the dock today defence solicitor Fraser Alexander said: "His position is that this was a joke. 

"He was extremely under the influence of alcohol. 

"The position is that he was drinking, the night before, heavily, woke the following morning and continued to drink, which resulted in him being extremely intoxicated. 

"He does not seek to use it as an excuse for his conduct - he recognises his consumption of alcohol is his problem.

"This is not the behaviour one would expect from a man that comes from the background Mr Hamilton comes from."

He said Hamilton had always worked, since leaving school at 16, and would be willing and able to carry out unpaid work as part of a Community Payback Order and be made the subject of a Restriction of Liberty Order - being tagged and subjected to house arrest every night. 

He added: "He lost his employment as a direct result of a plea of guilty in relation to this matter. 

"He has already lost what was a good job, with prospects, through his own foolish actions."

But Sheriff Simon Pender ruled the only appropriate sentence for Hamilton's crime was to also make him lose his liberty - and jailed him for 26 months, reduced from 30 because he admitted his guilt. 

Hamilton, of Dalgarrock, Pennyburn, Kilwinning, Ayrshire, could have been caged for five years for the offence.