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

Global Group standardframeGroup, toastGroup;
Global Container StandardFrameContainer;
Global Layout StandardFrameNormalLayout;
Global animatedLayer toast;
Global Timer toasterTimer;
Global List frameList;
Global int frameNum;
System.onScriptLoaded(){
StandardFrameContainer = getContainer("StandardFrameContainer");
StandardFrameNormalLayout = StandardFrameContainer.getLayout("normal");
standardframeGroup = StandardFrameNormalLayout.getObject("studio.standardframe");
toastGroup  = standardframeGroup.getObject("toastgroup");
toast = toastGroup.getObject("toast");
toasterTimer = new Timer;
toasterTimer.setDelay(225);
frameList = new List;
frameList.addItem(3); frameList.addItem(2); frameList.addItem(1);
frameList.addItem(0); frameList.addItem(0); frameList.addItem(0);
frameList.addItem(0); frameList.addItem(0); frameList.addItem(0);
frameList.addItem(0); frameList.addItem(0); frameList.addItem(4);
frameList.addItem(5); frameList.addItem(6); frameList.addItem(7);
frameNum = 0;
}

System.onScriptUnloading(){
delete toasterTimer;
delete frameList;
}

toast.onLeftButtonUp(int x, int y){
toasterTimer.start();
}

toasterTimer.onTimer(){
if (frameNum<15){
	toast.gotoFrame(frameList.enumItem(frameNum) );
	frameNum++;
	}
else{
	frameNum=0;
	toasterTimer.stop();
	}

}