$(function() {
	$('.tweets').hide().tweetable({
		username: 'horizoncomms',
		time: true,
		limit: 20,
		replies: false
	});

	var jTweets = [];

	(function tweetScroller(iTweet) {
		var iScrollTime = 500;
		var iTweetTime = 8000;
		if (jTweets.length) {
			if (iTweet >= jTweets.length - 1) {
				iTweetTime = 10;
				if (iTweet >= jTweets.length) {
					iTweet = 0;
					iScrollTime = 0;
				}
			}
		}
		else {
			// since twitter is read only once per page load, we can cache the twitter items
			if ($('.tweets ul').length) {
				// add an additonal element to the start and end of the list, to allow us to loop invisibly
				var sBlankTweet = '<li><p>&nbsp;</p><p>&nbsp;</p></li>';
				$('.tweets ul').prepend(sBlankTweet).append(sBlankTweet);
				jTweets = $('.tweets ul li');
				// move to and display the first item without animated scrolling
				iScrollTime = 0;
			}
			else {
				// otherwise, keep trying until the tweets are loaded
				setTimeout(function(){tweetScroller(iTweet)}, 50);
				return;
			}
		}
		$('.tweets').show().scrollTo($(jTweets[iTweet]), iScrollTime);
		setTimeout(function(){tweetScroller(iTweet + 1)}, iTweetTime);
	})(1);
});

function tweetScroll(iTweet) {
// retain legacy function so we don't have to change all the pages individually
}

