$(document).ready(function(){
	$("ul#twitterMain").children().each(function(){
		tempWidth = $(this).find("p.tweet").width();
		scrollTweet(this,tempWidth);
	});
});

function scrollTweet(tweet,tempWidth){
	if(tempWidth > 0){
		var curWidth = $(tweet).find("p.tweet").width();
		var curLeft = parseInt($(tweet).find("p.tweet").css("left"));
		
		if((curWidth + curLeft) < 500 && $(tweet).find("p.tweet").children().size() < 5){
			var tempHTML = $(tweet).find("p.tweet").html();
			$(tweet).find("p.tweet").append(tempHTML);
		}
		
		if(parseInt($(tweet).find("p.tweet").css("left")) < (0 - tempWidth)){
			var tempLeft = (parseInt($(tweet).find("p.tweet").css("left")) + tempWidth);
			$(tweet).find("p.tweet span:first-child").remove();
			$(tweet).find("p.tweet").css("left",(tempLeft + "px"));
			scrollTweet(tweet,tempWidth);
		}else{
			$(tweet).find("p.tweet").animate({
				left:"-=40px"
			},1000,"linear",function(){
				scrollTweet(tweet,tempWidth);
			});
		}
	}
}
