(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
	var args_len = arguments.length;
	for (var i = args_len; i--;) {
	  var cacheImage = document.createElement('img');
	  cacheImage.src = arguments[i];
	  cache.push(cacheImage);
	}
  }
})(jQuery)

var timeAgo = function(dateString) {
	var rightNow = new Date();
	var then = new Date(dateString);
	
	if ($.browser.ie) {
		then = Date.parse(dateString.replace(/( \+)/, ' UTC$1'));
	}
	
	var diff = rightNow - then;
	var second = 1000,
	minute = second * 60,
	hour = minute * 60,
	day = hour * 24,
	week = day * 7;
	
	if (isNaN(diff) || diff < 0) {
		return "";
	}
	
	if (diff < second * 2) {
		return "agora";
	}
	
	if (diff < minute) {
		return Math.floor(diff / second) + " segundos atrás";
	}
	
	if (diff < minute * 2) {
		return "1 minuto atrás";
	}
	
	if (diff < hour) {
		return Math.floor(diff / minute) + " minutos atrás";
	}
	
	if (diff < hour * 2) {
		return "à 1 hora atrás";
	}
	
	if (diff < day) {
		return  Math.floor(diff / hour) + " horas atrás";
	}
	
	if (diff > day && diff < day * 2) {
		return "ontem";
	}
	
	if (diff < day * 365) {
		return Math.floor(diff / day) + " dias atrás";
	} else {
		return "ano passado";
	}

};


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
