var blogUsers = ['jeffremer'];
// The twitter accounts that will be included in the ticker

$(document).ready(function(){

	// After the page is loaded

	$('#blog-ticker').slideDown('slow');
	// Show the ticker

	var fileref = document.createElement('script');
	// Creating a new script element

	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", "http://blog.teamroaringmouse.com/?feed=json&jsonp=BlogTick");

	// Setting its src to the search API URL; We provide TweetTick as a callback

	document.getElementsByTagName("head")[0].appendChild(fileref);
	// Appending it to the head of the page and thus executing it
});

function BlogTick(ob)
{
	// This is the callback function

	var container=$('#blog-container');
	container.html('');
	// Removing the loading gif animation

	$(ob).each(function(el){

		// ob contains all the tweets

		var str = '<div class="post">\
		<div class="title"><a href="'+this.link+'" target="_blank">'+this.title+'</a></div>\
		<div class="time">' + this.date + '</div>\
		<div class="txt">'+this.excerpt.substring(0,140)+' <a target="_blank" href="' + this.link + '">[...]</a></div>\
		</div>';

		container.append(str);
		// Adding the tweet to the container
	});

	container.jScrollPane();
	// After all the tweets have been added, create the slidebar
}

function relativeTime(pastTime)
{
	// Generate a JavaScript relative time for the tweets

	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";

	// If the tweet is older than a day, show an absolute date/time value;

	var dateArr = pastTime.split(' ');

	return dateArr[4].replace(/\:\d+$/,'')+' '+dateArr[2]+' '+dateArr[1]+
	(dateArr[3]!=curDate.getFullYear()?' '+dateArr[3]:'');
}