var setTweets = function(t){
	jQuery.each(t, function(){
		$('ul#tweetview').append('<li><a target="_blank" href="http://twitter.com/'+this.user.screen_name+'/status/'+this.id_str+'">'+relative_time(this.created_at)+'</a> '+this.text+'</li>')
	});
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return '1分以内';
  } else if(delta < 120) {
    return '1分前';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + '分前';
  } else if(delta < (120*60)) {
    return '1時間前';
  } else if(delta < (24*60*60)) {
    return '約' + (parseInt(delta / 3600)).toString() + '時間前';
  } else if(delta < (48*60*60)) {
    return '1日前';
  } else {
    return (parseInt(delta / 86400)).toString() + '日前';
  }
}

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery('#tweetview');
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 		
				$strip.find("li").each(function(i){
					stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);
				var totalTravel = stripWidth;//containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
					$strip.animate(
						{left: '-='+ spazio}, 
						{duration:tempo, easing:"linear",queue:false,
						complete:function(){$strip.css("left", 0); scrollnews(totalTravel, defTiming);}
					});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(
					function(){
						jQuery(this).stop();
					},
					function(){
						var offset = jQuery(this).offset();
						var residualSpace = offset.left + stripWidth;
						var residualTime = residualSpace/settings.travelocity;
						scrollnews(residualSpace, residualTime);
					}
				);			
		});	
};

function winOp(){
	window.open('ticket.html','','width=500,height=280,menubar=no,toolbar=no,scrollbars=no,resizable=no');
}
