function calenderInit(){
	var obj			= getObj("calenderArea");
	obj._handler	= new calender(obj);
}

var calender = function(id){
	this.init.apply(this,arguments);
};

calender.prototype={
	_obj		: null,
	_prevBtn	: null,
	_nextBtn	: null,
	_month		: null,
	_detailObj	: null,
	init:function(obj){
		// days
		var dds = obj.getElementsByTagName("DD");
		for(var i=0; i<dds.length; i++){
			var dt = upSearchTagName(dds[i], "DT");
			if(!dt._handler){
				dt._handler = new calenderNode(this, dt);
			}
		}
		
		// current Month
		var rex			= new RegExp("[0-9][0-9][0-9][0-9]年[0-9][0-9]?月");
		this._month		= obj.getElementsByTagName("STRONG")[0].innerHTML.match(rex).toString();//.replace("年", "-");

		// detailBox
		this._detailObj	= this.makeDetailObj();
		
		// buttons
		this._prevBtn	= obj.getElementsByTagName("A")[0];
		this._nextBtn	= obj.getElementsByTagName("A")[1];
		addEvent(this._prevBtn, "mousedown", this.bind(this.prevBtnListener));
		addEvent(this._nextBtn, "mousedown", this.bind(this.nextBtnListener));
		addEvent(this._detailObj, "mouseout", this.bind(this.mouseoutListener));
	},
	mouseoutListener:function(){
		var e = window.event?window.event:arguments.callee.caller.arguments[0];
//		var overObj = e.target || e.toElement;
		var outObj = e.relatedTarget || e.toElement;
		if(!contains(this._detailObj, outObj)){
			this.hideDetail();
		}
	},
	makeDetailObj:function(){
		// elements
		var boxObj	= document.createElement("DIV");
		var bgObj	= document.createElement("DIV");
		var bodyObj	= document.createElement("DIV");
		
		// style
		setClass(boxObj, "calenderDetail");
		setClass(bgObj, "bg");
		setClass(bodyObj, "body");
		
		bgObj.innerHTML = "&nbsp;"
		bodyObj.innerHTML = "&nbsp;"
		
		boxObj.appendChild(bgObj);
		boxObj.appendChild(bodyObj);
		document.body.appendChild(boxObj);
		
		return boxObj;
	},
	prevBtnListener:function(){
	},
	nextBtnListener:function(){
	},
	showDetail:function(nodeObj){		
		// html
		this._detailObj.getElementsByTagName("DIV")[1].innerHTML = nodeObj._bodyHTML;

		// style
		this._detailObj.style.display	= "block";
		var position					= cumulativeOffset(nodeObj._dayObj);
		this._detailObj.style.left		= position[0] + 10 + "px";
		this._detailObj.style.top		= position[1] + 10 + "px";
	},
	hideDetail:function(){
		this._detailObj.style.display	= "none";
	},
	bind:function(method,arg){
		var _this=this;var _arg=(arg)?arg:[];
		return function(){
			method.apply(_this,_arg);
		}
	}
};

var calenderNode = function(id){
	this.init.apply(this,arguments);
};

calenderNode.prototype={
	_calenderObj	: null,
	_dayObj			: null,
	_bodyHTML		: null,
	_day			: null,
	init:function(calenderObj, dayObj){
		this._calenderObj	= calenderObj;
		this._dayObj		= dayObj;
		this._bodyHTML		= "";
		this._day			= dayObj.innerHTML;

		// body
		var obj = this._dayObj.nextSibling;
		while(obj && obj.tagName != "DT"){
			if(obj.tagName == "DD"){
				this._bodyHTML += obj.innerHTML;
			}
			obj = obj.nextSibling;
		}
		
		// enable
		if(this._bodyHTML){
			// style
//			this._dayObj.style.cursor			= "pointer";
//			this._dayObj.style.backgroundColor	= "#EEEEEE";
			
			// event
			addEvent(this._dayObj, "mouseover", this.bind(this.mouseoverListener));
			addEvent(this._dayObj, "mouseout", this.bind(this.mouseoutListener));
		}
	},
	mouseoverListener:function(){
		this._calenderObj.showDetail(this);
	},
	mouseoutListener:function(){
		var e = window.event?window.event:arguments.callee.caller.arguments[0];
//		var overObj = e.target || e.toElement;
		var outObj = e.relatedTarget || e.toElement;
		if(!contains(this._calenderObj._detailObj, outObj)){
			this._calenderObj.hideDetail();
		}
	},
	bind:function(method,arg){
		var _this=this;var _arg=(arg)?arg:[];
		return function(){
			method.apply(_this,_arg);
		}
	}
};

addEvent(window, "load", calenderInit);

