/*==================================
	Queries
==================================*/
$(document).ready(function(){
	getLatestTweets();
});

function getLatestTweets(){
      
	$("#tweetQuery").tweet({
        avatar_size: 32,
        count: 10,
        query: "from:BSRF11 OR BSRF11 OR #BSRF11 OR @BSRF11", //"@BSRF11 OR #BSRF11", //not enough recent tweets for BSRF
        loading_text: "Searching twitter..."
    });
      
      
	setTweetTimer();
	  
}

/*==================================
	Animation
==================================*/
var tweetTimeout;
var numVisible = 5;
var tweetHeight = 92;


function setTweetTimer() {

    if (tweetTimeout) clearTimeout(tweetTimeout);
    
    tweetTimeout = setTimeout(function() {
		var curTop = parseInt($('.query div.tweet_list').css('top'), 10);
		var newTop = curTop - tweetHeight;
		var tweetsLoaded = $('#twitterFeed .tweet_item').length;
		
		if (newTop >= -((tweetsLoaded - numVisible) * tweetHeight) && tweetsLoaded > numVisible) {
		
			$('.query div.tweet_list').animate({
					top: newTop + 'px'
				}, 600, function() {
				setTweetTimer();
			});
			
		} else {
			
			$('.query div.tweet_list').animate({
					top: '0px'
				}, 1200, function() {
				setTweetTimer();
			});
		
		}
		
	}, 4500);
	
}

/*==================================
	Utility
==================================*/
function randomString(length) {
      var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
      var str = '';
      for (var i = 0; i < length; i++) {
        str += chars[Math.floor(Math.random() * chars.length)];
      }
      return str;
}

var rnd = randomString(8);
