ErrorLevel("off")
Include("Variables.mscr")
Call Variables
##############

#The following will close the active window.
#If there is no active window, it will launch the shutdown menu, instead.
#Exception #1: TaskMgr.exe doesn't have a window, so we have to check for it explicitly.
#Exception #2: MioMap gets minimized instead of closed.
#Exception #3: Apps by XFlib must be killed instead of closed.
#Exception #4: Media Player brings up a prompt to minimize or close.

If(ProcExists("MiniBar.exe"))
	MiniBarRunning = "true"
	Kill("MiniBar.exe")
EndIf

If(ProcExists("TaskMgr.exe"))
	Kill("TaskMgr.exe")
ElseIf(ActiveWindow() eq "MioMap")
	Minimize("MioMap")
	Exit
ElseIf(ActiveWindow() eq "Coded using XFlib")
	Kill(ActiveProcess())
ElseIf(ActiveWindow() eq "Player")
	Switch(Question("Choose YES to close Media Player or NO to minimize it","Close Media Player?","YesNo"))
	Case(Yes)
		Close("Player")
	Case(No)
		Minimize("Player")
	EndSwitch
ElseIf(ActiveWindow() eq "")
	Run(ScriptsFolder\"PowerPrompt.mscr")
Else
	Close(ActiveWindow())
EndIf

If(MiniBarRunning eq "true")
	Run(SkinFolder\"MiniBar\MiniBar.exe")
EndIf
