var pictures = new Array();

pictures[0] = "images/P1010002small.jpg";
pictures[1] = "images/tay1small.jpg";
pictures[2] = "images/dunkeld1small.jpg";
pictures[3] = "images/dunkeld2small.jpg";
pictures[4] = "images/dunkeld3small.jpg";
pictures[5] = "images/dunkeld4small.jpg";
pictures[6] = "images/dunkeld5small.jpg";
pictures[7] = "images/bluecraggs.jpg";
pictures[8] = "images/lochturret.jpg";
pictures[9] = "images/queensview1sml.jpg";
pictures[10] = "images/queensview2.jpg";
pictures[11] = "images/queensview3.jpg";
pictures[12] = "images/rivergarry2.jpg";
pictures[13] = "images/country road sml.jpg";
pictures[14] = "images/balboughtywoodmill2sml.jpg";
pictures[15] = "images/kinkellbridgesml.jpg";
pictures[16] = "images/lochlevensml.jpg";
pictures[17] = "images/above monziesml.jpg";
pictures[18] = "images/fromblairgowrietoperthsml.jpg";
pictures[19] = "images/sisnow1.jpg";
pictures[20] = "images/sisnow2sml.jpg";

var altText = new Array();

altText[0] = "\"Picture of Perth and the River Tay\"";
altText[1] = "\"Image of the Queen's Bridge\"";
altText[2] = "\"Image of the Telford Bridge, Dunkeld\"";
altText[3] = "\"Image of the Tay flowing downstream at Dunkeld\"";
altText[4] = "\"Image of view from Telford Bridge Dunkeld\"";
altText[5] = "\"Image of the Tay from Dunkeld Cathedral\"";
altText[6] = "\"Image of Dunkeld Cathedral\"";
altText[7] = "\"Image of Blue Craggs\"";
altText[8] = "\"Image of Loch Turret\"";
altText[9] = "\"Image of Queen's View, outside Killicrankie\"";
altText[10] = "\"Image of Queen's View in Autumn\"";
altText[11] = "\"Image of Queen's View - one of the best scenes in Perthshire\"";
altText[12] = "\"Image of River Garry in Autumn\"";
altText[13] = "\"Image of Country road by Aucterarder\"";
altText[14] = "\"Image of Balboughty Wood Mill\"";
altText[15] = "\"Image of Kinkell Bridge\"";
altText[16] = "\"Image of Loch Leven\"";
altText[17] = "\"Image of view above Monzie\"";
altText[18] = "\"Image of view from Blairgowrie to Perth\"";
altText[19] = "\"Image of view over South Inch park in the snow\"";
altText[20] = "\"Image of view over South Inch Park in the snow\"";

function randomImage(level)
{
    var index = Math.floor(pictures.length * Math.random());

    var result="";
    
    if (level == 0)
    {
        result = result + pictures[index];
    }
    else if (level == 1)
    {
        result = result + "../" + pictures[index];
    }
    
    var element = document.getElementById('randomImage');
    
    var img = document.createElement('img');
    img.setAttribute('src',result);
    img.setAttribute('alt',altText[index]);
    
    element.appendChild(img);
}

var oranges = new Array("#FF6600",
                                              "#FF6906", 
                                              "#FF6D0C", 
                                              "#FF7113", 
                                              "#FF7519", 
                                              "#FF791F",
                                              "#FF7C26",
                                              "#FF802C",
                                              "#FF8433",
                                              "#FF8839",
                                              "#FF8C3F",
                                              "#FF9046",
                                              "#FF934C",
                                              "#FF9752",
                                              "#FF9B59",
                                              "#FF9F5F",
                                              "#FFA366",
                                              "#FFA76C",
                                              "#FFAA72",
                                              "#FFAE79",
                                              "#FFB27F",
                                              "#FFB685",
                                              "#FFBA8C",
                                              "#FFBD92",
                                              "#FFC199",
                                              "#FFC59F",
                                              "#FFC9A5",
                                              "#FFCDAC",
                                              "#FFD1B2",
                                              "#FFD4B8",
                                              "#FFD8BF",
                                              "#FFDCC5",
                                              "#FFE0CC",
                                              "#FFE4D2",
                                              "#FFE8D8",
                                              "#FFEBDF",
                                              "#FFEFE5",
                                              "#FFF3EB",
                                              "#FFF7F2",
                                              "#FFFBF8",
                                              "#FFFFFF");

var blacks = new Array("#000000",
                                            "#060606", 
                                            "#0C0C0C", 
                                            "#131313", 
                                            "#191919", 
                                            "#1F1F1F",
                                            "#262626",
                                            "#2C2C2C",
                                            "#333333",
                                            "#393939",
                                            "#3F3F3F",
                                            "#464646",
                                            "#4C4C4C",
                                            "#525252",
                                            "#595959",
                                            "#5F5F5F",
                                            "#666666",
                                            "#6C6C6C",
                                            "#727272",
                                            "#797979",
                                            "#7F7F7F",
                                            "#858585",
                                            "#8C8C8C",
                                            "#929292",
                                            "#999999",
                                            "#9F9F9F",
                                            "#A5A5A5",
                                            "#ACACAC",
                                            "#B2B2B2",
                                            "#B8B8B8",
                                            "#BFBFBF",
                                            "#C5C5C5",
                                            "#CCCCCC",
                                            "#D2D2D2",
                                            "#D8D8D8",
                                            "#DFDFDF",
                                            "#E5E5E5",
                                            "#EBEBEB",
                                            "#F2F2F2",
                                            "#F8F8F8",
                                            "#FFFFFF");

function colourFadeEffect(id, start, length, colour)
{
    this.current = start;
    this.length = length;
    this.id = id;
    this.colour = colour;
    
    /*
        return true when the effect has completed one loop
        ie the character has faded to white or the reverse
        process has been completed
    */
    
    this.result = true;
    
    //Initialise the character to be white
    document.getElementById(this.id).style.color = "#ffffff";
    
    this.step = -1;
    
    //apply the function
    this.execute = function(restart)
    {
        this.result = restart;
        
        //Check to see if the effect has been completed
        if (this.current < 0)
        {
            this.current = 0;
            this.step = 1;
            this.result = false;
        }
        else if (this.current > 40)
        {
            this.current = 40;
            this.step = -1;
            this.result = false;
        }
        
        document.getElementById(this.id).style.color = this.colour[this.current];
        
        this.current = this.current + this.step;
        
        return this.result;
    }
}

function insertSpan(idText, t)
{
    var doc = document.getElementById('banner');
    var span = document.createElement('span');
    span.setAttribute('id',idText);
    span.appendChild(document.createTextNode(t));
    doc.appendChild(span);
}
/*
    text is the text that will be displayed on the screen.
    sequence is the order in which the effect is applied.
*/
function Banner(text, sequence)
{
    this.elements;
    this.current = 0;
    var effect;
    
    //Create the banner and attach the effect to the elements
    this.elements = new Array(text.length);
    
    for (var i=0;i<text.length;i++)
    {
        var name = "bannerID" + i;
       
        insertSpan(name, text.charAt(i));

        //Don't apply the effect to spaces
        if (text.charAt(i) != ' ')
        {
            //The first character is black all the others are orange
            if (i == 0)
            {
                effect = new colourFadeEffect(name, 40, blacks.length, blacks);
            }
            else
            {
                effect = new colourFadeEffect(name, 40, oranges.length, oranges);
            }
        }
        else
        {
            effect = null;
        }
       
        this.elements[sequence[i]] = effect;
    }
    
    this.bannerEffect = function update()
    {
        //skip the spaces
        if (this.elements[this.current] == null)
        {
            this.current = this.current + 1;
        }
        else 
        {
            if ((this.elements[this.current]).execute(true) == false)
            {
                this.current = this.current + 1;
            }
        }

        if (this.current > (this.elements.length - 1))
        {
            this.current = 0;
        }
    
        setTimeout("this.bannerEffect()",20);
    }
    
    bannerEffect();
}

function insertBanner(name)
{
    var doc = document.getElementById("banner");
    var other = document.getElementById("noscriptText");
    
    doc.removeChild(other);
    
    if (name == "Awareness")
    {
        Banner("MS Week 27th April - 3rd May", 
               [13,24,17,11,5,20,3,10,8,15,22,1,26,23,18,19,25,16,6,2,12,14,27,4,7,21,9,0]);
    }
}

function fadeDiv(name)
{
    this.effect = new colourFadeEffect(name,20,oranges.length,oranges);
    
    this.updateEffect = function update()
    {
        result = this.effect.execute(true)
        
        setTimeout("this.updateEffect()",40);
    }
    
    updateEffect();
}

