 var feedData;
    var index = 0;
    var intervalId1;
    var intervalId2;
    
    $(document).ready(function() {
        var url = "http://twitter.com/status/user_timeline/fontanamusic.json?count=30&callback=?";
        $.getJSON(url,
        function(data) {
            feedData = data;
            ShowFeed();
            intervalId1 = window.setInterval(ShowFeed, 10000);
        });
    });

    function ShowFeed() {
        var itemsToShow = new Array();
        
        for (var i = 0; i < 2; i++) {
            if (index < feedData.length) {
                itemsToShow[i] = feedData[index];
                index++;
            }
            else {
                window.clearInterval(intervalId1);
		index = 0;
		ShowFeed();
		intervalId1 = window.setInterval(ShowFeed, 10000);
            }
        }

        RenderFeed(itemsToShow);
    }

    function RenderFeed(data) {
        var twitter = $("#twitter");
        twitter[0].style.top = '40px';
        
        twitter.children().remove();
        twitter.append("<ul></ul>");
        
        $.each(data, function(i, item) {
            $("#twitter ul").append("<li>" + item.text.linkify() + " <span>(" + relative_time(item.created_at) + ")</span></li>");
            
	});

        intervalId2 = window.setInterval(ScrollFeed, 100);
    }

    function ScrollFeed() {
        var twitter = $("#twitter");
        var top = parseInt(twitter[0].style.top.replace('px', ''));

        if (top <= 0) {
            window.clearInterval(intervalId2);
        }
        else {
            top -= 10;
            twitter[0].style.top = top + 'px';
        }
    }

    String.prototype.linkify = function() {
        return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
            return m.link(m);
        });
    };
    function relative_time(time_value) {
        var values = time_value.split(" ");
        time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
        var parsed_date = Date.parse(time_value);
        var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
        var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
        delta = delta + (relative_to.getTimezoneOffset() * 60);

        var r = '';
        if (delta < 60) {
            r = 'a minute ago';
        } else if (delta < 120) {
            r = 'couple of minutes ago';
        } else if (delta < (45 * 60)) {
            r = (parseInt(delta / 60)).toString() + ' minutes ago';
        } else if (delta < (90 * 60)) {
            r = 'an hour ago';
        } else if (delta < (24 * 60 * 60)) {
            r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
        } else if (delta < (48 * 60 * 60)) {
            r = '1 day ago';
        } else {
            r = (parseInt(delta / 86400)).toString() + ' days ago';
        }

        return r;
    }
    function twitter_callback() {
        return true;
    }
