/*
 * PrettyDate: Implemented in a manner slightly nicer than jResig's attempt, more akin to twitter's date format.
 * @dependancy PHPJS.date()
 * @author Richard Assar
 */
function prettyDate(date){
	var now = new Date();

	var diff = (now.getTime() - date.getTime()) / 1000;

	if(
		date.getDay() == now.getDay() &&
		date.getMonth() == now.getMonth() && 
		date.getFullYear() == now.getFullYear()
	) { // Same day
		return (
			diff < 60 && "just now" ||
			diff < 120 && "1 minute ago" ||
			diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
			diff < 7200 && "1 hour ago" ||
			diff < 86400 && Math.floor( diff / 3600 ) + " hours ago" ||
			Math.floor( diff / 86400 ) + " days ago"
		);
	} else if(date.getFullYear() == now.getFullYear()) { // Same year
		return PHPJS.date("d M", date / 1000);
	} else { // Different year
		return PHPJS.date("d M y", date / 1000);
	}
};

// If jQuery is included in the page, adds a jQuery plugin to handle it as well
if ( typeof jQuery != "undefined" )
	jQuery.fn.prettyDate = function(){
		return this.each(function(){
			var date = prettyDate(this.title);
			if ( date )
				jQuery(this).text( date );
		});
	};
	

