/*
	Copyright (c) 2004-2008, The Dojo Foundation
	All Rights Reserved.

	Licensed under the Academic Free License version 2.1 or above OR the
	modified BSD license. For more information on Dojo licensing, see:

	http://dojotoolkit.org/license

*/

/*
	This is a compiled version of Dojo, built for deployment and not for
	development. To get an editable version, please visit:

		http://dojotoolkit.org

	for documentation and information on getting the source.
*/

if(!dojo._hasResource["blowery.index"]){
dojo._hasResource["blowery.index"]=true;
dojo.provide("blowery.index");

/*
 * Javascript Humane Dates
 * Copyright (c) 2008 Dean Landolt (deanlandolt.com)
 * Re-write by Zach Leatherman (zachleat.com)
 * 
 * Adopted from the John Resig's pretty.js
 * at http://ejohn.org/blog/javascript-pretty-date
 * and henrah's proposed modification 
 * at http://ejohn.org/blog/javascript-pretty-date/#comment-297458
 * 
 * Licensed under the MIT license.
 */

 /**
  * @param {String or Date} date_str either an ISO8601 date string or a Date object.
  *          Note: ISO8601 dates are always formatted using UTC/GMT timezone.
  *          Example: 2009-06-03T20:06:44Z
  */
function humane_date(date_str){
 var time_formats = [
  [1, '1 second'],
  [60, 'seconds', 1],
  [90, '1 minute'], // 60*1.5
  [3600, 'minutes', 60], // 60*60, 60
  [5400, '1 hour'], // 60*60*1.5
  [86400, 'hours', 3600], // 60*60*24, 60*60
  [129600, '1 day'], // 60*60*24*1.5
  [604800, 'days', 86400], // 60*60*24*7, 60*60*24
  [907200, '1 week'], // 60*60*24*7*1.5
  [2628000, 'weeks', 604800], // 60*60*24*(365/12), 60*60*24*7
  [3942000, '1 month'], // 60*60*24*(365/12)*1.5
  [31536000, 'months', 2628000], // 60*60*24*365, 60*60*24*(365/12)
  [47304000, '1 year'], // 60*60*24*365*1.5
  [3153600000, 'years', 31536000], // 60*60*24*365*100, 60*60*24*365
  [4730400000, '1 century'], // 60*60*24*365*100*1.5
 ];

 var time = ('' + date_str).replace(/-/g,"/").replace(/[TZ]/g," "),
  dt = new Date,
  seconds = (date_str instanceof Date ? (dt - date_str)
              : (dt - new Date(time) + (dt.getTimezoneOffset() * 60000))) / 1000,
  token = ' ago',
  i = 0,
  format;

 if (seconds < 0) {
  seconds = Math.abs(seconds);
  token = ' from now';
 }

 while (format = time_formats[i++]) {
  if (seconds < format[0]) {
   if (format.length == 2) {
    return format[1] + token
   } else {
    return Math.round(seconds / format[2]) + ' ' + format[1] + token;
   }
  }
 }

 // overflow for centuries
 if(seconds > 4730400000)
  return Math.round(seconds / 4730400000) + ' centuries' + token;

 return null;
};

blowery.index.fixupDates=function(){
function fixupDate(n){
var d=humane_date(n.title);
if(d){
n.innerHTML=d;
}
};
dojo.query("abbr.published").forEach(fixupDate);
};
dojo.addOnLoad(function(){
blowery.index.fixupDates();
setInterval(blowery.index.fixupDates,1000);
});
}

