function setAccColours(sBack, sFore)
{
    if (sBack != sFore)
    {
        setCookie("accBack", sBack);
        setCookie("accFore", sFore);
        loadAccOptions();
    }
}

function setLinkColour(sColour)
{
    setCookie("link", sColour);
    loadAccOptions();
}

function setVisitedColour(sColour)
{
    setCookie("visited", sColour);
    loadAccOptions();
}

function setAccFont(sFont)
{
    setCookie("accFont", sFont);
    loadAccOptions();
}

function setCookie(sCookie, value)
{
    expiredays = 30;
    expireDate = new Date();
    expireDate.setTime(expireDate.getTime() + (expiredays * 24 * 3600 * 1000));

    document.cookie = sCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + expireDate.toGMTString());
}

function getCookie(sCookie)
{
    // First we check to see if there is a cookie stored.
    // Otherwise the length of document.cookie would be zero.

    if (document.cookie.length > 0)
    {
        // Second we check to see if the cookie's name is stored in the
        // "document.cookie" object for the page.

        // Since more than one cookie can be set on a
        // single page it is possible that our cookie
        // is not present, even though the "document.cookie" object
        // is not just an empty text.
        // If our cookie name is not present the value -1 is stored
        // in the variable called "begin".

        begin = document.cookie.indexOf(sCookie + "=");
        if (begin != -1)
        {
            // Our cookie was set.
            // The value stored in the cookie is returned from the function.

            begin += sCookie.length + 1;
            end = document.cookie.indexOf(";", begin);
            if (end == -1)
                end = document.cookie.length;
            return unescape(document.cookie.substring(begin, end));
        }
    }

    return null;
}

function loadAccOptions()
{
    sFont = getCookie("accFont");
    if (sFont != null)
        document.body.style.fontFamily = sFont;

    sBack = getCookie("accBack");
    sFore = getCookie("accFore");
    if (sBack != null && sFore != null)
    {
        document.body.style.backgroundColor = sBack;
        document.body.style.color = sFore;
    }

    sLink = getCookie("link");
    if (sLink != null)
        document.linkColor = sLink;

    sVisited = getCookie("visited");
    if (sVisited != null)
        document.vlinkColor = sVisited;
}

var textSize = 100;
var minTextSize = 100;
var maxTextSize = 200;
var textSizeInc = 25;

function accToolbar()
{
    document.write("<div style=\"position: fixed; right: 6px; top: 2px; z-index: 1;\">");
    accToolbarButton("acccbonw.gif", "acccbonwneg.gif", "setColours('#000000','#ffffff');");
    document.write("&nbsp;");
    accToolbarButton("acccwonb.gif", "acccwonbneg.gif", "setColours('#ffffff','#000000');");
    document.write("&nbsp;");
    accToolbarButton("acccbony.gif", "acccbonyneg.gif", "setColours('#000000','#ffffaa');");
    document.write("&nbsp;");
    accToolbarButton("acccyonb.gif", "acccyonbneg.gif", "setColours('#ffffaa','#000000');");
    document.write("&nbsp;");
    accToolbarButton("accsdec.gif", "accsdecneg.gif", "decTextSize();");
    document.write("&nbsp;");
    accToolbarButton("accsinc.gif", "accsincneg.gif", "incTextSize();");
    document.write("</div>");
}

function accToolbarButton(image1, image2, onclick)
{
    document.write("<img class=\"minibtn\" style=\"margin-top: 3px;\" " +
                           "src=\"http://www.devonfhs.org.uk/images/bullet/" + image1 + "\" " +
                           "onmouseover=\"this.src='http://www.devonfhs.org.uk/images/bullet/" + image2 + "';\" " +
                           "onmouseout=\"this.src='http://www.devonfhs.org.uk/images/bullet/" + image1 + "';\" " +
                           "onclick=\"" + onclick + "\" " + ">");
}

function setColours(fore, back)
{
    disableStyleSheets();

    document.body.style.backgroundColor = back;
    document.body.style.color = fore;
}

function incTextSize()
{
    if (textSize < maxTextSize)
        setTextSize(textSize + textSizeInc);
}

function decTextSize()
{
    if (textSize > minTextSize)
        setTextSize(textSize - textSizeInc);
}

function setTextSize(size)
{
    disableStyleSheets();

    textSize = size;
    document.body.style.fontSize = textSize + '%';

    for (var element in document.body.children)
    {
        element.style.fontSize = textSize + '%';
    }
}

function disableStyleSheets()
{
    var i, a;
    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++)
        if (a.getAttribute("rel").indexOf("STYLE") != -1 /*&& a.getAttribute("title")*/)
            a.disabled = true;
}

