#include "std.mi"

Function Fn_CharaChange();
Function Fn_FadeLayer(Layer l,int TargetA, Float Speed);
Function fn_MoveButton(Button b, int TargetX, int TargetY, int TargetW, int TargetH, Float SpeedW, Float SpeedH, int TargetA);

Global Group		grpMain;
Global Group		grpBg;
Global Group		grpFrame;
Global Group		grpAniVu;
Global Group		grpChara;
Global Group		grpCharaImage;
Global Group		grpChrSelect;
Global Button		btnChange;
Global Layer		lyrChrSelectBg;
Global Button		btnChrSelect;
Global Button		btnChrSelect2;
Global Button		btnChrSelect3;
Global Button		btnChrSelect4;
Global Button		btnChrSelect5;
Global Button		btnChrSelect6;
Global AnimatedLayer	aniAniVu;
Global AnimatedLayer	aniAniVu2;
Global AnimatedLayer	aniAniVu3;
Global AnimatedLayer	aniAniVu4;
Global AnimatedLayer	aniAniVu5;
Global AnimatedLayer	aniAniVu6;
Global Layer		lyrBg;
Global Layer		lyrBg2;
Global Layer		lyrBg3;
Global Layer		lyrBg4;
Global Layer		lyrBg5;
Global Layer		lyrBg6;
Global Layer		lyrChara;
Global Layer		lyrChara2;
Global Layer		lyrChara3;
Global Layer		lyrChara4;
Global Layer		lyrChara5;
Global Layer		lyrChara6;
Global Layer		lyrCharaBlack;
Global Layer		lyrCharaBlack2;
Global Layer		lyrCharaBlack3;
Global Layer		lyrCharaBlack4;
Global Layer		lyrCharaBlack5;
Global Layer		lyrCharaBlack6;
Global Layer		lyrCharaImage;
Global Layer		lyrCharaImage2;
Global Layer		lyrCharaImage3;
Global Layer		lyrCharaImage4;
Global Layer		lyrCharaImage5;
Global Layer		lyrCharaImage6;
Global int		intCharaNmber;	//( 0, 1, 2, 3, 4, 5)
Global Timer		tmrChange;
Global int		intChange;

System.onScriptLoaded() {

	grpMain 	= getScriptGroup();
	grpFrame 	= grpMain.findObject("Frame.Group");
	grpAniVu 	= grpMain.findObject("AniVu.Group");
	grpChara 	= grpMain.findObject("Chara.Group");
	grpBg		= grpMain.findObject("Bg.Group");
	grpCharaImage	= grpMain.findObject("CharaImage.Group");
	grpChrSelect	= grpMain.findObject("Chara_Select.Group");
	btnChange 	= grpFrame.findObject("Switch_Button");
	lyrChrSelectBg 	= grpChrSelect.findObject("Chara_Select_BG");
	btnChrSelect 	= grpChrSelect.findObject("Chara1_Select");
	btnChrSelect2 	= grpChrSelect.findObject("Chara2_Select");
	btnChrSelect3 	= grpChrSelect.findObject("Chara3_Select");
	btnChrSelect4 	= grpChrSelect.findObject("Chara4_Select");
	btnChrSelect5 	= grpChrSelect.findObject("Chara5_Select");
	btnChrSelect6 	= grpChrSelect.findObject("Chara6_Select");
	aniAniVu 	= grpAniVu.findObject("AniVu");
	aniAniVu2 	= grpAniVu.findObject("AniVu2");
	aniAniVu3 	= grpAniVu.findObject("AniVu3");
	aniAniVu4 	= grpAniVu.findObject("AniVu4");
	aniAniVu5 	= grpAniVu.findObject("AniVu5");
	aniAniVu6 	= grpAniVu.findObject("AniVu6");
	lyrBg		= grpBg.findObject("Bg");
	lyrBg2		= grpBg.findObject("Bg2");
	lyrBg3		= grpBg.findObject("Bg3");
	lyrBg4		= grpBg.findObject("Bg4");
	lyrBg5		= grpBg.findObject("Bg5");
	lyrBg6		= grpBg.findObject("Bg6");
	lyrChara 	= grpChara.findObject("Chara");
	lyrChara2 	= grpChara.findObject("Chara2");
	lyrChara3 	= grpChara.findObject("Chara3");
	lyrChara4 	= grpChara.findObject("Chara4");
	lyrChara5 	= grpChara.findObject("Chara5");
	lyrChara6 	= grpChara.findObject("Chara6");
	lyrCharaBlack 	= grpChara.findObject("Chara_Black");
	lyrCharaBlack2 	= grpChara.findObject("Chara2_Black");
	lyrCharaBlack3 	= grpChara.findObject("Chara3_Black");
	lyrCharaBlack4 	= grpChara.findObject("Chara4_Black");
	lyrCharaBlack5 	= grpChara.findObject("Chara5_Black");
	lyrCharaBlack6 	= grpChara.findObject("Chara6_Black");
	lyrCharaImage	= grpCharaImage.findObject("CharaImage");
	lyrCharaImage2	= grpCharaImage.findObject("CharaImage2");
	lyrCharaImage3	= grpCharaImage.findObject("CharaImage3");
	lyrCharaImage4	= grpCharaImage.findObject("CharaImage4");
	lyrCharaImage5	= grpCharaImage.findObject("CharaImage5");
	lyrCharaImage6	= grpCharaImage.findObject("CharaImage6");
	intCharaNmber	= System.getPrivateInt("Scarlet", "CharaNmber", 0);

	tmrChange = new Timer;

	Fn_CharaChange();
}

System.onScriptUnloading() {

	System.setPrivateInt("Scarlet", "CharaNmber", intCharaNmber);

	tmrChange.Stop();
	delete tmrChange;
}

btnChange.onLeftButtondown(int x,int y) {

	if(intChange == 0){
		Fn_MoveButton(btnChrSelect, 0, 0, 241, 58, 1.0, 1.0, 255);
		Fn_MoveButton(btnChrSelect2, 0, 57, 241, 58, 1.0, 1.0, 255);
		Fn_MoveButton(btnChrSelect3, 0, 114, 241, 58, 1.0, 1.0, 255);
		Fn_MoveButton(btnChrSelect4, 0, 171, 241, 58, 1.0, 1.0, 255);
		Fn_MoveButton(btnChrSelect5, 0, 228, 241, 58, 1.0, 1.0, 255);
		Fn_MoveButton(btnChrSelect6, 0, 285, 241, 58, 1.0, 1.0, 255);
		intChange = 1;

		lyrChrSelectBg.setTargetA(255);
       		lyrChrSelectBg.gotoTarget();
	}
	else if(intChange == 1){
		Fn_MoveButton(btnChrSelect, -241, 0, 241, 58, 1.0, 1.0, 0);
		Fn_MoveButton(btnChrSelect2, 240, 57, 241, 58, 1.0, 1.0, 0);
		Fn_MoveButton(btnChrSelect3, -241, 114, 241, 58, 1.0, 1.0, 0);
		Fn_MoveButton(btnChrSelect4, 240, 171, 241, 58, 1.0, 1.0, 0);
		Fn_MoveButton(btnChrSelect5, -241, 228, 241, 58, 1.0, 1.0, 0);
		Fn_MoveButton(btnChrSelect6, 240, 285, 241, 58, 1.0, 1.0, 0);
		intChange = 0;

		lyrChrSelectBg.setTargetA(0);
       		lyrChrSelectBg.gotoTarget();
	}

}

btnChrSelect.onLeftButtonUp(int x,int y) {

	intCharaNmber = 0;
	System.setPrivateInt("Scarlet", "CharaNmber", intCharaNmber);
	Fn_FadeLayer(lyrCharaImage, 255, 0.7);
	tmrChange.setDelay(1000);
	tmrChange.start();
	intChange = 0;

	btnChrSelect.setXMLParam("Ghost", "1");
	btnChrSelect2.setXMLParam("Ghost", "1");
	btnChrSelect3.setXMLParam("Ghost", "1");
	btnChrSelect4.setXMLParam("Ghost", "1");
	btnChrSelect5.setXMLParam("Ghost", "1");
	btnChrSelect6.setXMLParam("Ghost", "1");

	Fn_MoveButton(btnChrSelect, -241, 0, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect2, 240, 57, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect3, -241, 114, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect4, 240, 171, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect5, -241, 228, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect6, 240, 285, 241, 58, 1.0, 1.0, 0);

	lyrChrSelectBg.setTargetA(0);
       	lyrChrSelectBg.gotoTarget();
}

btnChrSelect2.onLeftButtonUp(int x,int y) {

	intCharaNmber = 1;
	System.setPrivateInt("Scarlet", "CharaNmber", intCharaNmber);
	Fn_FadeLayer(lyrCharaImage2, 255, 0.7);
	tmrChange.setDelay(1000);
	tmrChange.start();
	intChange = 0;

	btnChrSelect.setXMLParam("Ghost", "1");
	btnChrSelect2.setXMLParam("Ghost", "1");
	btnChrSelect3.setXMLParam("Ghost", "1");
	btnChrSelect4.setXMLParam("Ghost", "1");
	btnChrSelect5.setXMLParam("Ghost", "1");
	btnChrSelect6.setXMLParam("Ghost", "1");

	Fn_MoveButton(btnChrSelect, -241, 0, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect2, 240, 57, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect3, -241, 114, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect4, 240, 171, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect5, -241, 228, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect6, 240, 285, 241, 58, 1.0, 1.0, 0);

	lyrChrSelectBg.setTargetA(0);
       	lyrChrSelectBg.gotoTarget();
}
btnChrSelect3.onLeftButtonUp(int x,int y) {

	intCharaNmber = 2;
	System.setPrivateInt("Scarlet", "CharaNmber", intCharaNmber);
	Fn_FadeLayer(lyrCharaImage3, 255, 0.7);
	tmrChange.setDelay(1000);
	tmrChange.start();
	intChange = 0;

	btnChrSelect.setXMLParam("Ghost", "1");
	btnChrSelect2.setXMLParam("Ghost", "1");
	btnChrSelect3.setXMLParam("Ghost", "1");
	btnChrSelect4.setXMLParam("Ghost", "1");
	btnChrSelect5.setXMLParam("Ghost", "1");
	btnChrSelect6.setXMLParam("Ghost", "1");

	Fn_MoveButton(btnChrSelect, -241, 0, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect2, 240, 57, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect3, -241, 114, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect4, 240, 171, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect5, -241, 228, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect6, 240, 285, 241, 58, 1.0, 1.0, 0);

	lyrChrSelectBg.setTargetA(0);
       	lyrChrSelectBg.gotoTarget();
}
btnChrSelect4.onLeftButtonUp(int x,int y) {

	intCharaNmber = 3;
	System.setPrivateInt("Scarlet", "CharaNmber", intCharaNmber);
	Fn_FadeLayer(lyrCharaImage4, 255, 0.7);
	tmrChange.setDelay(1000);
	tmrChange.start();
	intChange = 0;

	btnChrSelect.setXMLParam("Ghost", "1");
	btnChrSelect2.setXMLParam("Ghost", "1");
	btnChrSelect3.setXMLParam("Ghost", "1");
	btnChrSelect4.setXMLParam("Ghost", "1");
	btnChrSelect5.setXMLParam("Ghost", "1");
	btnChrSelect6.setXMLParam("Ghost", "1");

	Fn_MoveButton(btnChrSelect, -241, 0, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect2, 240, 57, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect3, -241, 114, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect4, 240, 171, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect5, -241, 228, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect6, 240, 285, 241, 58, 1.0, 1.0, 0);

	lyrChrSelectBg.setTargetA(0);
       	lyrChrSelectBg.gotoTarget();
}
btnChrSelect5.onLeftButtonUp(int x,int y) {

	intCharaNmber = 4;
	System.setPrivateInt("Scarlet", "CharaNmber", intCharaNmber);
	Fn_FadeLayer(lyrCharaImage5, 255, 0.7);
	tmrChange.setDelay(1000);
	tmrChange.start();
	intChange = 0;

	btnChrSelect.setXMLParam("Ghost", "1");
	btnChrSelect2.setXMLParam("Ghost", "1");
	btnChrSelect3.setXMLParam("Ghost", "1");
	btnChrSelect4.setXMLParam("Ghost", "1");
	btnChrSelect5.setXMLParam("Ghost", "1");
	btnChrSelect6.setXMLParam("Ghost", "1");

	Fn_MoveButton(btnChrSelect, -241, 0, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect2, 240, 57, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect3, -241, 114, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect4, 240, 171, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect5, -241, 228, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect6, 240, 285, 241, 58, 1.0, 1.0, 0);

	lyrChrSelectBg.setTargetA(0);
       	lyrChrSelectBg.gotoTarget();
}

btnChrSelect6.onLeftButtonUp(int x,int y) {

	intCharaNmber = 5;
	System.setPrivateInt("Scarlet", "CharaNmber", intCharaNmber);
	Fn_FadeLayer(lyrCharaImage6, 255, 0.7);
	tmrChange.setDelay(1000);
	tmrChange.start();
	intChange = 0;

	btnChrSelect.setXMLParam("Ghost", "1");
	btnChrSelect2.setXMLParam("Ghost", "1");
	btnChrSelect3.setXMLParam("Ghost", "1");
	btnChrSelect4.setXMLParam("Ghost", "1");
	btnChrSelect5.setXMLParam("Ghost", "1");
	btnChrSelect6.setXMLParam("Ghost", "1");

	Fn_MoveButton(btnChrSelect, -241, 0, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect2, 240, 57, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect3, -241, 114, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect4, 240, 171, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect5, -241, 228, 241, 58, 1.0, 1.0, 0);
	Fn_MoveButton(btnChrSelect6, 240, 285, 241, 58, 1.0, 1.0, 0);

	lyrChrSelectBg.setTargetA(0);
       	lyrChrSelectBg.gotoTarget();
}

tmrChange.onTimer(){

	tmrChange.Stop();
	Fn_CharaChange();

	btnChrSelect.setXMLParam("Ghost", "0");
	btnChrSelect2.setXMLParam("Ghost", "0");
	btnChrSelect3.setXMLParam("Ghost", "0");
	btnChrSelect4.setXMLParam("Ghost", "0");
	btnChrSelect5.setXMLParam("Ghost", "0");
	btnChrSelect6.setXMLParam("Ghost", "0");

}


Fn_CharaChange() {

	if(intCharaNmber == 0){

	//Show()
		aniAniVu.Show();
		lyrBg.Show();
		lyrChara.Show();
		lyrCharaBlack.Show();
	//Hide()
		aniAniVu2.Hide();
		lyrBg2.Hide();
		lyrChara2.Hide();
		lyrCharaBlack2.Hide();
	//Hide()
		aniAniVu3.Hide();
		lyrBg3.Hide();
		lyrChara3.Hide();
		lyrCharaBlack3.Hide();
	//Hide()
		aniAniVu4.Hide();
		lyrBg4.Hide();
		lyrChara4.Hide();
		lyrCharaBlack4.Hide();

	//Hide()
		aniAniVu5.Hide();
		lyrBg5.Hide();
		lyrChara5.Hide();
		lyrCharaBlack5.Hide();
	//Hide()
		aniAniVu6.Hide();
		lyrBg6.Hide();
		lyrChara6.Hide();
		lyrCharaBlack6.Hide();

		Fn_FadeLayer(lyrCharaImage, 0, 0.7);

	}
	else if(intCharaNmber == 1){

	//Show()
		aniAniVu2.Show();
		lyrBg2.Show();
		lyrChara2.Show();
		lyrCharaBlack2.Show();
	//Hide()
		aniAniVu.Hide();
		lyrBg.Hide();
		lyrChara.Hide();
		lyrCharaBlack.Hide();
	//Hide()
		aniAniVu3.Hide();
		lyrBg3.Hide();
		lyrChara3.Hide();
		lyrCharaBlack3.Hide();
	//Hide()
		aniAniVu4.Hide();
		lyrBg4.Hide();
		lyrChara4.Hide();
		lyrCharaBlack4.Hide();
	//Hide()
		aniAniVu5.Hide();
		lyrBg5.Hide();
		lyrChara5.Hide();
		lyrCharaBlack5.Hide();
	//Hide()
		aniAniVu6.Hide();
		lyrBg6.Hide();
		lyrChara6.Hide();
		lyrCharaBlack6.Hide();

		Fn_FadeLayer(lyrCharaImage2, 0, 0.7);
	}

	else if(intCharaNmber == 2){

	//Show()
		aniAniVu3.Show();
		lyrBg3.Show();
		lyrChara3.Show();
		lyrCharaBlack3.Show();
	//Hide()
		aniAniVu.Hide();
		lyrBg.Hide();
		lyrChara.Hide();
		lyrCharaBlack.Hide();
	//Hide()
		aniAniVu2.Hide();
		lyrBg2.Hide();
		lyrChara2.Hide();
		lyrCharaBlack2.Hide();
	//Hide()
		aniAniVu4.Hide();
		lyrBg4.Hide();
		lyrChara4.Hide();
		lyrCharaBlack4.Hide();
	//Hide()
		aniAniVu5.Hide();
		lyrBg5.Hide();
		lyrChara5.Hide();
		lyrCharaBlack5.Hide();
	//Hide()
		aniAniVu6.Hide();
		lyrBg6.Hide();
		lyrChara6.Hide();
		lyrCharaBlack6.Hide();

		Fn_FadeLayer(lyrCharaImage3, 0, 0.7);
	}
	else if(intCharaNmber == 3){

	//Show()
		aniAniVu4.Show();
		lyrBg4.Show();
		lyrChara4.Show();
		lyrCharaBlack4.Show();
	//Hide()
		aniAniVu.Hide();
		lyrBg.Hide();
		lyrChara.Hide();
		lyrCharaBlack.Hide();
	//Hide()
		aniAniVu2.Hide();
		lyrBg2.Hide();
		lyrChara2.Hide();
		lyrCharaBlack2.Hide();
	//Hide()
		aniAniVu3.Hide();
		lyrBg3.Hide();
		lyrChara3.Hide();
		lyrCharaBlack3.Hide();
	//Hide()
		aniAniVu5.Hide();
		lyrBg5.Hide();
		lyrChara5.Hide();
		lyrCharaBlack5.Hide();
	//Hide()
		aniAniVu6.Hide();
		lyrBg6.Hide();
		lyrChara6.Hide();
		lyrCharaBlack6.Hide();

		Fn_FadeLayer(lyrCharaImage4, 0, 0.7);
	}
	else if(intCharaNmber == 4){

	//Show()
		aniAniVu5.Show();
		lyrBg5.Show();
		lyrChara5.Show();
		lyrCharaBlack5.Show();
	//Hide()
		aniAniVu.Hide();
		lyrBg.Hide();
		lyrChara.Hide();
		lyrCharaBlack.Hide();
	//Hide()
		aniAniVu2.Hide();
		lyrBg2.Hide();
		lyrChara2.Hide();
		lyrCharaBlack2.Hide();
	//Hide()
		aniAniVu3.Hide();
		lyrBg3.Hide();
		lyrChara3.Hide();
		lyrCharaBlack3.Hide();
	//Hide()
		aniAniVu4.Hide();
		lyrBg4.Hide();
		lyrChara4.Hide();
		lyrCharaBlack4.Hide();
	//Hide()
		aniAniVu6.Hide();
		lyrBg6.Hide();
		lyrChara6.Hide();
		lyrCharaBlack6.Hide();

		Fn_FadeLayer(lyrCharaImage5, 0, 0.7);
	}
	else if(intCharaNmber == 5){

	//Show()
		aniAniVu6.Show();
		lyrBg6.Show();
		lyrChara6.Show();
		lyrCharaBlack6.Show();
	//Hide()
		aniAniVu.Hide();
		lyrBg.Hide();
		lyrChara.Hide();
		lyrCharaBlack.Hide();
	//Hide()
		aniAniVu2.Hide();
		lyrBg2.Hide();
		lyrChara2.Hide();
		lyrCharaBlack2.Hide();
	//Hide()
		aniAniVu3.Hide();
		lyrBg3.Hide();
		lyrChara3.Hide();
		lyrCharaBlack3.Hide();
	//Hide()
		aniAniVu4.Hide();
		lyrBg4.Hide();
		lyrChara4.Hide();
		lyrCharaBlack4.Hide();
	//Hide()
		aniAniVu5.Hide();
		lyrBg5.Hide();
		lyrChara5.Hide();
		lyrCharaBlack5.Hide();

		Fn_FadeLayer(lyrCharaImage6, 0, 0.7);
	}
}

Fn_FadeLayer(Layer l,int TargetA, Float Speed) {

	l.setTargetA(TargetA);
	l.setTargetSpeed(Speed);
	l.gotoTarget();
}

Fn_MoveButton(Button b, int TargetX, int TargetY, int TargetW, int TargetH, Float SpeedW, Float SpeedH, int TargetA) {

        b.setTargetX(TargetX);
        b.setTargetY(TargetY);
        b.setTargetW(TargetW);
        b.setTargetH(TargetH);
        b.setTargetSpeed(SpeedW);
        b.setTargetSpeed(SpeedH);
        b.setTargetA(TargetA);
        b.gotoTarget();
}