#include "std.mi"
/**************************************************************************************************
 ■自作関数宣言
***************************************************************************************************/
Function fn_StartAnim(AnimatedLayer l, int start, int end, int speed, int rep); //アニメ関数

/**************************************************************************************************
 ■グローバル関数宣言
***************************************************************************************************/
Global Group		grpMain;
Global Group		grpCalendar;
Global animatedlayer	aniMonth;
Global animatedlayer	aniWeek;
Global animatedlayer	aniDay;
Global animatedlayer	aniDay2;
Global Timer 		monthTmr;
Global Timer 		weekTmr;
Global Timer 		dayTmr;
Global Int 		datetime;

/**************************************************************************************************
// #System.onScriptLoaded()
//  条件：スクリプト起動時に呼び出される
//  機能：初期設定を行う
***************************************************************************************************/

System.onScriptLoaded() {
	
	//オブジェクト設定
	grpMain 	= getScriptGroup();
	grpCalendar	= grpMain.getObject("Calendar.Group");
	AniMonth	= grpCalendar.getObject("CalendarMonth");
	AniWeek		= grpCalendar.getObject("CalendarWeek");
	AniDay		= grpCalendar.getObject("Calendarday");
	AniDay2		= grpCalendar.getObject("Calendarday2");
	
	//タイマー設定
	MonthTmr= new Timer;
	WeekTmr = new Timer;
	DayTmr 	= new Timer;
	
	MonthTmr.setDelay(50);
	WeekTmr.setDelay(50);
	DayTmr.setDelay(50);
	
	MonthTmr.start();
	WeekTmr.start();
	DayTmr.start();
	
	//datetimeの取得
	datetime = System.getDate();
}

/**************************************************************************************************
// #System.onScriptUnloading()
//  条件：スクリプト終了時に呼び出される
//  機能：設定保存と単曲リピートの退避処理を行う
***************************************************************************************************/

System.onScriptUnloading() {
  
	delete MonthTmr;
  	delete WeekTmr;
	delete DayTmr;
}

/**************************************************************************************************
// #MonthTmr.onTimer()
//  条件：MonthTmrの時間に呼び出される
//  機能：
***************************************************************************************************/
MonthTmr.onTimer() {
		
	datetime = System.getDate();

	if(getDateMonth(datetime) == 0){
		fn_StartAnim(AniMonth, 1, 1, 0, 0);
	}
	else if(getDateMonth(datetime) == 1){
		fn_StartAnim(AniMonth, 2, 2, 0, 0);
	}
	else if(getDateMonth(datetime) == 2){
		fn_StartAnim(AniMonth, 3, 3, 0, 0);
	}
	else if(getDateMonth(datetime) == 3){
		fn_StartAnim(AniMonth, 4, 4, 0, 0);
	}
	else if(getDateMonth(datetime) == 4){
		fn_StartAnim(AniMonth, 5, 5, 0, 0);
	}
	else if(getDateMonth(datetime) == 5){
		fn_StartAnim(AniMonth, 6, 6, 0, 0);
	}
	else if(getDateMonth(datetime) == 6){
		fn_StartAnim(AniMonth, 7, 7, 0, 0);
	}
	else if(getDateMonth(datetime) == 7){
		fn_StartAnim(AniMonth, 8, 8, 0, 0);
	}
	else if(getDateMonth(datetime) == 8){
		fn_StartAnim(AniMonth, 9, 9, 0, 0);
	}
	else if(getDateMonth(datetime) == 9){
		fn_StartAnim(AniMonth, 10, 10, 0, 0);
	}
	else if(getDateMonth(datetime) == 10){
		fn_StartAnim(AniMonth, 11, 11, 0, 0);
	}
	else if(getDateMonth(datetime) == 11){
		fn_StartAnim(AniMonth, 12, 12, 0, 0);
	}
	else if(getDateMonth(datetime) == 12){
		fn_StartAnim(AniMonth, 12, 12, 0, 0);
	}
}
/**************************************************************************************************
// #WeekTmr.onTimer()
//  条件：WeekTmrの時間に呼び出される
//  機能：
***************************************************************************************************/
WeekTmr.onTimer() {

	datetime = System.getDate();

	if(getDateDow(datetime) == 0){
		fn_StartAnim(AniWeek, 7, 7, 0, 0);
	}
	else if(getDateDow(datetime) == 1){
		fn_StartAnim(AniWeek, 1, 1, 0, 0);
	}
	else if(getDateDow(datetime) == 2){
		fn_StartAnim(AniWeek, 2, 2, 0, 0);
	}
	else if(getDateDow(datetime) == 3){
		fn_StartAnim(AniWeek, 3, 3, 0, 0);
	}
	else if(getDateDow(datetime) == 4){
		fn_StartAnim(AniWeek, 4, 4, 0, 0);
	}
	else if(getDateDow(datetime) == 5){
		fn_StartAnim(AniWeek, 5, 5, 0, 0);
	}
	else if(getDateDow(datetime) == 6){
		fn_StartAnim(AniWeek, 6, 6, 0, 0);
	}
}

/**************************************************************************************************
// #DayTmr.onTimer()
//  条件：DayTmrの時間に呼び出される
//  機能：
***************************************************************************************************/
DayTmr.onTimer() {

	datetime = System.getDate();

	if(getDateDay(datetime) == 1){
		fn_StartAnim(AniDay, 1, 1, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 2){
		fn_StartAnim(AniDay, 2, 2, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 3){
		fn_StartAnim(AniDay, 3, 3, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 4){
		fn_StartAnim(AniDay, 4, 4, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 5){
		fn_StartAnim(AniDay, 5, 5, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 6){
		fn_StartAnim(AniDay, 6, 6, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 7){
		fn_StartAnim(AniDay, 7, 7, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 8){
		fn_StartAnim(AniDay, 8, 8, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 9){
		fn_StartAnim(AniDay, 9, 9, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 10){
		fn_StartAnim(AniDay, 10, 10, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 11){
		fn_StartAnim(AniDay, 11, 11, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 12){
		fn_StartAnim(AniDay, 12, 12, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 13){
		fn_StartAnim(AniDay, 13, 13, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 14){
		fn_StartAnim(AniDay, 14, 14, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}
	else if(getDateDay(datetime) == 15){
		fn_StartAnim(AniDay, 15, 15, 0, 0);
		AniDay2.Hide();
		AniDay.Show();
	}


	else if(getDateDay(datetime) == 16){
		fn_StartAnim(AniDay2, 1, 1, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 17){
		fn_StartAnim(AniDay2, 2, 2, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 18){
		fn_StartAnim(AniDay2, 3, 3, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 19){
		fn_StartAnim(AniDay2, 4, 4, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 20){
		fn_StartAnim(AniDay2, 5, 5, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 21){
		fn_StartAnim(AniDay2, 6, 6, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 22){
		fn_StartAnim(AniDay2, 7, 7, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 23){
		fn_StartAnim(AniDay2, 8, 8, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 24){
		fn_StartAnim(AniDay2, 9, 9, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 25){
		fn_StartAnim(AniDay2, 10, 10, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 26){
		fn_StartAnim(AniDay2, 11, 11, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 27){
		fn_StartAnim(AniDay2, 12, 12, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 28){
		fn_StartAnim(AniDay2, 13, 13, 0, 0);
		AniDay.Hide();
	}
	else if(getDateDay(datetime) == 29){
		fn_StartAnim(AniDay2, 14, 14, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 30){
		fn_StartAnim(AniDay2, 15, 15, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
	else if(getDateDay(datetime) == 31){
		fn_StartAnim(AniDay2, 16, 16, 0, 0);
		AniDay.Hide();
		AniDay2.Show();
	}
}
/*--------------自作関数------------------------------------------------------*/

/**************************************************************************************************
// #fn_StartAnim(
//      AnimatedLayer   l,      //アニメーションさせるオブジェクト
//      int             start,  //スタートフレーム
//      int             end,    //終了フレーム
//      int           speed,  //1フレームのアニメーション速度
// )
//
// 機能：アニメーションをスタートさせる
***************************************************************************************************/
fn_StartAnim(AnimatedLayer l, int start, int end, int speed,int rep) 
{
    l.stop();
    l.setStartFrame(start);
    l.setEndFrame(end);
    l.setSpeed(speed);
    l.setAutoReplay(rep);
    l.play();
}


