/*
	Date formatter class to create string representations of date objects.
	(c) 2011 Kimmo Tapala / Verkkojulkaisut - Network Publications Ltd.
*/
(function($){
function DateFormatter(date,opts){this.date=date;this.opts={locale:'en',digits:{year:4,date:2,month:2,hours:2,minutes:2,seconds:2}};this.locales={en:{dayNames_long:['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],dayNames_short:['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],monthNames_long:['January','February','March','April','May','June','July','August','September','October','November','December'],monthNames_short:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']},fi:{dayNames_long:['Sunnuntai','Maanantai','Tiistai','Keskiviikko','Torstai','Perjantai','Lauantai'],dayNames_short:['Su','Ma','Ti','Ke','To','Pe','La'],monthNames_long:['Tammikuu','Helmikuu','Maaliskuu','Huhtikuu','Toukokuu','Kesäkuu','Heinäkuu','Elokuu','Syyskuu','Lokakuu','Marraskuu','Joulukuu'],monthNames_short:['Tammi','Helmi','Maalis','Huhti','Touko','Kesä','Heinä','Elo','Syys','Loka','Marras','Joulu']}};this.stringUtils={leftPad:function(val,length){return((length<=(val+='').length)?val:(Math.pow(10,length-val.length)+val).substr(1));},chop:function(str,length){return str.substr(str.length-length);}};this.formatters={DAYNAME_LONG:function(date){return''+this.locales[this.opts.locale].dayNames_long[date.getDay()];},DAYNAME_SHORT:function(date){return''+this.locales[this.opts.locale].dayNames_short[date.getDay()];},MONTHNAME_LONG:function(date){return''+this.locales[this.opts.locale].monthNames_long[date.getMonth()];},MONTHNAME_SHORT:function(date){return''+this.locales[this.opts.locale].monthNames_short[date.getMonth()];},DATE:function(date){return this.stringUtils.leftPad(date.getDate(),this.opts.digits.date);},MONTH:function(date){return this.stringUtils.leftPad((date.getMonth()+1),this.opts.digits.month);},YEAR:function(date){return this.stringUtils.chop(this.stringUtils.leftPad(date.getFullYear(),this.opts.digits.year),this.opts.digits.year);},HOURS:function(date){return this.stringUtils.leftPad(date.getHours(),this.opts.digits.hours);},MINUTES:function(date){return this.stringUtils.leftPad(date.getMinutes(),this.opts.digits.minutes);}};this.init=function(){$.extend(this.opts,this.userOptions);},this.getString=function(fmtStr){var self=this;for(var formatter in self.formatters){if(typeof(self.formatters[formatter])===typeof((function(){}))){var regexp=new RegExp("%D_"+formatter+"%","g");fmtStr=fmtStr.replace(regexp,self.formatters[formatter].call(self,self.date));}}
return fmtStr;};this.userOptions=opts;this.init();}

	window.DateFormatter = DateFormatter;
})(jQuery);
