
Object.extend(Object.extend('core.ui.Calendar.prototype',core.ui),{
	allMonth:[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31],
	allWeek:['日','一','二','三', '四', '五', '六'],
	className:'Calendar',
	create:function(o){
		var t = this,d = new Date();
		if(!o)t.options=Object.extend(t.options,{width:0,height:0,year:d.getFullYear(),month:d.getMonth(),today:d.getDate()});
		var t = this,o=t.options,first=new Date(o.year,o.month,1);startDay=first.getDay(),monthDay=t.allMonth[o.month]+startDay,count=monthDay%7==0?monthDay:monthDay+7-monthDay%7,ul = "<ul>",m=new Date();
		
		for(var i=0;i<count;i++){
			var s = "",day=0;
			if(i>=startDay && i<monthDay)s=i-startDay+1;
			day=new Date(o.year,o.month,s+1)>m&&s!=''?1:0;
			ul+="<li "+(!day?"":"class='item' onmouseover=\"this.className='over'\" onmouseout=\"this.className='item'\"")+">"+s+"</li>";
			if(i+1%7==0) ul+='</ul><ul>';
		}
		t.element.innerHTML=t.header()+t.title()+ul+'</ul>';
		
		$('#'+t.id()+" ul .item").click(function(){o.day=this.innerHTML;if(o.onchange)o.onchange(o)});
		$('#'+t.id()+" .header 0,2").click(function(){t.update(this.innerHTML=="&lt;&lt;"?0:1);});
	},
	update:function(add){
		var o = this.options;
		
		add?o.month<11?o.month++:(o.month=0,o.year++):o.month>0?o.month--:(o.month=11,o.year--);
		
		this.create(o);
	},
	title:function(){var t="<ul class='title'>";this.allWeek.each(function(i){t+='<li>'+i+'</li>'});return t+'</ul>'},
	header:function(){return "<ul class='header'><li>&lt;&lt;</li><li class='center'>"+this.options.year+" - "+(this.options.month+1)+"</li><li>&gt;&gt;</li></ul>"}
});