var RecaptchaOptions = {
   theme : 'blackglass'
};

function calculateTime (timestamp) {
	currentTimeMS = new Date().getTime();
	currentTimeS = currentTimeMS/1000;
	seconds = Math.round(currentTimeS - timestamp);
	minutes = Math.round(seconds/60);
	hours = Math.round(minutes/60);
	days = Math.round(hours/24);
	weeks = Math.round(days/7);
	months = Math.round(days/31);
	years = Math.round(days/365);
	if (minutes < 60) {
		if (minutes < 2) {
			return 'just now';
		}
		return minutes + ' min. ago';
	} else if (hours < 24) {
		if (hours == 1) {
			return hours + ' hour ago';
		} else {
			return hours + ' hours ago';
		}
	} else if (days < 7) {
		if (days == 1) {
			return days + ' day ago';
		} else {
			return days + ' days ago';
		}
	} else if (days < 31) {
		if (weeks == 1) {
			return weeks + ' week ago';
		} else {
			return weeks + ' weeks ago';
		}
	} else if (days < 365) {
		if (months == 1) {
			return months + ' month ago';
		} else {
			return months + ' months ago';
		}
	} else {
		if (years == 1) {
			return years + ' year ago';
		} else {
			return years + ' years ago';
		}
	}
}

function loadTwitter() {
	$.ajax({
		type: "POST",
		url: '/twitter/usertimeline',
		beforeSend: function() {
			$('#twitter-feed').html('<div class="loader"><img src="/design/plain_site/images/loading_animation.gif" alt="Loading..."/></div>');
		},
		success: function(data){
			$('#twitter-feed').html(data);
			$('#twitter-feed .timespan').each(function() {
				time = $(this).text();
				$(this).text('@ ' + calculateTime(time));
			});
		}
	});
}

/* GLOBAL DOCUMENT READY FUNCTIONS */
$(document).ready(function(){
	if ($('#twitter-feed').length) {
		loadTwitter();
	}
});
