/* 
	All Source Code Copyright 2010, Vrasa
	http://vrasa.com/
	
	If you like what you see, and want to use
	some of this code please email us here: 
	hello [at] vrasa.com and we can discuss 
	pricing and availability.

	Date: Sat August 14 20:19:07 2010 -0600
*/

$(document).ready(function(){
	
	var fileref = document.createElement('script');
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", "http://search.twitter.com/search.json?q=from:starfieldband&callback=TweetTick&rpp=50");
	document.getElementsByTagName("head")[0].appendChild(fileref);
	
	var filereftwo = document.createElement('script');
	filereftwo.setAttribute("type","text/javascript");
	filereftwo.setAttribute("src", "http://search.twitter.com/search.json?q=&ands=starfield&nots=%40starfield+wallpaper+3D+droid+background+screensaver+android+RT&lang=en&units=mi&callback=TweetTickTwo&rpp=50");
	document.getElementsByTagName("head")[0].appendChild(filereftwo);
	
});

function TweetTick(ob){

	var container=$('#tweetcontainer');
	container.html('');
	
	$(ob.results).each(function(el){
	
		var str = '	<div class="tweet">\
					<div class="txt">'+formatTwitString(this.text)+'</div>\
					<div class="time">'+relativeTime(this.created_at)+'</div>\
					</div>';
		
		container.append(str);
	
	});
	
	container.jScrollPane({
		scrollbarWidth:5, 
  		scrollbarMargin:0,
  		animateTo:true,
	}); 
}

function TweetTickTwo(ob){

	var container=$('#tweetcontainertwo');
	container.html('');
	
	$(ob.results).each(function(el){
	
		var str = '	<div class="tweettwo">\
					<div class="txttwo">'+formatTwitString(this.text)+'</div>\
					<div class="timetwo">'+relativeTime(this.created_at)+'</div>\
					</div>';
		
		container.append(str);
	
	});
	
	container.jScrollPane({
		scrollbarWidth:5, 
  		scrollbarMargin:0,
  		animateTo:true,
	});
}

function formatTwitString(str){str=' '+str;str=str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>');str=str.replace(/([^\w])\@([\w\-]+)/gm,'$1@<a href="http://twitter.com/$2" target="_blank">$2</a>');str=str.replace(/([^\w])\#([\w\-]+)/gm,'$1<a href="http://twitter.com/search?q=%23$2" target="_blank">#$2</a>');return str}function relativeTime(pastTime){var origStamp=Date.parse(pastTime);var curDate=new Date();var currentStamp=curDate.getTime();var difference=parseInt((currentStamp-origStamp)/1000);if(difference<0)return false;if(difference<=5)return"Just now";if(difference<=20)return"Seconds ago";if(difference<=60)return"A minute ago";if(difference<3600)return parseInt(difference/60)+" minutes ago";if(difference<=1.5*3600)return"One hour ago";if(difference<23.5*3600)return Math.round(difference/3600)+" hours ago";if(difference<1.5*24*3600)return"One day ago";var dateArr=pastTime.split(' ');return dateArr[2]+' '+dateArr[1]+(dateArr[3]!=curDate.getFullYear()?' '+dateArr[3]:'')}

