#include "../../../lib/std.mi" 

Function SwitchLight();

Global Layer BackLight, Light;
Global Group SoftLight;
Global Text Songticker;
Global Checkbox DISPLAYCheck;
Global Boolean BackLightMode;

System.onScriptLoaded() { 

	Group BackLightGrp = system.getContainer("Main").getLayout("normal");
	Group ConfigGrp = system.getContainer("config").getLayout("normal");

	BackLight = BackLightGrp.findObject("BackLight");
	Light = BackLightGrp.findObject("Light");
	SoftLight = BackLightGrp.findObject("SoftLightGrp");

	Songticker = BackLightGrp.findObject("Songticker");

	DISPLAYCheck = ConfigGrp.findObject("config.display.on");
	DISPLAYCheck.setChecked(system.getPrivateInt(getSkinName(), "BackLightMode", 1));

	BackLightMode = getPrivateInt(getSkinName(), "BackLightMode", 1);

	if(BackLightMode) {
		Light.setXmlParam("Alpha", "150");
		SoftLight.setXmlParam("Alpha", "200");
	} else SoftLight.hide();
}

System.onScriptUnloading() {
}

DISPLAYCheck.onToggle(boolean on) {
	system.setPrivateInt(getSkinName(), "BackLightMode", on);
	if(on) BackLightMode = 0;
	else BackLightMode = 1;
	SwitchLight();
}

Light.onTargetReached() {
	if(BackLightMode) {
		SoftLight.show();
		SoftLight.setTargetA(200);
		SoftLight.setTargetSpeed(0.5);
		SoftLight.gotoTarget();
	}
}

SoftLight.onTargetReached() {
	if(!BackLightMode) {
		Light.setTargetA(0);
		Light.setTargetSpeed(0.5);
		Light.gotoTarget();
		SoftLight.hide();
	}
}

SwitchLight() {
	if(!SoftLight.isGoingtoTarget() || !Light.isGoingtoTarget()) {
		if(BackLightMode) {
			BackLightMode=0;
			SoftLight.setTargetA(0);
			SoftLight.setTargetSpeed(0.5);
			SoftLight.gotoTarget();
			setPrivateInt(getSkinName(), "BackLightMode", BackLightMode);
		} else {
			BackLightMode=1;
			Light.setTargetA(150);
			Light.setTargetSpeed(0.5);
			Light.gotoTarget();
			setPrivateInt(getSkinName(), "BackLightMode", BackLightMode);
		}
	}
}