#include <lib/std.mi>

Function plresize(int h, int w);
Function doortoggle(int h);

Global Group Topdoor, Bottomdoor, frameGroup, Overlay;
Global Layer Toplogo, BottomLogo;
Global Timer doorTimer;
Global Guiobject pleditor;
Global Boolean doorState, doorPL;

System.onScriptLoaded() {
	frameGroup = getScriptGroup();

	pleditor = framegroup.findObject("playlist.content");

	Topdoor = framegroup.findObject("playlist.topdoor");
	Bottomdoor = framegroup.findObject("playlist.bottomdoor");

	Toplogo = framegroup.findObject("topdoor.logo");
	Bottomlogo = framegroup.findObject("bottomdoor.logo");

	Overlay = frameGroup.findObject("playlist.overlay");

	doorState = 1;

	doorPL = system.getPrivateInt(getSkinName(), "doorPL", 0);

	if(doorPL) {
		pleditor.hide();

		plresize(framegroup.getHeight(), framegroup.getWidth());

		doorTimer = new Timer;
		doorTimer.setDelay(300);
		doorTimer.start();
	} else {
		Topdoor.hide();
		Toplogo.hide();
		Bottomdoor.hide();
		Bottomlogo.hide();

		Overlay.hide();

		pleditor.show();
	}
}

System.onScriptUnloading() {
  delete doorTimer;
}

plresize(int h, int w) {
		Topdoor.setXmlParam("h", integerToString((h-48)/2));
		Toplogo.setXmlParam("x", integerToString((w-44)/2-47));

		Bottomdoor.setXmlParam("h", integerToString((h-48)/2));
		Bottomdoor.setXmlParam("y", integerToString((h-48)/2+24));
		Bottomlogo.setXmlParam("x", integerToString((w-44)/2-61));
}

framegroup.onresize(int x, int y, int w, int h) {
	if(doorPL) plresize(h, w);
}

doorTimer.onTimer() {
	doortoggle(framegroup.getHeight());
	doorTimer.stop();
}

doortoggle(int h) {
	if(doorstate) {
	int toph = Topdoor.getXmlParam("h");

	Topdoor.setTargetY(24-toph);
	Topdoor.setTargetSpeed(3);
	Topdoor.gotoTarget();

	Bottomdoor.setTargetY((h-48)/2+(h-48)/2+24);
	Bottomdoor.setTargetSpeed(3);
	Bottomdoor.gotoTarget();

	doorState = 0;
	} else {
	Topdoor.setXmlParam("h", integerToString((h-48)/2));
	Topdoor.setTargetY(24);
	Topdoor.setTargetSpeed(3);
	Topdoor.gotoTarget();

	Bottomdoor.setXmlParam("h", integerToString((h-48)/2));
	Bottomdoor.setTargetY((h-48)/2+24);
	Bottomdoor.setTargetSpeed(3);
	Bottomdoor.gotoTarget();

	doorState = 1;
	}
}

//DoorBtn.onLeftButtonUp(int x, int y) {
//	if(doorPL) {
//	Topdoor.setXmlParam("h", integerToString((framegroup.getHeight()-48)/2));
//	Topdoor.setXmlParam("y", integerToString(24-Topdoor.getHeight()));
//	Toplogo.setXmlParam("x", integerToString((framegroup.getWidth()-44)/2-47));
//
//	Bottomdoor.setXmlParam("h", integerToString((framegroup.getHeight()-48)/2));
//	Bottomdoor.setXmlParam("y", integerToString((framegroup.getHeight()-48)/2+(framegroup.getHeight()-48)/2+24));
//	Bottomlogo.setXmlParam("x", integerToString((framegroup.getWidth()-44)/2-61));
//
//	Overlay.Show();
//	Overlay.setTargetA(255);
//	Overlay.setTargetSpeed(0.5);
//	Overlay.gotoTarget();
//	} else {
//	CloseBtn.leftClick();
//	}
//}

Topdoor.onTargetReached() {
	if(!doorState) {
		pleditor.show();

		Overlay.setTargetA(0);
		Overlay.setTargetSpeed(0.5);
		Overlay.gotoTarget();

		Topdoor.hide();
		Bottomdoor.hide();
//	} else {
//		CLoseBtn.leftClick();
	}
}

Overlay.onTargetReached() {
	if(Overlay.getAlpha()==0) Overlay.hide();
	else {
		Topdoor.show();
		Bottomdoor.show();
		pleditor.hide();
		doortoggle(framegroup.getHeight());
	}
}