Dim cxClient
Dim cyClient
Dim SC_MINIMIZE 
Dim SC_MAXIMIZE
Dim SC_CLOSE 
Dim SC_RESTORE 
Dim SS_RESTORED
Dim SS_MINIMIZED
Dim SS_MAXIMIZED
Dim MIN_WIDTH
Dim MIN_HEIGHT
Dim IsWindowMaxmized


Sub Window_OnInit()
	SC_MINIMIZE				= 61472
	SC_MAXIMIZE				= 61488
	SC_CLOSE				= 61536
	SC_RESTORE				= 61728
	SS_RESTORED				= 0
	SS_MINIMIZED			= 1
	SS_MAXIMIZED			= 2
	window.minWidth         = 210
	window.minHeight        = 231
End Sub

sub WindowLayOut()	
	Window.LockPaint()
	
	CaptionBar.width = cxClient - CaptionLeftSide.width - CaptionRightSide.width
	CaptionBarBtns.left  = CaptionBar.left + CaptionBar.width - CaptionBarBtns.width
	CaptionMiddle.width = CaptionBar.width
	Caption.width = CaptionBarBtns.left - Caption.left - 30 

	CaptionRightSide.left = cxClient - CaptionRightSide.width

	ShowMainArea.width = cxClient - LeftSide.width - RightSide.width
	ShowMainArea.height = cyClient - CaptionBarBtns.height - BottomBar.height
	ShowBox.width = ShowMainArea.width
	ShowBox.height = ShowMainArea.height
	RightSide.left = cxClient - RightSide.width
	RightSide.height = ShowMainArea.height
	LeftSide.height = ShowMainArea.height		
	
	BottomBar.top = cyClient - BottomBar.height
	BottomBar.width = cxClient 
	BottomMiddle.width = BottomBar.width - BottomLeft.width - BottomRight.width
	BottomRight.left = cxClient - BottomRight.width
	
	Window.UnLockPaint()
end sub	

Sub Window_OnNotify(code ,var)
	if (code =  1) then
		Dim Wndwidth
		Wndwidth= var.GetInt("nVedioShowBoxWidth")
		Dim Wndheight
		Wndheight= var.GetInt("nVedioShowBoxHeight")	
		'if(Wndwidth < MIN_WIDTH)then
		'	Wndwidth = MIN_WIDTH
		'end if	
		'if(Wndheight < MIN_HEIGHT)then
		'	Wndheight = MIN_HEIGHT
		'end if	
		cxClient = Wndwidth + LeftSide.width + RightSide.width 
		cyClient = Wndheight + CaptionBarBtns.height + BottomBar.height		
				
		WindowLayOut()		
	elseif(code = 2) then
		if(var = 0) then
			btnCaptionTopmost.image = "BTN_SYS_TOPOFFnormal.bmp"
			btnCaptionTopmost.hoverImage = "BTN_SYS_TOPOFFmouseover.bmp"
			btnCaptionTopmost.downImage = "BTN_SYS_TOPOFFpress.bmp"
		else
			btnCaptionTopmost.image = "BTN_SYS_TOPnormal.bmp"
			btnCaptionTopmost.hoverImage = "BTN_SYS_TOPmouseover.bmp"
			btnCaptionTopmost.downImage = "BTN_SYS_TOPpress.bmp"				
		end if
	elseif(code = 3)then
		Caption.value = var	
		WindowLayOut()
	elseif(code = 4)then
		WindowLayOut()
	end if	
End Sub

Sub Window_OnChildCommand( childId, code )
End Sub

sub Window_WindowLayOut(cx, cy, wndState)	
	
	'if(cx < MIN_WIDTH)then
	'	cx = MIN_WIDTH
	'end if	
	'if(cy < MIN_HEIGHT)then
	'	cy = MIN_HEIGHT
	'end if	

	cxClient = cx 
	cyClient = cy 
	If(wndState = SS_RESTORED) Then
		IsWindowMaxmized = false
	ElseIf (wndState = SS_MAXIMIZED) Then
		IsWindowMaxmized = true
	End if
	WindowLayOut()	
end Sub

Sub Window_OnShowStateChange(nCmdShow)
	If nCmdShow = SS_RESTORED Then
		btnCaptionRestore.visible = false
		btnCaptionMax.visible = True
	elseIf nCmdShow = SS_MAXIMIZED Then
		btnCaptionRestore.visible = true
		btnCaptionMax.visible = False
	End If
End Sub

Sub btnCaptionTopmost_onClick()
	window.ExeCommand 1, 0
End Sub

Sub btnCaptionMin_onClick()
	window.ShowWindow SC_MINIMIZE
End Sub

Sub btnCaptionMax_onClick()
	btnCaptionMax.visible = false
	btnCaptionRestore.visible = true
	window.ShowWindow SC_MAXIMIZE
End Sub

Sub btnCaptionRestore_onClick()
	btnCaptionMax.visible = true
	btnCaptionRestore.visible = false
	window.ShowWindow SC_RESTORE
End Sub

Sub btnCaptionClose_onClick()
	window.ShowWindow SC_CLOSE
End Sub