// JavaScript Document

// Variables
var tweets = {};



/**
* Latest tweets
*/
function init_tweets() {
	
	tweets.tweet_count = 0;
	tweets.num_tweets = $(".latest-tweets ul li").size();
	
	if (tweets.num_tweets > 1) {
		
		// Clone the first tweet
		$(".latest-tweets ul").find("li:first").clone(true).appendTo($(".latest-tweets").find("ul"));
		tweets.num_tweets ++;
		
		// Position for the first tweet
		$(".latest-tweets ul").find("li:first").css({ "margin-top": $(".latest-tweets ul").height()+"px" });
		
		scroll_tweets();
		
	}
	
}



/**
* Scrolls the twitter feed
*/
function scroll_tweets() {
	
	if (tweets.tweet_count >= tweets.num_tweets) {
		
		$(".latest-tweets ul").find("li:first").css({ "margin-top": "0px" });
		
		tweets.tweet_count = 1;
		
		scroll_tweets();
		
	}
	
	else {
		
		// Animate with a bounce!
		$(".latest-tweets ul").find("li:first").animate({
			
			"marginTop" : "-="+$(".latest-tweets ul").height()+"px"
			
		}, 200, "swing", function() {
			
			tweets.tweet_count ++;
			
			tweets.tweetTimer = window.setTimeout(scroll_tweets, 8000);
			
		});
		
	}
	
}



// Make sure the document is ready
$(document).ready(function() {
	
	/**
	* Adds the IE6 warning to the document
	*/
	if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
		
		$("body").prepend("<div id=\"ie6-warning\"></div>");
		$("#ie6-warning").load("/templates/default/templates/custom/ie6.php");
		
	}
	
	
	
	// Initialise
	init_tweets();
	
});

