function getObjName(name)
{
    if (document.getElementById)
    {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
    }
    else if (document.all)
    {
        this.obj = document.all[name];
        this.style = document.all[name].style;
    }
    else if (document.layers)
    {
        this.obj = document.layers[name];
        this.style = document.layers[name];
    }
}

function divScroller(id, speed, delay)
{
    var tickerScroller = new getObjName(id);
    var tickerInner = new getObjName(id + "_inner");

    tickerInner.style.position = "absolute";
    tickerInner.style.left = parseInt(tickerScroller.style.width) + "px";
    tickerInner.style.top = parseInt(tickerScroller.style.height) + "px";

    tickerInner.style.left = "0px";
    tickerInner.style.width = parseInt(tickerScroller.style.width) + "px";

    limit = tickerInner.obj.getElementsByTagName('div').length * parseInt(tickerScroller.style.height);

    setTimeout("headlineTicker(\"" + id + "\", " + limit + ", " + speed + ", " + delay + ")", parseInt(speed));
}

function headlineTicker(id, limit, speed, delay)
{
    // DOM3 = IE5+, NS6+, FF0.7+
    var tickerScroller = new getObjName(id);
    var tickerInner = new getObjName(id + "_inner");
    
    // *** Tick duration
    nextTick = speed;
    
    // *** Avoiding some errors
    if (!tickerInner.style.top) tickerInner.style.top = "0px";
    
    // *** Moving the tickerInner div. At the end, restart.
    if (parseInt(tickerInner.style.top) < -limit)
    {
        tickerInner.style.top = parseInt(tickerScroller.style.height) + "px";
    }
    else
    {
        tickerInner.style.top = (parseInt(tickerInner.style.top) - 1) + "px";
    }
    
    // *** Bigger delay on item found
    // Skips borders to make transition without delays on loop
    if (!(parseInt(tickerInner.style.top) == parseInt(tickerScroller.style.height)) &&
        !(parseInt(tickerInner.style.top) == -limit) &&
        (parseInt(tickerInner.style.top) % parseInt(tickerScroller.style.height)) == 0)
    {
        nextTick = delay;
    }
    
    // *** Tick!
    setTimeout("headlineTicker(\"" + id + "\", " + limit + ", " + speed + ", " + delay + ")", parseInt(nextTick));
}

function setBackgroundColour(colour)
{
    $("body").css("background-color", colour);
    $("#colour_picker").css("background-color", colour);
    $.cookie("es_bgcolour", colour, { path: '/', expires: 60 });
}

function setFontColour(colour)
{
    $(".content_full").css("color", colour);
    $(".content_full").find("a").css("color", colour);
    $.cookie("es_fontcolour", colour, { path: '/', expires: 60 });
}

/* Colour Selection Area */

$(document).ready(function()
{
    if ($.cookie("es_fontcolour"))
    {
        setFontColour($.cookie("es_fontcolour"));
    }

    if ($.cookie("es_bgcolour"))
    {
        setBackgroundColour($.cookie("es_bgcolour"));
    }

    $("#colour_picker").click(function () {
        $("#header_standard").toggle();
        $("#header_selector").toggle();
        return false;
    });

    $("#colour_picker2").click(function () {
        $("#header_standard").toggle();
        $("#header_selector").toggle();
        return false;
    });
    
    $("#s_bgcolour").change(function () {
        $("#s_bgcolour option:selected").each(function () {
            setBackgroundColour($(this).val());
        });
    });
    
    $("#s_fontcolour").change(function () {
        $("#s_fontcolour option:selected").each(function () {
            setFontColour($(this).val());
        });
    });
    
    $("#s_reset").click(function () {
        setFontColour("#000000");
        setBackgroundColour("#ffffff");
        //  Blank the Cookies
        $.cookie("es_bgcolour", null, { path: '/' });
        $.cookie("es_fontcolour", null, { path: '/' });
    });
    
});

