// JavaScript Document

var tweetarray = new Array(); 
var tweetcount = 0;
$(document).ready( function() {

	 
	var tweetcount = 0; //to keep track 
	var waittime = 5000;	
		
	$.getJSON("http://twitter.com/statuses/user_timeline.json?screen_name=suntileUK&count=10&callback=?",
 		function(data){
			$.each(data, function(i,item){
				nowtweet = item.text;
				nowtweet = nowtweet.replace(/http:\/\/\S+/g,  '<a href="$&" target="_blank">$&</a>');
			    nowtweet = nowtweet.replace(/\s(@)(\w+)/g,    ' @<a href="http://twitter.com/$2" target="_blank">$2</a>');
			    nowtweet = nowtweet.replace(/\s(#)(\w+)/g,    ' #<a href="http://search.twitter.com/search?q=%23$2" target="_blank">$2</a>');
				
				tweetarray[i] = nowtweet;
				// $("#jstweets").append('<div>'+tweetarray[i] +"</div>");
				$("#jstweets").html(tweetarray[0]);
 			});
			tweetloop();
		
	});

})

function tweetloop() {
	
	$("#jstweets").animate({"opacity" : "1"}, 400) // fade in
				  .animate({"opacity" : "1"}, 5000) // delay length
				  .animate({"opacity" : "0"}, 400, function() { // fade out
					tweetcount++ ; if (tweetcount > tweetarray.length - 1) tweetcount = 0;
					$("#jstweets").html(tweetarray[tweetcount]);										
				   tweetloop();
				})
}

/*            
	

     var j = 0;
     var delay = 2000; //millisecond delay between cycles
     function cycleThru(){
             var jmax = $("ul#cyclelist li").length -1;
             $("ul#cyclelist li:eq(" + j + ")")
                     .animate({"opacity" : "1"} ,400)
                     .animate({"opacity" : "1"}, delay)
                     .animate({"opacity" : "0"}, 400, function(){
                             (j == jmax) ? j=0 : j++;
                             cycleThru();
                     });
             };

     cycleThru();
			 */

