/*
---------------------------------------------------------------------
shuffle photos, twitter ticker
for:  http://roji-kamakura.net/
Author: Asami FUJITA   http://onamon.com/
---------------------------------------------------------------------*/

function pshuffle(){
		$('#photos').shuffle();
		$('#photos a img').attr("style","display:inline");
}

$(function(){
            var tweeturl="http://twitter.com/status/user_timeline/roji_kamakura.json?count=10&callback=?";
            $.getJSON(tweeturl, function(data){
               $.each(data, function(i, item){
                  // URL link
                  var txt = item.text
                     .replace(/(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig,'<a href="$1">$1</a>')
                     .replace(/@+([_A-Za-z0-9-]+)/ig, '<a href="http://twitter.com/$1" target="_blank">@$1</a>')
                     .replace(/#+([_A-Za-z0-9-]+)/ig, '<a href="http://search.twitter.com/search?q=$1" target="_blank">#$1</a>');
                  $("<li></li>")
                   // .addClass(i%2 ? "even" : "odd")
                     .html(txt)
                     .prependTo("#tweet");
               });
            });
         });


$(document).ready(function(){
	
	var first = 0;
	var speed = 1000;
	var pause = 5000;
	
		function removeFirst(){
			first = $('ul#tweet li:first').html();
			$('ul#tweet li:first')
			.animate({opacity: 0}, speed)
			.fadeOut('slow', function() {$(this).remove();});
			addLast(first);
		}
		
		function addLast(first){
			last = '<li style="display:none">'+first+'</li>';
			$('ul#tweet').append(last)
			$('ul#tweet li:last')
			.animate({opacity: 1}, speed)
			.fadeIn('slow')
		}
	
	interval = setInterval(removeFirst, pause);
});