jQuery(function($) {
    var tweets = {
        el: '.twitterTicker .twitter-stream',
        items: new Array(),
        count: 0,
        total: -1,
        delay: 6000,
        animate: true
    };
    $(tweets.el+' p').each(function(i) {
        tweets.items[i] = $(this).html();
        tweets.total++;
    }).hide();
    runTweeter();
    function runTweeter() {
        if(tweets.animate == true) {
            if($(tweets.el+' p').length > 0) {
                $(tweets.el).children('p').fadeOut(500, function() {
                    $(this).parent(0).empty().append('<p style="display: none;">'+tweets.items[tweets.count]+'</p>').children('p').fadeIn(500);
                });
            } else {
                $(tweets.el).empty().append('<p style="display: none;">'+tweets.items[tweets.count]+'</p>').children('p').fadeIn(750);
            }
        } else {
            $(tweets.el).empty().append('<p>'+tweets.items[tweets.count]+'</p>');
        }
        setTimeout(function() {
            if(tweets.count == tweets.total) {
                tweets.count = 0;
            } else {
                tweets.count++;
            }
            runTweeter();
        }, tweets.delay);
    }
});
