Date.prototype.format = (function(){//this is a function that will be excuted after it is defined.
	var 
		literal = ' ,.:/-',//literal characters allowed.
		MONTHS = ['january','february','march','april','may','june','july','august','september','october','november','december'];
		DAYS = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday'];

	function twodigit(n){if(n<10)n='0'+n;return n;};//ensure 2 digits (add a '0' if it's a one digit number)
	function second(){return twodigit(this[0]());};//used on all the second cases, returns the first but with 2 digits ensured.
	function firstthree(s){return s.substring(0,3);};//return only the last 3 digits.

	var parsers = {
	  	d:[function(){return d.getDate();},second,function(){return firstthree(this[3]());},function(){return Lex.get(DAYS[d.getDay()]);}],
	  	M:[function(){return d.getMonth()+1;},second,function(){return firstthree(this[3]());},function(){return Lex.get(MONTHS[this[0]()-1]);}],
	  	y:[function(){return this[3]()%100;},second,function(){return d.getFullYear();},function(){return d.getFullYear();}],
  		H:[function(){return d.getHours();},second],
  		h:[function(){var h=d.getHours();return(h<12?h:h-12);},second],
  		m:[function(){return d.getMinutes();},second],
  		s:[function(){return d.getSeconds();},second],
  		t:[function(){return(d.getHours()<12?'a':'p');},function(){return this[0]()+'m';}],
  		T:[function(){return(d.getHours()<12?'A':'P');},function(){return this[0]()+'M';}]
	};

	var examiner = [], d;
	for(var p in parsers)examiner.push(p);//add the parseable letters to the list of recognized digits.
	examiner.push('['+literal+']+');//add the literals.
	examiner = new RegExp(examiner.join('+|'),"g");//generate the needed Regex.

	function examine(s){
		var parser = parsers[s.charAt(0)];//get the array of functions that parse the first letter of the string.
	  	if(!parser)return s;//if it was a literal.. return it untouched.
	  	var l = Math.min(s.length,parser.length);//get the length of the string (reduce it to the length of the array if it exceeds it).
		return parser[l-1]().toString();//format it and return it.
	};
	function analyze(t){
		 var a = Date.prototype.format.arguments;
		 if(!a.length || typeof a[0] != 'string')//if no arguments were passed, just use the original toString function.
				return t.String();
		 var f = '';
		 d = t;//put this date in the local variable of the function.
		 a[0].replace(examiner,function(m){//iterate through the matches.
			f+=examine(m);//add the parsed part to the final string.
		 });
		 d = null;
		 return f;//return the formatted date.
	};
	return function(){//this is the function that will replace the original toString. The rest will stay in the scope of the anonymous function.
		return analyze(this);
	};
})();