'
' <Xinics v3.2 Viewer> Copyright (C) 2001-2007 Xinics Inc. All rights reserved. #3.2.200708.1048
'
Const MSG_1 = "以前に見た内容です."
Const MSG_2 = "から続けて見ますか？"
Const MSG_3 = "続けて見る"
Const MSG_4 = "視聴しているときだけメモが可能です."
Const MSG_5 = "板書を読み取れませんでした."
Const MSG_6 = "ストリームノートが設置されていません."
Const MSG_7 = "メディアプレーヤーが設置されていません."
Const Msg_8 = "Contentsを視聴するためのコンポーネントがインストールされていませんので、ViewerOCX.exeのインストールを開始します。"
Const MSG_LOG1 = "サーバーへの接続に失敗しました。学習時間が記録されていません."
Const MSG_LIVE1 = "生放送が進行しているときだけ質問が可能です."
Const MSG_LIVE2 = "生放送講義サーバーへの接続に失敗しました."
Const MSG_LIVE3 = "生放送講義サーバーへの接続に失敗しました。板書が表示されません."
Const MSG_LIVE4 = "生放送が終了しました."
Const MSG_LIVE5 = "生放送がすでに進行中です."
Const MSG_LIVE6 = "ページです."
Const MSG_LIVE7 = "生放送がまだ始まっていません."
Const MSG_LIVE8 = "生放送が始まりました."
Const MSG_LIVE9 = "生放送ではサポートしていません."

Const BufText = "<font color=red>バッファリング中です...</font>"
Const BufText2 = "バッファリング"

Const gInc = 100
Dim gCurListIndex,gListNum

'Array index - 1:posLeft, 2:posTop, 3:posWidth, posHeight:4
Dim gNormalWindow(2), gTitleBar(2)
Dim gSlideRect(4),gVideoRect(4), gInitSlideRect(4), gInitVideoRect(4)
Dim gSlideControlRect(4),gSlideControlRect2(4),gNoteRect(4),gNoteRect2(4),gMemoRect(4),gMemoRect2(4)

Dim gListPos(2), gPagePos(2), gInfoPos(2)
Dim gQuestionPos(2), gSwapPos(2), gVideoMaxPos(2), gSlideMaxPos(2), gPrintPos(2), gHelpPos(2)
Dim gViewerUtilPos(2)

Dim gIsLiveFirstTry
Dim gPrevMarker

Dim gMarkers()
Dim gMarkerNum
Dim gLateMarker
Dim gGUID
Dim gLiveOn
Dim gLoggingOn
Dim gbMP7
Dim gDataVideo
Dim gUIMode
Dim gLiveStop

'WMP9
Dim bWindowLoaded
Dim bReservePlayReady
Dim bReserveOpen

Dim gSliderTimeoutId, gBuffTimeoutId
Dim gPlayState

Dim gbAppMode
Dim gSizeX
Dim gSizeY

Dim gnReloadPage


Sub window_onload()
	window.focus()

	bWindowLoaded = False
	bReservePlayReady = False
	bReserveOpen = False
	gnReloadPage = -1

	SetSync False
	ShowToolTip
	MyInitLayers

	if (not gbMP7) and isObj(td_Video) then td_Video.style.posHeight = td_Video.style.posHeight + 9
	UpdateSize
	WriteCurrentStatus "SIZE_COMPLETE" , True

	if ( not CheckSN() ) then
			if IsObj(ViewerComponent) then
				ViewerComponent.style.posLeft = (ViewerWidth - ViewerComponent.style.posWidth) / 2
				ViewerComponent.style.posTop = 150
				ShowLayer ViewerComponent
			else
				MsgBox Msg_8
				window.opener=window
				window.location.replace ("ViewerOCX.exe")
				setTimeout "window.close()", 1000
			end if
		exit sub
	end if

	ControlInit
	showCustomLogo	

	if LiveMode then
		ShowLayer Question		
		ShowLayer bg_LiveLine
		HideLayer TrackPos
'		ShowInfo

		if VideoUrl <> "" then
			gListNum = InitListLive()
			gCurListIndex = 1
			ShowSlideNumber gCurListIndex
			if (gListNum > 0) then SetbScale LiveMarker( gCurListIndex )
			if not ViewerUtil.LiveConnect (LiveIP, LiveChannel) then
				msgbox MSG_LIVE2, 16
			else
				if sn2.Connect( LiveIP, LiveChannel, False ) <> 0 then
					msgbox MSG_LIVE3, 16
				end if
			end if
			gIsLiveFirstTry = True
			ViewerUtil.LiveGetInfo
		end if
	else
		gListNum = InitListNew()
'		SetUIMode
		if (gListNum > 0) then SetbScale GetEventItem( GetMarkerIndex( 1 ) )
'		SetInterval "SetVideoElapseTime()", 1000
	end if
	
	gSizeX = Request("x_mode_x")
	gSizeY = Request("x_mode_y")

	if gSizeX <> "" and gSizeY <> "" then
		gbAppMode = True
	else
		gbAppMode = False
	end if

	bWindowLoaded = True
	if bReservePlayReady then PlayReady
End Sub

Sub window_onresize()
	UpdateSize
End Sub

Sub OnOpenStateChangeMP6( lOldState, lNewState )
	if not gbMP7 and lNewState = 6 then
		if bReserveOpen then 
			bReserveOpen = False
			Exit Sub
		end if
		PlayReady
	end if

	select case openState
	case 3
		bReserveOpen = True
	case 4	
		ShowProgress "Connecting ..."
	case 5
		ShowProgress "Opening ..."
	case 0
		ShowProgress "STOP"
	end select
End Sub

Sub OnOpenStateChangeMP7( openState )
	'If gbMP7 and openState = 13 then PlayReady
	if gbMP7 then 
		select case openState
		case 10
			ShowProgress "Connecting ..."
		case 12
			'if (not LiveMode) then gIsLoadEst = LoadEst()
		case 13
			PlayReady
		case 20
			ShowProgress "Waiting ..."
		end select
	end if
End Sub

Sub PlayReady()
	if ( not bWindowLoaded ) then
		bReservePlayReady = True
		Exit Sub
	end if
	bReservePlayReady = False

	if LiveMode then
		Redim gMarkers(gInc)
		gMarkerNum = 1
		gMarkers(gMarkerNum) = LiveMarker( 1 )
		gLateMarker = -1
	else
		gIsLoadEst = LoadEst()
		if gListNum = "" then gListNum = InitListNew ()
		if gListNum = 0 then gListNum = InitList()
		SetUIMode
		gCurListIndex = 1
		ShowSlideNumber gCurListIndex
		gCurListIndex = 0
		ShowDuration
		ShowInfo

'		gIsLoadEst = LoadEst()
		gSkipPos = 0
		if gIsLoadEst then
'			gGUID = sn2.GetGUID
			ViewerUtil.NoteLoad gGUID
			gSkipPos = SkipPosition()

			if gSkipPos < 0 then 
				MP_SetCurrentPosition 0
			elseif gSkipPos > 0 then 
				MP_SetCurrentPosition gSkipPos 
			end if

		else
			MsgBox MSG_5   
		end if
'		if gIsLoadEst and gSkipPos > 0 then MP_SetCurrentPosition gSkipPos 
		StartTimer gEventCur
	end if

	HideLayer Play
	ShowLayer Pause

	dim interval, dur
	if LiveMode then
		dur = 0
	else
		dur = MP_Duration()
	end if
	if LogMode then
		interval = ViewerUtil.LogCreateSession( LogIp, ClientID, ClientName, L_Code, L_contentTITLE, dur )
		if interval > 0 then
			SetInterval "Viewing()", interval * 1000
			gLoggingOn = True
		else
			gLoggingOn = False
'			msgbox MSG_LOG1
		end if
	end if
	sn2.strStatusText = "---"
End Sub

Sub DoEvent(mn)
	if LiveMode then exit sub
	if Not gSnReady then exit sub
	if gIsSync then exit sub
	if ( not CheckSN() ) then exit sub
	if sn2 = "" then exit sub

	if LCase(Left(mn,13)) = "anizoom slide" then
		DoZoom 1
	elseif LCase(Left(mn,13)) = "anizoom video" then
		DoZoom 2
	elseif LCase(Left(mn,8)) = "maxslide" then
		SlideMax_onClick()
	elseif LCase(Left(mn,8)) = "maxvideo" then
		VideoMax_onClick()
'	elseif LCase(Left(mn,7)) = "aniswap" then
'		Swap1_OnClick
	elseif LCase(Left(mn,7)) = "hideall" then
		sn2.HideAllObjects
		ListIndex = GetListIndex(gEventCur-1)
		DoSlideObject(ListIndex)
	elseif LCase(Left(mn,3)) = "ani" then
		sn2.execScript "DocAction()", "JavaScript"
		sn2.ReserveDelayedUpdate
	elseif LCase(Left(mn,4)) = "note" then
		objs = Mid( mn, InStrRev( mn, "*" )+1, 50 )
		PlayObjects objs, True, gDataVideo
	elseif LCase(Left(mn,5)) = "slide" then
		ListIndex = GetListIndex(gEventCur-1)
		GotoSlide ListIndex, mn, "", "LISTSCROLL"
	end if
End Sub

Sub OnScriptCommand(sType, sParam)
	if gClosed then exit sub
	if LCase(sType) = "text" then
	        CaptionLayer.innerHTML = sParam
		exit sub
	end if
	if not LiveMode then exit sub
	if not gSnReady then exit sub

	gMarkerNum = gMarkerNum + 1
	if gMarkerNum mod gInc = 0 then
		Redim Preserve gMarkers( gInc * (CInt(gMarkerNum/gInc) + 1) )
	end if
	gMarkers(gMarkerNum) = sParam
	if gIsSync then exit sub

	mn = gMarkers(gMarkerNum)
	if LCase(Left(mn,13)) = "anizoom slide" then
		DoZoom 1
	elseif LCase(Left(mn,13)) = "anizoom video" then
		DoZoom 2
	elseif LCase(Left(mn,8)) = "maxslide" then
		SlideMax_onClick()
	elseif LCase(Left(mn,8)) = "maxvideo" then
		VideoMax_onClick()
'	elseif LCase(Left(mn,7)) = "aniswap" then
'		Swap1_OnClick
	elseif LCase(Left(mn,7)) = "hideall" then
		sn2.HideAllObjects
	elseif LCase(Left(mn,3)) = "ani" then
		sn2.execScript "DocAction()", "JavaScript"
		sn2.ReserveDelayedUpdate
	elseif LCase(Left(mn,4)) = "note" then
		objs = Mid( mn, InStrRev( mn, "*" )+1, 50 )
		PlayObjects objs, True, gDataVideo
	elseif LCase(Left(mn,5)) = "slide" then
		ListIndex = GetListIndex(gEventCur-1)
		GotoSlide ListIndex, mn, "", "LISTSCROLL"
	end if
End Sub

Sub OnPlayStateChange(playState)
	if gClosed then exit sub
	if not gbMP7 then playState = playState + 1
	gPlayState = playState

	if gListNum = gCurListIndex and playState = 1 and not IsVideoFull() then
		if gQuizOnNextPage then
			QuizMarker = Right( gPrevMarker, Len(gPrevMarker)-InStrRev( gPrevMarker, "@" ) ) & ","
			DoQuiz QuizMarker
			gQuizOnNextPage = False
		else		
			if (InStr( gPrevMarker, "@") > 0) then
				DoDataItems GetSlideIndex(gPrevMarker), "media_end"
				gPrevMarker = ""
			end if
		end if
	end if

	if LiveMode and gLiveStop and not gClosed then 'mpStopped
		if gLiveOn then msgbox MSG_LIVE4, 64
		gLiveOn = False
		if not ViewerUtil.LiveConnect (LiveIP, LiveChannel) then
'			msgbox MSG_LIVE2, 16
		end if
	end if

	select case playState
	case 3 'mpPlaying
		if (gnReloadPage > 0) then
			m = GetMarkerIndex( gnReloadPage )
			mn = GetEventItem(m)
			ListIndex = gnReloadPage
			GotoSlide ListIndex, mn, "", "LISTSCROLL"
			StartTimer gEventCur

			HideLayer Play
			ShowLayer Pause
			ShowProgress "PLAYING ..."
			exit sub 
		else
			gnReloadPage = -1
		end if

		if ( IsAudioContent() ) then 
			showAudioLogo
			ShowLayer VideoLogoLayer
		else
			HideLogo
			HideLayer VideoLogoLayer
		end if

		StartTimer gEventCur
		clearInterval gSliderTimeoutId
		gSliderTimeoutId = SetInterval ("SetVideoElapseTime()", 1000)

		if gLoggingOn then ViewerUtil.LogResume
		if gUIMode="MAXVIDEO" then 
			MP_Fullscreen True 
			gUIMode = ""
		elseif gUIMode="MAXSLIDE" then 
			SlideMax_onClick()
			gUIMode = ""		
		end if

		HideLayer Play
		ShowLayer Pause
		ShowProgress "PLAYING ..."
	case 1	'mpStopped
		gIgnoreOnce = True
		MP_SetCurrentPosition 0 
		clearTimeout gEventTimeoutId
		gEventCur = 0
		if gLoggingOn then ViewerUtil.LogPause

'		clearInterval gSliderTimeoutId
		ResetSlider
		HideLayer Pause
		ShowLayer Play
		ShowProgress "STOP"
	case 2	'mpPaused
		gIgnoreOnce = True
		MP_SetCurrentPosition MP_CurrentPosition()
		clearTimeout gEventTimeoutId
'		clearInterval gSliderTimeoutId
		if gLoggingOn then ViewerUtil.LogPause

		HideLayer Pause
		ShowLayer Play

		ShowProgress "PAUSE"
	case 9	
		ShowProgress "Preparing ..."
	case 10 'mpReady
		gIgnoreOnce = True
		MP_SetCurrentPosition 0 
		clearTimeout gEventTimeoutId
		gEventCur = 0
		if gLoggingOn then ViewerUtil.LogPause

'		clearInterval gSliderTimeoutId
		ResetSlider
		HideLayer Pause
		ShowLayer Play
		ShowProgress "READY"
	end select
End Sub

Sub window_onunload()
	clearInterval gSliderTimeoutId
	gClosed = True
	gQuizOnNextPage = False
	if LogMode And gLoggingOn then ViewerUtil.LogEnd

	if ( IsObj(sn2) and sn2 <> "") then
		sn2.execScript "TerminateMPDataWin()", "JavaScript"
	end if

	'DelCookie "ESTREAM" & gGUID
	SetCookie gGUID, MP_CurrentPosition(), 365

	if gIsLoadEst then 
		ViewerUtil.NoteSetMarkers gCurListIndex, gPMarkers
		gNoteDirty = True
	end if
	if gIsLoadEst and gNoteDirty then 
		ViewerUtil.NoteSetTitle gLectureTitle, gLectureAuthor, gLectureDate
		ViewerUtil.NoteSave
		sn2.SavePrivateFile gGUID & ".est"
	end if

	if ( IsOpenWindow(window.opener) ) then window.opener.focus()
End Sub

Sub OnPositionChange(oldPosition, newPosition)
	if gIgnoreOnce then
		gIgnoreOnce = False
		exit sub
	end if
	if LiveMode then exit sub
	if gIsSync then SetSync False
	Dim ListIndex, mn
	FindCurrentSlide ListIndex, mn
	gEventCur = GetCurrentEvent(newPosition*1000)
	SetPrevUIMode gEventCur
	StartTimer gEventCur
	if ListIndex = gCurListIndex then gQuizOnNextPage = False
	GotoSlide ListIndex, mn, "", "LISTSCROLL"
End Sub

Sub Printbtn_onClick()
	if not gSnReady then exit sub
	sn2.execScript "DoPrint()", "JavaScript"
End Sub

Sub Help_onClick()
	DoHelp
End Sub

Sub Play_onClick()
	MP_Play
End Sub

Sub Pause_onClick()
	MP_Pause
End Sub

Sub Stop_onClick()
	if not LiveMode then
		'MP_SetCurrentPosition 0 
		MP_Stop
	end if
End Sub

Sub Mute_onClick()
	if gbMP7 then
		MediaPlayer1.settings.mute = not MediaPlayer1.settings.mute
		b = MediaPlayer1.settings.mute
	else
		MediaPlayer1.Mute = not MediaPlayer1.Mute
		b = MediaPlayer1.Mute
	end if
	if b then
		HideLayer Mute
		ShowLayer SoundOn
	else
		HideLayer SoundOn
		ShowLayer Mute
	end if
End Sub

Sub Next_onclick()
	if gCurListIndex >= gListNum then exit sub

	if not gIsSync then SetSync True
	if LiveMode then
		MarkerText = LiveMarker( gCurListIndex )
		GotoSlide -1, MarkerText, "ShowAllPage", ""
		exit sub
	end if

	m = GetMarkerIndex( gCurListIndex+1 )
	mn = GetEventItem(m)
	GotoSlide gCurListIndex+1, mn, "ShowAllPage", "LISTSCROLL"
End Sub

Sub Prev_onclick()
	if gCurListIndex <= 1 then exit sub

	if not gIsSync then SetSync True
	if LiveMode then
		MarkerText = LiveMarker( gCurListIndex )
		GotoSlide -1, MarkerText, "ShowAllPage", ""
		exit sub
	end if

	m = GetMarkerIndex( gCurListIndex-1 )
	mn = GetEventItem(m)
	GotoSlide gCurListIndex-1, mn, "ShowAllPage", "LISTSCROLL"
End Sub

Sub Sync_onclick()
	if not gIsSync then exit sub

	SetSync False

	if LiveMode then
		for index=1 to gMarkerNum
			if LCase(Left(gMarkers(index),5)) = "slide" then
				MarkerText = gMarkers(index)
			end if
		next
		GotoSlide -1, MarkerText, "", "LISTSCROLL"
	else
		Dim ListIndex, mn
		FindCurrentSlide ListIndex, mn
		gEventCur = GetCurrentEvent( MP_CurrentPosition() * 1000 )
		StartTimer gEventCur
		GotoSlide ListIndex, mn, "", "LISTSCROLL"
	end if

End Sub

Sub SNScreen_onClick()	
	if ( not CheckSN() ) then exit sub
	if ( sn2 = "" ) then exit sub

	if (gSNScreenMode = True) then
		sn2.StopRecord
		gPenMode = false
		Pen.disabled = true
		PenColor.disabled= true
		PenWidth.disabled= true
		Eraser.disabled= true
	else
		Pen.disabled = false
		PenColor.disabled= false
		PenWidth.disabled= false
		Eraser.disabled= false
	end if

	sn2.HideScreenWnd(gSNScreenMode)
	gSNScreenMode = not gSNScreenMode

	imgMouseOut "Pen"
	imgMouseOut "Eraser"
	imgSelectOn "SNScreen"
End Sub

Sub Pen_onClick()
	if ( not CheckSN() ) then exit sub
	if ( sn2 = "" ) then exit sub
	if ( gSNScreenMode = False ) then exit sub
	if gPenMode then 
		sn2.StopRecord
	else
		sn2.StartRecord True
		sn2.StartPrivateRecord
	end if
	gPenMode = not gPenMode
	sn2.PutProp -1, "bTranslucent", False

	cr = Trim(PenColor.value)
	if Left(cr,1) = "#" then
		cr = "&H" & Right( cr, Len(cr)-1 ) & "&"
		sn2.PutProp -1, "color", Eval( cr ) 
	else
		sn2.PutProp -1, "color", CInt(cr) 
	end if
	sn2.PutProp -1, "penWidth", CInt(PenWidth.value)*2 
End Sub

Sub resetSNPenColor()
	sn2.PutProp -1, "bTranslucent", False

	cr = Trim(PenColor.value)
	if Left(cr,1) = "#" then
		cr = "&H" & Right( cr, Len(cr)-1 ) & "&"
		sn2.PutProp -1, "color", Eval( cr ) 
	else
		sn2.PutProp -1, "color", CInt(cr) 
	end if
	sn2.PutProp -1, "penWidth", CInt(PenWidth.value)*2 
End Sub 

Sub PenColor_onChange()
	if ( not CheckSN() ) then exit sub 
	if ( sn2 = "" ) then exit sub
	if ( gSNScreenMode = False ) then exit sub
	cr = Trim(PenColor.value)
	if Left(cr,1) = "#" then
		cr = "&H" & Right( cr, Len(cr)-1 ) & "&"
		sn2.PutProp -1, "color", Eval( cr )
	else
		sn2.PutProp -1, "color", CInt(cr)
	end if
	sn2.focus
End Sub

Sub PenWidth_onChange()
	if ( not CheckSN() ) then exit sub 
	if ( sn2 = "" ) then exit sub
	if ( gSNScreenMode = False ) then exit sub
	sn2.PutProp -1, "penWidth", CInt(PenWidth.value)*2
	sn2.focus
End Sub

Sub Memo_onClick()
	if LiveMode then
		msgbox MSG_LIVE9, 16
		exit sub
	end if
	if gIsLoadEst then
		DoMemo "LOAD"
'		ViewerUtil.MemoLoad gGUID, gCurListIndex, window.event.screenX, window.event.screenY
		gNoteDirty = True
	else
		msgbox MSG_4, 16
	end if
End Sub

Sub Swap_OnClick()
	if gZoomState = 1 then 
		DoZoom 2
	else 
		DoZoom 1
	end if
End Sub

Sub DoZoom(state)
'	if gIsSlideFull or IsVideoFull() then exit sub
	if IsVideoFull() then MP_Fullscreen False
	if gIsSlideFull then SlideNormal_onClick

	if state = gZoomState then exit sub
	gZoomState = state

	HideLayer VideoLayer
	HideLayer VideoLogoLayer
	HideLayer SlideLayer

	LoadRect VideoLogoLayer, gSlideRect 
	LoadRect VideoLogo, gSlideRect 

	LoadRect MediaPlayer1, gSlideRect 
	LoadRect VideoLayer, gSlideRect 
	
	LoadRect SlideLayer, gVideoRect 

	SaveRect gSlideRect, SlideLayer 
	SaveRect gVideoRect, VideoLayer

	ShowLayer VideoLayer
	ShowLayer VideoLogoLayer
	ShowLayer SlideLayer
End Sub

Sub List_onClick( ListIndex )
	if LiveMode then
		MarkerText = LiveMarker( ListIndex )
		GotoSlide -1, MarkerText, "ShowAllPage", ""
		if not gIsSync then SetSync True
		exit sub
	end if

'	if ListIndex <> gCurListIndex then
		m = GetMarkerIndex( ListIndex )
		gEventCur = m+1
		mn = GetEventItem(m)
		gIgnoreOnce = True
'		if ListIndex > 1 then
'			MP_SetCurrentPosition GetEventTime(m)/1000.0 + 0.5
'		else
			MP_SetCurrentPosition GetEventTime(m)/1000
'		end if
		SetPrevUIMode gEventCur
		if gIsSync then SetSync False
		StartTimer gEventCur
		if ListIndex = gCurListIndex then gQuizOnNextPage = False
'		if IsDataVideo(mn) and  not LiveMode then
'			SetTimeout "GotoSlide(" & ListIndex & ", '" & mn & "','','')", 1000
'		else
			GotoSlide ListIndex, mn, "", ""
'		end if
'	end if
End Sub

Sub SlideMax_onClick()
	if gIsSlideFull then exit sub
	if IsVideoFull() then MP_Fullscreen False
	gIsSlideFull = True

	WriteCurrentStatus "SIZE_FULL_START" , False

	gNormalWindow(1) = BodyImg.width
	gNormalWindow(2) = BodyImg.height

	if gbAppMode then
		ScreenWidth  = gSizeX
		ScreenHeight = gSizeY
	else
		ScreenWidth  = screen.availWidth							'1024
		ScreenHeight = screen.availHeight							'768
	end if

	window.top.moveTo 0,0
	window.top.resizeTo ScreenWidth, ScreenHeight

	WriteCurrentStatus "SIZE_FULL_COMPLETE" , True

	gTitleBar(1) = ScreenWidth  - BodyImg.width
	gTitleBar(2) = ScreenHeight - BodyImg.height
	
	ScreenWidth  = ScreenWidth  - gTitleBar(1)
	ScreenHeight = ScreenHeight - gTitleBar(2)
	ControlPos   = ControlSet.style.posHeight + 10

	Dim TempRect(4)
	TempRect(1) = 0
	TempRect(2) = 0
	TempRect(3) = ScreenWidth
	TempRect(4) = ScreenHeight - ControlPos	'673
	
	if ( 3 * TempRect(3) < 4 * TempRect(4) ) then
		TempRect(3) = TempRect(3) - (TempRect(3) mod 4)
		TempRect(4) = 3 * TempRect(3) / 4
	else
		TempRect(4) = TempRect(4) - (TempRect(4) mod 3)
		TempRect(3) = 4 * TempRect(4) / 3
	end if

	TempRect(1)   = (ScreenWidth - TempRect(3)) / 2
	TempRect(2)   = (ScreenHeight - (TempRect(4) + ControlSet.style.posHeight)) / 2
	LoadRect SlideLayer, TempRect

	TempRect(2) = TempRect(2) + TempRect(4)
	TempRect(4) = ControlSet.style.posHeight
	LoadRect ControlSet, TempRect

	TempRect(1) = TempRect(1) - 1
	TempRect(2) = SlideLayer.style.posTop - 1
	TempRect(3) = TempRect(3) + 2
	TempRect(4) = SlideLayer.style.posHeight + 50
	LoadRect bgSlideControl, TempRect
	ShowLayer bgSlideControl

	HideLayer TopLayer
	HideLayer VideoLayer
	HideLayer VideoLogoLayer

	HideLayer SlideMax
	ShowLayer SlideNormal

	HideLayer ListLayer
	HideLayer Info

	HideLayer Printbtn
	HideLayer Help

	HideLayer ViewerUtil	
	HideLayer ViewerComponent

	HideLayer Swap
	ShowLayer noSwap

	if IsObj(VideoLogoLayer) then
		VideoLogoLayer.style.zIndex = 0
		VideoLogoLayer.style.posLeft = VideoLayer.style.posLeft
	end if

	ResetPosition ControlSet, "SLIDEMAX"
'	WriteCurrentStatus "SIZE_FULL_COMPLETE" , True
End Sub

Sub VideoMax_onClick()
	if gIsSlideFull then SlideNormal_onClick
	MP_Fullscreen True
End Sub

Sub SlideNormal_onClick()
	WriteCurrentStatus "SIZE_NORMAL_START" , False

	gIsSlideFull = False
	HideLayer SlideNormal
	HideLayer bgSlideControl

	window.top.resizeTo gNormalWindow(1) + gTitleBar(1), gNormalWindow(2) + gTitleBar(2)

	WriteCurrentStatus "SIZE_NORMAL_COMPLETE" , True

	ShowLayer TopLayer
	ShowLayer TopLogo
	ShowLayer LeftLayer
	ShowLayer RightLayer
	ShowLayer VideoControl
	ShowLayer MuteLayer
	ShowLayer Track
	ShowLayer TrackPos
	ShowLayer SlideControl
	if (td_Toc.style.display = "none") then
		ShowLayer Info
	else
		ShowLayer ListLayer
	end if
	ShowLayer PageLayer

	checkVideoLogo
	ShowLayer VideoLayer
	ShowLayer PenColor
	ShowLayer PenWidth
	ShowLayer VideoMax
	ShowLayer SlideMax	
	ShowLayer NoteLayer
	ShowLayer MemoLayer
	ShowLayer TopButton
	ShowLayer Printbtn
	ShowLayer Help
	ShowLayer Buttons
	if (LiveMode) then
		ShowLayer bg_LiveLine
		ShowLayer Question
	end if
	ShowLayer ViewerUtil

	HideLayer noSwap
	ShowLayer Swap
	HideLayer SlideNormal

	gIsSlideFull = False

	LoadRect MediaPlayer1, gVideoRect
	LoadRect VideoLayer, gVideoRect
	LoadRect SlideLayer, gSlideRect

	if IsObj(VideoLogoLayer) then
		VideoLogoLayer.style.zIndex = VideoLayer.style.zIndex
		VideoLogoLayer.style.posLeft = VideoLayer.style.posLeft
	end if

	Dim TempRect(4)
	if (gZoomState = 2) then
		TempRect(1) = VideoLayer.style.posLeft
		TempRect(2) = VideoLayer.style.posTop + VideoLayer.style.posHeight
		TempRect(3) = VideoLayer.style.posWidth
		TempRect(4) = ControlSet.style.posHeight
		LoadRect ControlSet, TempRect
	else
		TempRect(1) = SlideLayer.style.posLeft
		TempRect(2) = SlideLayer.style.posTop + SlideLayer.style.posHeight
		TempRect(3) = SlideLayer.style.posWidth
		TempRect(4) = ControlSet.style.posHeight
		LoadRect ControlSet, TempRect
	end if

	TempRect(1) = 0
	TempRect(2) = 0
	TempRect(3) = 1
	TempRect(4) = 1
	LoadRect bgSlideControl, TempRect
	HideLayer bgSlideControl

	ResetPosition ControlSet, "SLIDENORMAL"
'	WriteCurrentStatus "SIZE_NORMAL_COMPLETE" , True
End Sub

Sub Restore()
	if gIsSlideFull then SlideNormal_onClick
	if IsVideoFull() then MP_Fullscreen False
End Sub

Sub Eraser_onClick()
	if ( not CheckSN() ) then exit sub
	if ( sn2 = "" ) then exit sub
	if ( gSNScreenMode = False ) then exit sub
	sn2.HideAllObjects
	if ( gCurListIndex = "" ) then exit sub

	objs = gPMarkers & ","
	pos = InStr( objs, "," )
	while pos <> 0
		t = Left( objs, pos-1 )
		
		if t<>"" then sn2.DeleteObject CLng(t)
		objs = Right( objs, len(objs)-pos )
		pos = InStr( objs, "," )
	wend
	gPMarkers = ""

	if LiveMode then 
		SlideIndex = gCurListIndex
	else
		ListIndex = 0
		m = GetMarkerIndex( gCurListIndex )
		SlideIndex = GetSlideIndex( GetEventItem(m) )
	end if
	objs = PlayRange(SlideIndex, False)
	DoSlideObject( SlideIndex )
	PlayObjects objs, False
End Sub

Sub Question_OnClick()
	if not gLiveOn then 
		MsgBox MSG_LIVE1, 48
		exit sub
	end if

	ret = ShowModalDialog( "ques.htm", "", "dialogWidth:443px;dialogHeight:190px;resizable:no;scroll:no;status:no" )
	if ret <> "" then
		ViewerUtil.LiveConnect LiveIP, LiveChannel
		ViewerUtil.LiveQuestion "LQ" & ret
		ViewerUtil.LiveClose
	end if
End Sub

Sub sn2_PacketReceived(id)
	if gLateMarker >= 0 then
		if sn2.PlayObject(gLateMarker, False) then
			gLateMarker = -1
		end if
	end if
End Sub

Sub sn2_StatusMatched()
	if ( not IsObj(MediaPlayer1) ) then exit sub 
	playState = MediaPlayer1.playState
	if ( not gbMP7 ) then playState = playState + 1
	if( playState = 1 ) then 
		sn2.strStatusText = "---"
		exit sub
	end if

	Select Case sn2.strStatusText
	Case "PlayingStart"
		gReservePause  = False
		gReservePause2 = False
		sn2.strStatusText = "---"
		SetTimeout "MP_Play()", 500
	Case "PlayingEnd"
		sn2.strStatusText = "---"
		SetTimeout "MP_Play()", 500
	End Select
End Sub

Sub sn2_PacketGenEnd( id )
	if gPMarkers <> "" then gPMarkers = gPMarkers & ","
	gPMarkers = gPMarkers & id
End Sub

Sub ViewerUtil_OnLiveInfo( IsStarted, SlideNum, GUID )
	if IsStarted then
		if SlideNum > 0 and gIsLiveFirstTry then 
			MsgBox MSG_LIVE5 & SlideNum & MSG_LIVE6, 64
			Redim gMarkers(gInc)
			gMarkerNum = 1
			gLateMarker = -1
			gMarkers(gMarkerNum) = LiveMarker( SlideNum )
			GotoSlide -1, LiveMarker( SlideNum ), "", ""
			if ( IsAudioContent() ) then showAudioLogo
		end if
		gGUID = GUID
		ViewerUtil.LiveClose
		gLiveOn = True
		gLiveStop = False
	else
		MsgBox MSG_LIVE7, 64
		gLiveOn = False
		gLiveStop = True
	end if
End Sub

Sub ViewerUtil_OnLiveStart()
	msgbox MSG_LIVE8, 64
	Redim gMarkers(gInc)
	gMarkerNum = 1
	gMarkers(gMarkerNum) = LiveMarker( 1 )
	gLateMarker = -1
	sn2.ResetContent
	if gIsSync then SetSync False
	if not gbMP7 and MediaPlayer1.PlayState <> 2 then 'not playing
		MediaPlayer1.FileName = VideoUrl
	elseif gbMP7 and MediaPlayer1.PlayState <> 3 then 'not playing
		MediaPlayer1.URL = VideoUrl
	end if
	gIsLiveFirstTry = False
	ViewerUtil.LiveGetInfo
	if ( IsAudioContent() ) then showAudioLogo
End Sub

Sub window_onfocus()
	if ( not CheckSN() ) then exit sub
	if ( sn2 = "" ) then exit sub
	sn2.ReserveDelayedUpdate
End Sub

Sub ShowToolTip()
	SetAlt document.all.item("Printbtn"), "Print"
	SetAlt Help, "HELP"
	SetAlt SlideMax, "SLIDE FULL SCREEN"
	SetAlt VideoMax, "VIDEO FULL SCREEN"	
	SetAlt Swap, "SWITCH VIDEO/SLIDE"
	SetAlt Play, "PLAY"
	SetAlt Pause, "PAUSE"
	SetAlt document.all.item("Stop"), "STOP"
	SetAlt Mute, "MUTE"
	SetAlt Prev, "PREV"
	SetAlt Sync, "VIDEO/SLIDE SYNC"
	SetAlt document.all.item("Next"), "NEXT"
	SetAlt SlideNormal, "CLOSE"
	Setalt NoteLook, "NOTE ON/OFF"
	SetAlt MemoLook, "MEMO ON/OFF"
	SetAlt AnnoLook, "ANNOTATION ON/OFF"
	Setalt Pen, "PEN"
	SetAlt Eraser, "ERASER"
	SetAlt Memo, "MEMO"
	SetAlt Question, "QUESTION"
	SetAlt SNScreen, "NOTE ON/OFF"
End Sub

Function SkipPosition()
	SkipPosition = 0
	Dim pos
	if IsNull(gScormAPI) then
		pos = GetCookie(gGUID)
	'For Scorm
	else
		pos = gLessonLocation
	end if

	if pos <> "" then
		t = CInt(pos)
		if t<10 then exit function
		if ( MP_SourceFile() and not IsAudioContent() ) then HideLayer VideoLogoLayer
		d = FormatTime(t)
		str = MSG_1 & d & MSG_2
		if msgbox( str, 4, MSG_3 ) = 6 then
			SkipPosition = t
			gUIMode = ""
		else
			SkipPosition = -1
		end if
	end if
End Function

Function PlayRange( SlideIndex, bAnimation )
	Dim index, AniNum, bPlay, mn, hideindex, t, objs
	objs = ""
	AniNum = 0
	bPlay = False
	hideindex = 0
	if LiveMode then
		toIndex = gMarkerNum
	else
		toIndex = gEventCur
	end if
	for index=1 to toIndex
		if LiveMode then
			mn = gMarkers(index)
		else
			mn = GetEventItem(index-1)
		end if
		if LCase(Left(mn,5)) = "slide" then
			If SlideIndex = GetSlideIndex(mn) then
				bPlay = True
			Else
				bPlay = False
			End If
		elseif bPlay = True and LCase(Left(mn,7)) = "hideall" then
			hideindex = index
		end if
	next
	bPlay = False
	for index=1 to toIndex
		if LiveMode then
			mn = gMarkers(index)
		else
			mn = GetEventItem(index-1)
		end if
		if LCase(Left(mn,5)) = "slide" then
			If SlideIndex = GetSlideIndex(mn) then
				bPlay = True
			Else
				bPlay = False
			End If
		elseif bPlay = True and LCase(Left(mn,4)) = "note" and index > hideindex then
			objs = objs & Mid( mn, InStrRev( mn, "*" )+1, 50 ) & ","
		elseif bPlay = True and LCase(Left(mn,3)) = "ani" and LCase(Left(mn,7)) <> "anizoom" and LCase(Left(mn,7)) <> "aniswap"  then
			AniNum = AniNum + 1
		end if
	next
	if bAnimation then
		sn2.execScript "SetAniNum( " & AniNum & ")", "JavaScript"
	end if
	if objs <> "" then objs = Left( objs, Len(objs)-1 )
'window.status = "MPCur=" & toIndex & "," & MP_CurrentMarker() & ",objs=" & objs & ",Aninum=" & AniNum 
	PlayRange = objs
End Function

Sub Viewing()
	ViewerUtil.LogViewing 
End Sub

Sub ShowInfo()
	if not IsObj( info ) then exit sub
	infoc = Info.innerHTML
	infoc = Replace( infoc, "<contentTITLE>", gLectureTitle, 1, -1, 1 ) 'mpClipTitle
	infoc = Replace( infoc, "<contentAUTHOR>", gLectureAuthor, 1, -1, 1 ) 'mpClipAuthor
	infoc = Replace( infoc, "<contentDATE>", gLectureDate, 1, -1, 1 ) 'mpClipRating

	Info.innerHTML = infoc
End Sub

Function document_onkeydown()
	'if window.event.keycode = 27 then MP_Stop
	document_onkeydown = False
End Function

Sub SetSync(v)
	gIsSync = v	
	clearTimeout gEventTimeoutId
	MultiMouseOut "Sync", "button_"
End Sub

Sub GotoSlide( ListIndex, MarkerText, ShowAllPage, ListScroll )
	if ( not CheckSN() ) then exit sub 
	if ( sn2 = "" ) then exit sub
	if IsDataVideo( MarkerText ) and not LiveMode then
		if Abs(MP_CurrentPosition()-gPrevPosition) < 0.1 then exit sub
	end if

	'sn2.strStatusText = "---"

	SlideIndex = GetSlideIndex(MarkerText)
	PrevIndex = gCurListIndex
	if LiveMode then
		gCurListIndex = SlideIndex
	else
		gCurListIndex = ListIndex
		gUIMode = ""
	end if
	if gCurListIndex=0 then gCurListIndex = 1

	gnReloadPage = -1

	if gPlayState = 3 or gPlayState = 6 then
		if not gIsPrevStuff and not IsVideoFull() and PrevIndex <> gCurListIndex and InStr( gPrevMarker, "@") > 0 then
			On Error Resume Next
			if not LiveMode then 
				if gbMP7 then
					if MediaPlayer1.playState = 6 then
						gReservePause = True
					elseif MediaPlayer1.controls.isAvailable("pause") then 
						MP_Pause
					else
						gReservePause = True
					end if
					'gReservePause = True
				else
					MP_Pause
				end if
			end if
			On Error Goto 0

			if DoDataItems (GetSlideIndex(gPrevMarker), "media_end") = "play" then
				MP_Play
			else
				gPrevMarker = ""
				gnReloadPage = ListIndex
				'gEventCur = gEventCur - 1
				gCurListIndex = PrevIndex
				exit sub
			end if
			gPrevMarker = ""

		elseif gQuizOnNextPage and not IsVideoFull() then
			On Error Resume Next
			if not LiveMode then 
				if gbMP7 then
					if MediaPlayer1.playState = 6 then
						gReservePause = True
					elseif MediaPlayer1.controls.isAvailable("pause") then 
						MP_Pause
					else
						gReservePause = True
					end if
					'gReservePause = True
				else
					MP_Pause
				end if
			end if
			On Error Goto 0
		
			QuizMarker = Right( gPrevMarker, Len(gPrevMarker)-InStrRev( gPrevMarker, "@" ) ) & ","
			DoQuiz QuizMarker
			if IsQuiz( MarkerText ) then
				gPrevMarker = MarkerText
				gQuizOnNextPage = True
			else
				gQuizOnNextPage = False
			end if
		end if
	else
		gPrevMarker = ""
		gQuizOnNextPage = False
	end if

	if IsQuiz( MarkerText ) then
		if gIsPrevStuff then gQuizOnNextPage = True
		gPrevMarker = MarkerText
	end if

	SetbScale MarkerText

	ChangeEntry gCurListIndex, ListScroll
	ShowSlideNumber gCurListIndex
	ShowDuration

	sn2.HideAllObjects

	title=Left( MarkerText, InStrRev( MarkerText, "*")-1 )
	title=Mid( title, InStr( title, "#")+1, Len(title) )
	if IsObj(SlideTitle) then SlideTitle.innerText = title

	if HasAnno(MarkerText) and not IsVideoFull() and (PrevIndex <> gCurListIndex) then
		DoAnno SlideIndex
	end if

	if not LiveMode and not IsVideoFull() and (PrevIndex <> gCurListIndex) then
		DoMemo "CHECK"
'		if IsObj(MemoLayer) then
'			ViewerUtil.MemoCheck gGUID, gCurListIndex, window.screenLeft+MemoLayer.style.posLeft, window.screenTop+MemoLayer.style.posTop
'		elseif IsObj(NoteLayer) then
'			ViewerUtil.MemoCheck gGUID, gCurListIndex, window.screenLeft+NoteLayer.style.posLeft, window.screenTop+NoteLayer.style.posTop
'		end if
	end if


	gPrevPosition = -1

	GetVideoMetadata ListIndex, volume, main_pause
	if volume = "" then volume = "-1"
	
	if IsDataVideo( MarkerText ) and  not LiveMode and not gIsSync then	
		sn2.strStatusText = "---"
		if gbMP7 then
			if MediaPlayer1.playState = 6 then
				gReservePause = True
			elseif MediaPlayer1.controls.isAvailable("pause") then 
				MP_Pause
			else
				gReservePause = True
			end if
			'gReservePause = True
		else
			MP_Pause
		end if
	end if

	SetInvalidate sType
	sn2.ReserveDelayedUpdate
	objs = PlayRange(SlideIndex, True)
	if IsDataVideo( MarkerText ) then
		if ManagerMode then 
			sManager="true"
		else
			sManager="false"
		end if
		if sType = 5 then  'AppVideo
			sScale="false"
		else
			sScale="true"
		end if
		if LiveMode then
			MediaUrl = DataVideoUrl & "/"
		else
			MediaUrl = MP_Url()
			MediaUrl = Replace( MediaUrl, "\", "/", 1, -1, 1 )
		end if
		if IsVideoFull() then MP_Fullscreen False
		sn2.execScript "DoDataVideo2 (" & SlideIndex & "," & sScale & ",'" & MediaUrl & "'," & volume & "," & sManager & ")", "JavaScript"
	else
		sn2.execScript "setFrames (" & SlideIndex & ", '" & ShowAllPage & "')", "JavaScript" 
	end if
	WriteVisitLog ListIndex
	'SetTimeout "ReserveScrollBar()", 1500 

	if IsDataVideo( MarkerText ) and not LiveMode and Trim(LCase(main_pause)) <> "yes" then
		sn2.strStatusText = "PlayingStart"
	elseif IsDataVideo( MarkerText ) and not LiveMode and Trim(LCase(main_pause)) = "yes" then
		sn2.strStatusText = "PlayingEnd"
	end if

	if IsDataVideo( MarkerText ) OR (sType = 6) then
		gDataVideo = True
	else
		gDataVideo = False
	end if
	PlayObjects objs, False, gDataVideo
	DoPrivateMarker PrevIndex, gCurListIndex
	DoSlideObject( ListIndex )
End Sub

Sub DoPrivateMarker(PrevIndex, SlideIndex)
	if not gIsLoadEst then exit sub
	if not (PrevIndex=1 and SlideIndex=1) then 
		ViewerUtil.NoteSetMarkers PrevIndex, gPMarkers
		gNoteDirty = True
	end if
	gPMarkers = ViewerUtil.NoteGetMarkers(SlideIndex)
	if gPMarkers = "" then exit sub
	objs = gPMarkers & ","
	pos = InStr( objs, "," )
	while pos <> 0
		t = Left( objs, pos-1 )
		if t<>"" then sn2.PlayObject CLng(t), False
		objs = Right( objs, len(objs)-pos )
		pos = InStr( objs, "," )
	wend
End Sub

Sub ShowSlideNumber(curNum)
	if (not IsObj( PageLayer )) or (curNum = "") then exit sub
	PageLayer.innerHTML =  "SLIDE " & curNum & "/" & gListNum
End Sub

Sub MyInitLayers
	SaveRect gSlideRect, SlideLayer 
	SaveRect gInitSlideRect, SlideLayer 
	VideoLayer.style.posWidth = MediaPlayer1.style.posWidth
	VideoLayer.style.posHeight = MediaPlayer1.style.posHeight
	SaveRect gVideoRect, VideoLayer
	SaveRect gInitVideoRect, VideoLayer
	SaveRect gSlideControlRect, SlideControl
	SaveRect gNoteRect, NoteLayer
	SaveRect gMemoRect, MemoLayer

	gSlideControlRect2(1) = SlideControl_posLeft2
	gSlideControlRect2(2) = SlideControl_posTop2
	gNoteRect2(1) = Note_posLeft2
	gNoteRect2(2) = Note_posTop2
	gMemoRect2(1) = Memo_posLeft2
	gMemoRect2(2) = Memo_posTop2	

	SavePos gListPos, ListLayer
	SavePos gPagePos, PageLayer
	SavePos gInfoPos, Info
	
	SavePos gQuestionPos, Question
	SavePos gSwapPos, Swap
	SavePos gVideoMaxPos, VideoMax
	SavePos gSlideMaxPos, SlideMax
	SavePos gPrintPos, Printbtn
	SavePos gHelpPos, Help
	
	SavePos gViewerUtilPos, ViewerUtil

End Sub

Sub FindCurrentSlide( ByRef ListIndex, ByRef SlideMarker )
	Dim index, mn
	ListIndex=0
	SlideMarker = ""
	for index=0 to gEventNum-1
		if GetEventTime(index) > MP_CurrentPosition() * 1000  then exit for
		mn = GetEventItem(index)
		if LCase(Left(mn,5)) = "slide" then 
			ListIndex = ListIndex + 1
			SlideMarker = mn
		end if
	next
End Sub

Sub SaveRect( rect, obj )
	If not IsObj(obj) Then exit Sub
	rect(1) = obj.Style.posLeft
	rect(2) = obj.Style.posTop
	rect(3) = obj.Style.posWidth
	rect(4) = obj.Style.posHeight
End Sub

Sub LoadRect( obj, rect )
	If not IsObj(obj) Then exit Sub
	obj.Style.posLeft = rect(1)
	obj.Style.posTop = rect(2)
	obj.Style.posWidth = rect(3)
	obj.Style.posHeight = rect(4)
End Sub

Sub DoSlideObject( ListIndex )
	if not gXmlLoad then exit sub
	objs = ""
	query = "lecture/slide[seq=" & ListIndex & "]/object"
	Set nodes = SlideList.XMLDocument.selectNodes(query)
	if nodes.length > 0 then 
		Set node = SlideList.XMLDocument.selectSingleNode(query)
		objs = node.text
	end if
	PlayObjects objs, False, False
End Sub

Sub GetVideoMetadata( ListIndex, volume, main_pause )
	volume = ""
	mian_pause = ""
	if Not IsObj(SlideList) then exit sub
	if SlideList.XMLDocument.parseError <> 0 then exit sub
	if ListIndex = -1 then
		query = "lecture/main_volume"
		Set nodes = SlideList.XMLDocument.selectNodes(query)
		if nodes.length > 0 then 
			Set node = SlideList.XMLDocument.selectSingleNode(query)
			volume = node.text
		end if
		exit sub
	end if

	query = "lecture/slide[seq=" & ListIndex & "]/volume"
	Set nodes = SlideList.XMLDocument.selectNodes(query)
	if nodes.length > 0 then 
		Set node = SlideList.XMLDocument.selectSingleNode(query)
		volume = node.text
	end if

	query = "lecture/slide[seq=" & ListIndex & "]/main_pause"
	Set nodes = SlideList.XMLDocument.selectNodes(query)
	if nodes.length > 0 then 
		Set node = SlideList.XMLDocument.selectSingleNode(query)
		main_pause = node.text
	end if
End Sub

Sub OnBuffering( Start )
	if Start=True then
		clearTimeout gEventTimeoutId
		if gReservePause then
			gReservePause = False
			gReservePause2 = True
		end if
		if gCurListIndex = 0 then
			showCustomLogo
			ShowLayer VideoLogoLayer
		end if
		gBuffTimeoutId = SetInterval ("showBuffstr()", 1000)
	else
		if ( not IsAudioContent() ) then
			HideLayer VideoLogoLayer
		end if
		StartTimer gEventCur
		if gReservePause2 then
			gReservePause2 = False
			SetTimeout "ReservePause()", 100
		else
'			MP_Play
			MP_Play
		end if
		clearInterval gBuffTimeoutId
	end if
End Sub

Function document_onmousemove()
	Exit Function
	window.status = window.event.clientX & "," & (screen.availWidth - 20)
	if gIsSlideFull and window.event.clientX > screen.availWidth - 20 and ListLayer.style.display = "none" then
		ShowLayer ListLayer
		ListLayer.style.zIndex = 2
		SlideLayer.style.zIndex = 1
	end if
End Function

Function getStartPos( mode )
	Dim s
	Select Case mode
	Case "w"
		s = document.body.clientWidth - viewerWidth
'		s = BodyImg.width - viewerWidth
	Case "h"
		s = document.body.clientHeight - viewerHeight
'		s = BodyImg.height - viewerHeight
	Case Else
		s = 0
	End Select
	
	If (s > 0) Then
		getStartPos = s / 2
	Else
		getStartPos = 0
	End If
End Function

Sub UpdateSize ()
	Exit Sub 
	if gIsSlideFull then exit sub

	w = getStartPos("w")
	h = getStartPos("h")

	BODYDoc.style.posLeft = w
	BODYDoc.style.posTop = h

	Exit Sub

	If (gIsSlideFull = True) Then Exit Sub
	w = getStartPos("w")
	h = getStartPos("h")
	
	'If (w = 0 and h = 0) Then Exit Sub

	If IsObj(TopLayer) Then
		TopLayer.style.posLeft = w
		TopLayer.style.posTop = h
	End If

	If IsObj(SlideTitle) Then
		SlideTitle.style.posLeft = SlideLayer.style.posLeft
		SlideTitle.style.posTop = SlideLayer.style.posTop + SlideLayer.style.posHeight + 1
		SlideTitle.style.posWidth = SlideLayer.style.posWidth
	End If

End Sub

Sub SavePos ( posArr, obj )
	If not IsObj(obj) Then Exit Sub
	posArr(1) = obj.style.posLeft
	posArr(2) = obj.style.posTop
End Sub

Sub MovePos ( posArr, obj, offsetX, offsetY)
	If not IsObj(obj) Then Exit Sub
	If UBound(posArr) = 0 Then Exit Sub
	obj.style.posLeft = posArr(1) + offsetX
	obj.style.posTop = posArr(2) + offsetY

End Sub

Sub SetSlideTitlePos ()
	SlideTitle.style.posLeft = SlideLayer.style.posLeft
	SlideTitle.style.posTop = SlideLayer.style.posTop + SlideLayer.style.posHeight + 1
	SlideTitle.style.posWidth = SlideLayer.style.posWidth
End Sub


Function IsAudioContent()
	Dim imgWidth

	if gbMP7 then
		imgWidth = MediaPlayer1.currentMedia.imageSourceWidth
	else
		imgWidth = MediaPlayer1.ImageSourceWidth
	end if
	
	if imgWidth = 0 then
		IsAudioContent = True
	else
		IsAudioContent = False
	end if
End Function

Sub SetbScale( MarkerText )
	sType = GetSubType( MarkerText )

	if sType = 1 or sType = 2 or (not gIsPrevStuff and sType = 3) or sType = 5 then
		sn2.bScale = False
	else
		sn2.bScale = True
	end if
End Sub

Sub ShowDuration()
	if ( LiveMode ) then exit sub
	strCurPosition
End Sub

Function IsUndefined( strVar )
	if ( VarType( strVar ) = 0 or VarType( strVar ) = 1 ) then 	'0:empty, 1:null
		IsUndefined = True
	else
		IsUndefined = False
	end if
End Function

Function GetHideListMetadata( ListIndex )
	if IsObj(SlideList) then  		
		if not gXmlLoad or SlideList.XMLDocument.parseError <> 0 then					
			GetHideListMetadata = "visible"
			Exit Function
		end if
			
		query = "lecture/slide[seq=" & ListIndex & "]/list_visibility"		
		Set snodes = SlideList.XMLDocument.selectNodes(query)
		if snodes.length > 0 then		 
			Set snode = SlideList.XMLDocument.selectSingleNode(query)
			GetHideListMetadata = snode.text
		else
			GetHideListMetadata = "visible"
		end if
	else
		GetHideListMetadata = "visible"
	end if
End Function

Sub SetUIMode()
	if IsDividerViewer() then
		gUIMode = GetSectionUIMode()
	else
		if IsObj(SlideList) then  		
			if SlideList.XMLDocument.parseError <> 0 then					
				gUIMode = "NONE"		
			else			
				query = "lecture/initial_ui_mode"		
				Set snodes = SlideList.XMLDocument.selectNodes(query)
				if snodes.length > 0 then		 
					Set snode = SlideList.XMLDocument.selectSingleNode(query)
					gUIMode = snode.text
				else
					gUIMode = "NONE"
				end if
			end if
		else
			gUIMode = "NONE"
		end if
	end if
	
	Select Case gUIMode
	Case "NONE"	
	Case "MAXVIDEO"
		'VideoMax_onClick()		
	Case "MAXSLIDE"
		'SlideMax_onClick()
	Case "ZOOMVIDEO"
		DoZoom 2
	Case "ZOOMSLIDE"
	      	DoZoom 1
	End Select
End Sub

Sub Sn2_OnLiveStop()
	gLiveStop = True
End Sub


'************************************4.0*******************
Sub showTocLayer()
	document.getElementById("td_info").style.display = "none"
	document.getElementById("td_toc").style.display = ""

	HideLayer Info
	ShowLayer ListLayer
End Sub

Sub showInfoLayer()
	document.getElementById("td_toc").style.display = "none"
	document.getElementById("td_info").style.display = ""
	
	HideLayer ListLayer
	ShowLayer Info
End Sub

Sub AboutViewer_onClick()
	HideLayer PenWidthLayer
	HideLayer PenColorLayer

	if not IsObj(CopyrightLayer) then exit sub

	HideLayer TimeLayer
	if CopyrightLayer.innerHTML = "" then 
		txtCopyright = "<table width='100%' height='100%' border=0 cellspacing=0 cellpadding=0>"
		txtCopyright = txtCopyright & "<tr><td class='track' align='right'>"
		txtCopyright = txtCopyright & "Xinics Viewer &copy; Xinics Inc.&nbsp;"
		txtCopyright = txtCopyright & "</td><td width=11></td>"
		txtCopyright = txtCopyright & "</tr></table>"
		CopyrightLayer.innerHTML = txtCopyright
	end if
	CopyrightLayer.style.posLeft = ControlSet.style.posLeft + ControlSet.style.posWidth - CopyrightLayer.style.posWidth
	CopyrightLayer.style.posTop = ControlSet.style.posTop

	ShowLayer CopyrightLayer
End Sub

Sub AboutViewer_Close()
	HideLayer CopyrightLayer
	ShowLayer TimeLayer
End Sub

Sub SetPrevUIMode(Cur)
	IF (Cur > 0) Then
		Cur = Cur -1  'search for previous event
	End IF
 
	Dim Mode
	For counter = Cur To 0 Step -1
		Select Case GetEventItem(counter)
		Case "anizoom slide"
			Mode = "ZOOMSLIDE"
		Case "anizoom video"
			Mode = "ZOOMVIDEO"
		Case "maxslide"
			Mode = "MAXSLIDE"
		Case "maxvideo"
			Mode = "MAXVIDEO"
		End Select
 
		IF Len(Mode) > 0 Then
			Exit For
		End IF
	Next

	IF Len(Mode) > 0 Then
		DoPlayUIMode Mode
	ELSE
		IF IsDividerViewer() Then
			DoPlayUIMode GetSectionUIMode()
		ELSE
			IF IsObj(SlideList) Then
				if SlideList.XMLDocument.parseError = 0 then
					query = "lecture/initial_ui_mode"  
					Set snodes = SlideList.XMLDocument.selectNodes(query)
					if snodes.length > 0 then   
						Set snode = SlideList.XMLDocument.selectSingleNode(query)
						DoPlayUIMode snode.text
					end if
				end if
			End If
		End If
	End If
End Sub
 
Sub DoPlayUIMode(Mode)
	Select Case Mode
	Case "ZOOMSLIDE"
		setTimeout "DoZoom(1)", 10
	Case "ZOOMVIDEO"
		setTimeout "DoZoom(2)", 10
	Case "MAXSLIDE"
		setTimeout "SlideMax_onClick()", 10
	Case "MAXVIDEO"
		setTimeout "VideoMax_onClick()", 10
	Case Else
		setTimeout "DoZoom(1)", 10
	End Select
End Sub
