function calendarClass(){
	this.monthName  = new Array("","January","February","March","April","May","June","July","August","September","October","November","December");
	this.dayName  = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	this.monthDays  = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	this.classNames = new Array('blank','today','sunday','weekday','saturday','holiday');
	this.today = new Date();
	this.year = this.today.getYear();
	if (this.year < 2000) { this.year = this.year + 1900; }
	this.month = this.today.getMonth() + 1;
	this.date = this.today.getDate();
	this.currentID;
	
	this.zerofull = function( aNum ){
		var str = "0" + aNum;
		return str.substr(str.length - 2);
	};
	
	this.getCurrentID = function(){
		return this.year + this.zerofull(this.month) + this.zerofull(this.date);
	};
	
	// イベントを登録する
	this.addEvent = function ( elem, ev, func ) {
	//  prototype.js があれば利用する(IEメモリリーク回避)
		if ( window.Event && Event.observe ) {
			/*Event.stopObserving( elem, ev, func );*/
			Event.observe( elem, ev, func, false );
		} else {
			elem["on"+ev] = func;
		}
	}
	
	this.tagYear = this.year;
	this.tagMonth = this.month;
	this.tagElement;
	
	this.makeNear = function( dir ){
		this.tagMonth += dir;
		if( this.tagMonth == 0 ){
			this.tagMonth = 12;
			this.tagYear -= 1;
		} else if( this.tagMonth == 13 ){
			this.tagMonth = 1;
			this.tagYear += 1;
		}
		this.make( this.tagElement );
	}
	
	this.make = function( elmID,nYear,nMonth ){
		if( !document.getElementById(elmID) ){
			return;
		}
		this.tagElement = elmID;
		if( isNaN(nYear) ){
			nYear = this.tagYear;
		} else {
			this.tagYear = nYear;
		}
		if( isNaN(nMonth) ){
			nMonth = this.tagMonth;
		} else {
			this.tagMonth = nMonth;
		}
		
		var firstDate  = new Date(nYear,(nMonth-1),1);
		//対象月の初日の曜日
		var firstDay    = firstDate.getDay();
		//閏年2月の補正
		if (((nYear % 4 == 0) && (nYear % 100 != 0)) || (nYear % 400 == 0)) { 
			this.monthDays[2] = 29;
		} else {
			this.monthDays[2] = 28;
		}
		var datePtr = 1 - firstDay;
		var kyujitu = 0;
		var furikae = 0;
		var MonthWeeks = Math.floor((this.monthDays[nMonth]+firstDay+6)/7);
		var substitute = false;
		var idbase = nYear + this.zerofull(nMonth);
		
		var outerHTML = '<p><a href="javascript:void();" id="prevCalendar" onclick="return otherCalendar( -1 );">[←]</a><a href="javascript:void();" id="nextCalendar" onclick="return otherCalendar( 1 );">[→]</a>' + this.monthName[nMonth] + " - " + nYear + '</p>';
		outerHTML += '<table border="0" cellspacing="0" cellpadding="0">';
		outerHTML += '<tr><th>' + this.dayName[0] + '</th>';
		outerHTML += '<th>' + this.dayName[1] + '</th>';
		outerHTML += '<th>' + this.dayName[2] + '</th>';
		outerHTML += '<th>' + this.dayName[3] + '</th>';
		outerHTML += '<th>' + this.dayName[4] + '</th>';
		outerHTML += '<th>' + this.dayName[5] + '</th>';
		outerHTML += '<th>' + this.dayName[6] + '</th></tr>';
		
		var curID = this.getCurrentID();
		for(w=1 ; w<=MonthWeeks ; w++) {
			outerHTML += '<tr>';
			for(d=1 ; d<=7 ; d++) {
				if(datePtr<= 0 || datePtr > this.monthDays[nMonth]) {
					outerHTML += '<td class="' + this.classNames[0] + '">&nbsp;</td>';
				} else {
					classIs = 3;
					idstr = idbase + this.zerofull(datePtr);
					kyujitu = this.holiday(nYear,nMonth,datePtr,firstDay);
					if (kyujitu != "" ){
						classIs = 5;
						if( d ==1 ){
							substitute = true;
						}
					} else if (d == 1 ){
						classIs = 2;
					} else if (substitute){
						classIs = 5;
						kyujitu = "振り替え休日";
						substitute = false;
					} else if ( d == 7 ){
						classIs = 4;
					}
					outerHTML += '<td id="' + idstr + '" class="' + this.classNames[classIs];
					if( true ){ outerHTML += ' clicker'; }
					if( idstr == curID ){ outerHTML += ' today'; }
					outerHTML += '" onclick="dayClick(this,event)" title="' + kyujitu + '">' + datePtr + '</td>';
				}
				datePtr++;
			}
			outerHTML += '</tr>';
		}
		outerHTML += '</table>';
		document.getElementById(this.tagElement).innerHTML = outerHTML;
		/*
		var __this = this;
		// 前の月へボタン
		var btn_prev = document.getElementById( "prevCalendar" );
		this.addEvent( btn_prev, "click", function(){ __this.makeNear( -1 ); });
		// 次の月へボタン
		var btn_next = document.getElementById( "nextCalendar" );
		this.addEvent( btn_next, "click", function(){ __this.makeNear( 1 ); });
		*/
	};

	// * -------------------------------------------------- *
	// yy,m,dd が祝日かどうかを調べる
	//
	//　・firstDayはその月の1日の曜日を示す数値
	//　・戻り値は祝日名、あるいは""
	
	this.holiday = function( yy,mm,dd,firstDay ){
		//月の補正
		var fd = (firstDay + 5) % 7;
		var xday = 0;
		
		if( mm == 1 ){
			if( dd == 1 ){ return("元旦");
			} else if( yy>=2000 && dd == 14 - fd) { return("成人の日"); //第２月曜
			} else if( yy<2000 && dd == 15) { return("成人の日"); //1999年まで、15日
			}
		} else if( mm == 2 ){
			if( dd == 11 ){ return("建国記念の日");　//1967年（昭和42年）〜：かつての紀元節
			}
		} else if( mm == 3 ){
			if( dd == Math.floor(20.712662+0.242199*(yy-1996)-Math.floor((yy-1996)/4)) ){ return("春分の日");
			}
		} else if( mm == 4 ){
			if( dd==29 ){
				if( yy >=2007 ){ return("昭和の日"); }  // 2007年～
				else if( yy>=1989 ){ return("みどりの日"); } // 1989年～2006年
				else { return("天皇誕生日"); } // 〜1988年（昭和63年）
			}
		} else if( mm == 5 ){
			if( dd == 3 ){ return("憲法記念日"); } 
			else if( dd == 4) { 
				if( yy>=2007 ){ return("みどりの日"); }
				else if( yy>=1988 ){ return("国民の休日"); } } 
			else if( dd == 5) { return("こどもの日"); }
		} else if( mm == 7 ){
			if( yy>=2003 && dd == 21 - fd ){ return("海の日"); //第３月曜
			} else if( yy<2003 && yy>=1996 && dd == 20) { return("海の日"); //2002年まで、20日
			}
		} else if( mm == 9 ){
			shuubun = Math.floor(23.130023+0.242199*(yy-1996)-Math.floor((yy-1996)/4));
			if( yy>=2003 && dd == 21 - fd ){ return("敬老の日"); //第３月曜
			} else if( yy<2003 && yy>=1966 && dd == 15) { return("敬老の日"); //2002年まで、15日
			} else if( dd == shuubun) { return("秋分の日"); 
			} else if( dd == 22 ) {
				xday = new Date(yy,mm-1,shuubun);
				if( xday.getDay() == 3 ){
					return("国民の休日"); 
				}
			}
		} else if( mm == 10 ){
			if( yy>=2000 && dd == 14 - fd ){ return("体育の日"); //第２月曜
			} else if( yy<2000 && yy>=1966 && dd == 10) { return("体育の日"); //1999年まで、10日
			}
		} else if( mm == 11 ){
			if( dd == 3 ){ return("文化の日"); 
			} else if( dd == 23) { return("勤労感謝の日"); 
			}
		} else if( mm == 12 ){
			if( yy>=1989 && dd == 23 ){ return("文天皇誕生日"); 
			}
		} else {
			return(""); 
		}
		return(""); 
	};


}

