Object.extend(Date.prototype, {
	strftime: function(format) {
		var day = this.getDay(), month = this.getMonth();
		var hours = this.getHours(), minutes = this.getMinutes();
		function pad(num) { return num.toPaddedString(2); };
		
		return format.gsub(/\%([aAbBcdDHiImMhpSwyY])/, function(part) {
			switch(part[1]) {
			case 'a': return $w("Sun Mon Tue Wed Thu Fri Sat")[day]; break;
			case 'A': return $w("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")[day]; break;
			case 'b': return $w("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")[month]; break;
			case 'B': return $w("January February March April May June July August September October November December")[month]; break;
			case 'c': return this.toString(); break;
			case 'd': return this.getDate(); break;
			case 'D': return pad(this.getDate()); break;
			case 'h': return hours; break;
			case 'H': return pad(hours); break;
			case 'i': return (hours === 12 || hours === 0) ? 12 : (hours + 12) % 12; break;
			case 'I': return pad((hours === 12 || hours === 0) ? 12 : (hours + 12) % 12); break;
			case 'm': return pad(month + 1); break;
			case 'M': return pad(minutes); break;
			case 'p': return hours > 11 ? 'PM' : 'AM'; break;
			case 'S': return pad(this.getSeconds()); break;
			case 'w': return day; break;
			case 'y': return pad(this.getFullYear() % 100); break;
			case 'Y': return this.getFullYear().toString(); break;
			}
		}.bind(this));
	},
	unix_ts:	function()
	{
		return	(this.getTime()/1000);
	},
	sub_ts:	function(op_b)
	{
		return	(this.getTime()-op_b.getTime())/1000;
	},
	i_min:	function(a)	{	return	a*60000;				},
	i_hour:	function(a)	{	return	a*3600000;			},
	i_day:	function(a)	{	return	a*86400000;			},
	i_week:	function(a)	{	return	a*604800000;			},
});


/**
 * A modified version of Stefan Hayden's onJSReady Prototype plugin.
 * http://www.stefanhayden.com/blog/2008/07/29/javascript-event-onjsready-fires-when-all-js-files-have-loaded/
 *
 * @author John-David Dalton 
 * @usage
 *   Prototype.include(['test1.js','test2.js','test3.js']); // array
 *   Prototype.include('test1.js', 'test2.js', 'test3.js'); // separate arguments OR
 *   Prototype.include('test1.js,test2.js,test3.js');       // comma separated string OR
 *
 *   document.observe('scripts:loaded', function(){ dependent_on_external_js() });
 */
// Prototype.include = Object.extend(
//   function() {
//     var callee = arguments.callee,
//      head = document.getElementsByTagName('HEAD')[0],
//      args = Array.prototype.slice.call(arguments, 0);
// 
//     args._each(function(files) {
//       if (Object.isString(files))
//         files = files.split(',');
// 
//       callee.total += files.length;
//       files._each(function(file) {
//         head.appendChild(
//           new Element('script', { type: 'text/javascript', src: file.strip() })
//         )
//         .observe('readystatechange', function () {
//           if (!this.loaded && /^(loaded|complete)$/.test(this.readyState)) {
//             this.loaded = true;
//             callee.downloaded++;
//           }
//         })
//         .observe('load', function () {
//         	console.log("asd");
//           if (this.loaded) return;
//           this.loaded = true;
//           callee.downloaded++;
//         }); // end observers
//       }); // end files _each
//     }); // end args _each
//   },
//   {
//     total: 0,
//     downloaded: 0
//   }
// );
// 
// (function() {
//   var timer;
//   function ready() {
//     if (arguments.callee.done) return;
//     clearInterval(timer);
//     arguments.callee.done = true;
//     document.fire('scripts:loaded');
//   }
// 
//   timer = setInterval(function() {
//     var i = Prototype.include;
//     if (i.total && i.downloaded === i.total) ready();
//   }, 10);
// })();

