﻿var tweetArray;

var loadPrintzTweets = function () {
    var printztweets = "";

    // Gather the tweets from the Twitter Feed
    $.get('/Utils/PrintzTweets.aspx', function (data) {
        printztweets = data;

        // Put them into a array
        var tweetarrayTemp = data.split("AXIspa:");
        var tweetArray = tweetarrayTemp.splice(0, 11);


        // skip that first tweet (which isn't really a tweet)
        var i = 1;

        // Load the first real tweet
        $("#printztweet").html(tweetArray[1]);
        $("#tweet_container").fadeIn(300);

        var interval = setInterval(function () {
            // Fade out, switch tweet and fade back in.
            $("#tweet_container").fadeOut(300, function () {
                $("#printztweet").html(tweetArray[i]);
                $("#tweet_container").fadeIn(300);
            });

            i++;

            // if we run out of tweets, start again.
            if (i >= tweetArray.length) {
                i = 1;
            }

            // this should never occur.
            if (i >= tweetArray.length) {
                clearInterval(interval);
                console && console.log("??");
            }
        }, 10000);
    });
};

$(document).ready(function () {

    // Start showing Printz Tweets
    loadPrintzTweets();

});




