The first Kay Dingwall knew of the potential for a media storm to hit her school was when she received a call from the Metropolitan Police just after 8am one morning in March 2009.
The headteacher of Cleveden Secondary in Glasgow was told that officers were preparing to arrest her principal pastoral care teacher, Kerr Wright, who had been at the school for 15 years, for suspected sexual offences against a child.
"I was absolutely stunned by the allegation. This was a popular member of staff who was a personal friend to many of his colleagues," said Mrs Dingwall, now head of Knightswood Secondary in Glasgow.
"However, you instantly have to put any such considerations aside. The priority was to deal with the situation in a way which minimised the potential impact on pupils, staff and the wider school community. Working closely with the education directorate and the council's media office, that's what we set out to do."
Wright was away that day on a training course. The police arrested him at his house before he was due to return to school.
"The key to preventing this becoming a media frenzy lay in the fact that for several days only myself, my depute and a handful of people in the education department knew anything about it at all," Mrs Dingwall said.
"So we had time to plan exactly what, when and how we wanted to tell people what had happened. We had letters drafted up for parents and the wording of briefings sorted out for staff and for each individual year group well in advance.
"As a result, by the time the information did become public, we had done everything possible in terms of minimising its impact. It would have been exceedingly difficult if the media had been on to the story immediately."
Once the interest had died down (Wright was later jailed), Mrs Dingwall gave presentations to groups of heads from all educational sectors across Glasgow on her experience. The events marked the launch of the city's guidelines on managing critical incidents.
Teachers behaving inappropriately are always newsworthy. Occasionally, their notoriety enables the media to have more than one bite of the cherry.
In 2005, the spotlight turned on Aberdeen's Kincorth Academy when head of music John Forrester resigned and set up home with one of his 16-year-old pupils.
That story continues to have repercussions eight years later. The couple settled in Aberdeenshire and had two children, and last year Mr Forrester was elected secretary of their local school's parent teacher council.
That new "news" put the local school, Auchenblae Primary, through its own 15 minutes of unsolicited media fame.
In the above cases, the situation was managed by competent headteachers with the backing of supportive and well-prepared local authorities.
Occasionally, though, it is the headteacher who becomes the focus of the attention.
In 2009 the former head of Auchmuty High in Glenrothes, David Wilson, was jailed after being found with nearly 3,000 pornographic images of children.
That case demonstrates why it is important that a school's entire senior management team - not just the headteacher - is well versed in how to deal with the media and a contributor to and custodian of any pre-prepared crisis management plan.
It is only in a small minority of cases that negative stories involving schools stem from a decision the headteacher or a member of staff has either made or is perceived to have made.
We've all seen the stories. Pupils wearing safety goggles to play conkers (see panel, page 13), the making of Mother's Day cards being scrapped to avoid upsetting motherless pupils; nativity plays being cancelled to avoid offending families of other faiths, and so on.
These stories may be entirely true. Sometimes, though, the media is guilty of disseminating a version of events to suit their own ends which significantly blurs the facts.
In 2002, a tabloid ran a series of articles about student William "Junior" Mann allegedly being sent home from the Christmas disco at Glasgow's Nitshill Primary by the headteacher for not being dressed smartly enough.
The school told the journalist that while the head had indeed phoned his carer to ask whether she could bring him a different pair of trousers (the school had made clear for weeks beforehand that dress code for the disco was "smart"), she had responded angrily and instructed that he be sent home. That information was never published.
"Banned for not having a suit at age 10," screamed the headline, with a story about Junior being "heartbroken" at having been "kicked out" of the disco for not wearing "a kilt or suit".
It got worse. It turned into a series of stories. The tabloid took him to John Lewis and kitted him out in a suit ("New look suits disco ban Junior"). Then it hired a stretch limo and picked up Junior and his sister for a trip which included skating in George Square, a visit to Santa's Kingdom, the SECC Christmas Carnival and a party meal at McDonald's, complete with gifts ("Little Mann's big day").
What had initially been a simple phone call had turned into every headteacher's nightmare.
At least in that case the headteacher was involved, however distorted the portrayal. What, though, if the decision is made by the local authority rather than the school itself?
The most obvious recent example was the story involving Martha Payne, the Lochgilphead Primary pupil who set up her NeverSeconds blog to comment on her school lunches. When Argyll and Bute Council decided to prevent her from photographing her food, the world's media had a feeding frenzy.
In January 2008, a number of firearms - along with clothing including balaclavas - was found in a gym cupboard at the now-closed Blairtummock Primary in Glasgow.
The 130 pupils were immediately sent home and a police investigation began. Police soon discovered the guns were replicas, but their inquiry meant that the school was unable to explain the situation to parents for four days.
Naturally, some parents had used that time to vent their anger in the local and national media at the perceived lack of information coming from the school.
Former Blairtummock head Shelagh Delahunt, now head at the city's Haghill Park Primary, said it was a steep learning curve.
"I'd received media training as part of my CPD, but that was the first time I'd ever had to deal with the media descending on the school," she added.
"The rumours spread with incredible speed. Within what seemed like minutes we were being contacted and asked whether it was true I'd been shot, whether we were in the midst of another Dunblane and so on.
"One of the things I found most difficult was the fact that my hands were tied regarding what I could tell the parents. I was inundated with parents asking how I could guarantee their child's safety. For several days I couldn't give them the detail they wanted, despite writing to all parents to give them what information I could. It was a difficult time.
"On the plus side, my media training and the support I received during that time proved invaluable. It's hard to overstate how important it is to ensure you know what to do and where to turn if things do suddenly kick off at your school."
Increasingly, the message is that the more media-savvy headteachers, senior managers and their local authorities are, the better.
Ken Cunningham, general secretary of School Leaders Scotland, said: "SLS has long recognised the influence of media in the life of schools for good and bad and offers both training for such as well as immediate pastoral support for members in the midst of crises.
"As someone has well said, `By the time you hear the thunder, it's too late to build the ark!' Many local authorities have excellent media departments to support staff and schools when such issues arise."
What about those headteachers who do not have the guidance and advice of a local authority communications team?
In January this year, the body of Anna Johnson, a 15-year-old student at the independent Morrison's Academy in Crieff, was found underneath a bridge on the M9.
Soon afterwards the school's headteacher, Simon Pengelley, issued a brief statement confirming that police had informed the school of Anna's death and expressing the school community's shock and sadness.
When - in spite of Anna's father issuing a supportive statement about the school - allegations surfaced regarding possible bullying, he put out another to confirm that Morrison's would be carrying out its own investigation as well as supporting the police in theirs.
Mr Pengelley had previously attended a media-handling course run by SLS. One of its key messages was the importance of carefully prepared public statements.
"The availability of external, neutral advice is also critical. Being in the middle of such a distressing and emotive situation is difficult on many levels, and it's very important to be able to draw on the skills and expertise of people who are in some way removed from it," said Mr Pengelley.
It's not all challenging, though. The media is often a force for good in terms of letting communities know what their local schools are up to, as AHDS general secretary Greg Dempster stressed.
"The vast majority of the media interaction which leaders of Scotland's nursery, primary and ASN schools have is positive. There are fantastic things happening in establishments across the country, and the local media in particular is usually very good at running school success stories," he said.
"Very occasionally, however, there is the potential for less positive coverage. Today's school leaders are aware of the evolving challenges posed by the media and - through a combination of training and, in the vast majority of cases, support from media professionals within local authorities - are usually well placed to minimise any potentially negative impact."
New technologies present significant challenges in terms of managing a crisis. Social networking and media sharing websites, coupled with the boom in smartphone ownership, means anyone - including students - can potentially now "report" on a breaking situation in a school before the traditional media are even aware of it.
It's a sobering thought that every school in Scotland is already swarming with potential journalists. But this new technology can also prove a critical tool for any school finding itself in the media spotlight.
Aberdeenshire Council's head of customer communication and improvement, Kate Bond, is also chair of the National Communications Group Scotland and executive member of LGcomms, which works to raise the standard of communications in local government.
"New technology like social media gives us greater opportunities to respond and engage with audiences directly," she said.
"It's about establishing yourself as a trusted point of information, a source that people will go to to get a response. If you have built up a strong online following before an incident or crisis, people will be more likely to trust that source for a range of more difficult messages. The challenge is in meeting their expectations by responding accurately and quickly."
Maureen McKenna, Glasgow City Council's executive director of education, says heads - supported and advised by their council's media office - should be confident and comfortable in their relationships with the media in all its forms.
"A large proportion of the general public get their information through that media, so it's vital that our schools make the most of the opportunities it presents to disseminate positive news, and also get it right when the news is not so good," she said.
"In the vast majority of cases, potentially negative news is not the fault of either the school or the head. Dealing with such situations badly, though, is always avoidable.
"Having the necessary knowledge, confidence and support to cope with the demands of the media during a crisis can make the difference between a school emerging relatively unscathed and it suffering significant and potentially long-term damage to its reputation and its relationships with pupils, parents, staff and the wider community."
10 TIPS ON HOW TO DEAL WITH THE MEDIA DURING A CRISIS
1. Be prepared. Don't wait until you're already in a crisis to set out who deals with the media and how.
2. Use professional expertise. Always work in partnership with your corporate communications team (if you have one).
3. Be quick. Issue a statement to the media, however short, as fast as possible. Your school may be judged as much on the speed of its public response as on the crisis itself.
4. Keep it simple. Decide what you want to say and say it as concisely and in as jargon-free a way as possible.
5. Keep it factual. Limit statements to what you know - avoid speculation on what may have happened or what you may do in response.
6. Keep your school community informed. Make sure whatever you issue to the media is simultaneously sent to parentsput on your school website, social media pages etc. Parents, staff and pupils should not be getting information from the school through the media.
7. Stick to your official statement(s). Don't get drawn into a dialogue with journalists.
8. Be honest. Never try to "cover up" the severity of a situation through fear of negative publicity. The truth will one day come out, along with your attempts to hide it.
9. Understand that there is no such thing as "off the record" during a crisis. Journalists are trying to find new angles, and exclusive information - whether intended to be confidential or not - is like gold dust.
10. Don't alienate the media. You're already in a crisis - don't make it worse by making journalists angry. They will accept that you're not able to issue more information if you let them know in a polite and courteous manner.
A BONKERS CASE OF CONKERS
One former head who knew how to use the press for his own ends was Shaun Halfpenny, who ran Cummersdale Primary near Carlisle until his retirement in 2005. But on one famous occasion his dealings with the press backfired. The story he conjured has almost passed into legend; he was the head who reportedly "forced" his pupils to wear safety goggles when playing conkers.
The tale was referred to in a speech by David Cameron just months before he became prime minister as an example of how health-and-safety culture was "stultifying" the country.
It started in 2004 after a group of Mr Halfpenny's students had discovered horse chestnuts while on a school trip, but were unsure of how to play conkers. The head said he would show them how, but they would have to wear goggles because of health and safety. While many came out in favour of this safety measure, Mr Halfpenny insists his instruction was a joke.
"I was jesting, but the next day they were all playing conkers with safety goggles on," he laughs. "We had a visitor to the school who thought it was hilarious and said I should get in touch with the local rag to do it as a story."
Mr Halfpenny had a good relationship with his local paper, the Carlisle Times amp; Star, and it ran the piece.
"I received a call the next day. It was someone saying they were from Radio 4," the head explains.
The story had ended up on the front page of The Sun, knocking the war in Iraq off it for the first time in days. Soon, seven TV crews had parked in the school's yard to cover the story.
"I think the tabloids wanted to pluck whatever story they could, saying I had banned conkers unless goggles were worn and they weren't interested in the truth. They just wanted to describe me as bonkers."
What had started as a head's attempt to poke fun at health and safety laws ended up as a global news story with him being depicted as an overzealous "nutcase". But he is quick to defend the courting of the press, as long as people are aware that playing with fire sometimes means getting burned.