﻿var tinyNewsIndex = 0;
var loadedOnce = false;

rotateTinyNewsServerSideSuccess = function(result)
{
    var tinyNewsContainer = document.getElementById("tiny-news-msg");
    if (tinyNewsContainer != null)
    {
        var fadeOut = new AjaxControlToolkit.Animation.FadeOutAnimation(tinyNewsContainer, 0.5, 20, 0, 1, false);

        var script = "document.getElementById('tiny-news-msg').innerHTML = \"" + result + "\";";
        var animScript = new AjaxControlToolkit.Animation.ScriptAction(null, 0.01, null, script);

        var fadeIn = new AjaxControlToolkit.Animation.FadeInAnimation(tinyNewsContainer, 0.5, 20, 0, 1, false);

        var sequence = new AjaxControlToolkit.Animation.SequenceAnimation();
        sequence.add(fadeOut);
        sequence.add(animScript);
        sequence.add(fadeIn);
        sequence.play();
    }
    
    tinyNewsIndex++;
    if (tinyNewsIndex > 500)
    {
        // If we stay on this page too long, looping through the tiny news rotator, we end up executing so
        // many JS statements that IE and FF think we may be on an unresponsive page. To prevent this, we can
        // refresh the page to start the counter over again. See http://support.microsoft.com/kb/175500
        window.location.reload();
    }
    else
    {
        setTimeout("rotateTinyNews()", 10000);
    }
}

rotateTinyNewsServerSideFailed = function(result)
{
    // Our invocation of the server-side (page) method did not work. It's not that
    // that method returned "false" as an answer. Rather, the method did not get invoked.
    // Typically this happens if there is a problem communicating between the client and the server.
}

rotateTinyNews = function()
{
    if (typeof(PageMethods) != "undefined")
    {
        PageMethods.RotateTinyNews(tinyNewsIndex, rotateTinyNewsServerSideSuccess, rotateTinyNewsServerSideFailed);
    }
}

pageLoad = function()
{
    if (!loadedOnce)
    {
        loadedOnce = true;
        rotateTinyNews();
    }
}

