<?xml version="1.0" encoding="UTF-8"?>
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<include src="button.xml"/>

 	<define name="VIDEOPATH" value="':mmlab.chemcommon.info:resources\\video\\'" />
	<composition _name="CVPreviewBtn" >

		<image _name="iactive" src="eval(VIDEOPATH+'active.png')" visible="false"/>
		<image _name="iinactive" src="eval(VIDEOPATH+'inactive.png')" _visible="false" />
		<styles _name="stlActive" fontSize="12"  fontFamily="Verdana"  textAlign="center" color="#24557E"/>
		<styles _name="stlInactive" fontSize="14"  fontFamily="Verdana"  textAlign="center" color="#1693A7"/>
		<text _name="txt" style="stlActive" _x="0" y="-1" > </text>

		<script>
			function	Activate(val)
			{
				if( val == undefined)
					val = true;
				if(val)
				{
					txt.style = stlActive;
				if(scene.videowall.aVideoTxts[scene.idVideo] == undefined){
					if (scene.VideoLep != undefined) {
 						curLep=eval('scene.Lep'+scene.VideoLep);
 						txt.value=curLep.videowall.aVideoTxts[scene.idVideo];
 					}else{
						txt.value="";
					}
				}
				else{
						txt.value=scene.videowall.aVideoTxts[scene.idVideo];

				}
					txt.show();
					scene.videowall.addHotspot(txt);
				}
				else
				{
					txt.style = stlInactive;
					txt.hide();
				}
			}

			Activate(false);
//hide();
		</script>
	</composition>

	<composition _name="CBaseVideoSlider">
		<script>
			this.ms = 0;
			this.px = 0;
			this.currentVideo = null;
			this.wall = null;
			this.savedMode = "";
		</script>
		<image _name="lLim" src="eval(VIDEOPATH+'slider.png')" enabled="false" />
		<image _name="rLim" src="eval(VIDEOPATH+'slider.png')" enabled="false"/>
		<image _name="line" src="eval(VIDEOPATH+'slider.png')" enabled="false"/>
		<image _name="lslider" src="eval(VIDEOPATH+'slider.png')" _y="-1" enabled="false"/>
		<image _name="rslider" src="eval(VIDEOPATH+'slider.png')" _y="-1" enabled="false" depth="-1"/>
		<image _name="slider" src="eval(VIDEOPATH+'slider.png')" _y="-1" enabled="false"/>
		<button _name="hsslider" hitArea="[0,0,0,0]" enabled="true" _depth="-2">
			<script event="onPress">
					if( parent.ms != 0)
					{
						var pos = this.xMouse/parent.px*parent.ms;
						parent.parent.SetCurrentVideoPos(pos);
						parent.SetSliderPositionMS(pos);
					}
			</script>
		</button>
		<script><![CDATA[
			function Initialize(ams)
			{trace('slider '+ams);
				ms = ams;
			}

			function SetLength(px)
			{
				// cropping


				lLim.crop(0,0,2,9);
				rLim.crop(38,0,2,9);
				line.crop(2,0,36,9);
				slider.crop(17,9,2,11);
				lslider.crop(12,9,2,11);
				rslider.crop(19,9,6,11);
				// arranging
				line._x = lLim._x + lLim._width;
				line._width = px - lLim._width - rLim._width;
				this.px = line._width - slider._width;
				rLim._x = lLim._x + lLim._width + line._width;
				hsslider.hitArea = "[0,0,"+px+",20]";
			}

			function SetSliderPositionMS(ams)
			{
				slider.x = lLim.x + lLim.width - 1;
				lslider.x = slider.x;
				if( ms != 0)
				{
					var a = ams/ms*px;
					slider.width = (a==0)?1:a;
					rslider.x = slider.x + a - 1;
					slider.show();
					lslider.show();
					rslider.show();
				}
				else
				{
					slider.hide();
					lslider.hide();
					rslider.hide();
				}
				parent.FrameChanged();
			}

			function SetControlledVideo(vd)
			{
				this.currentVideo = vd;
			}

			function TracePosition(tr)
			{
				seqPosition._playing = tr;
			}
		]]></script>
		<sequencer _name="seqPosition" _loop="true">
			<script>
				if( this.currentVideo != null)
				{
					SetSliderPositionMS( this.currentVideo.currentPos);
					if( this.currentVideo._playing)
						250;
					else
						false;
				}
			</script>
		</sequencer>
	</composition>
	<composition _name="CVideoWall"  class="CDraggableComposition" userEvents="evPlayed, evMinimized,evClosed, evFirstPlayed" _x="150" _y="50" >
		<script>

			this.extraHeight = 0;
			this.wallHeight = 0;
			this.aVideos = new Array();
			this.aVideoTxts = new Array();
			this.aVideoNum = new Array();// массив флажков показывает, что ситуация с видео нестандартная
			this.aPlayedCount = new Array();
			this.aFirstPlayed = new Array();
			this.currentVideo = null;
			this.uiMode = "stop";
			this.screenMode = "";
			//this.openedHeight = 295; //389 - для 448х336
			this.openedHeight = 391;// - для 448х336
			this.closedHeight = 51;
			this.screenHeight = this.openedHeight;
			this.useOnlyClientArea = true;
			this.onFrameChanged = null;
			this.addHotspot(walltop);

		</script>
		<image _name="walltop" src="eval(VIDEOPATH+'walltop.png')"/>
		<image _name="wallcenter" src="eval(VIDEOPATH+'wallcenter.png')" _y="42" _height="0"/>
		<image _name="wallbottom" src="eval(VIDEOPATH+'wallbottom.png')" _y="37"/>

		<composition _name="btPlay" _class="CVideoButton" _x="35" visible="true" >
			<image _name="img" src="eval(VIDEOPATH+'btPlay.png')" />
		</composition>
 		<composition _name="btStop" _class="CVideoButton" _x="35" _visible="false">
			<image _name="img" src="eval(VIDEOPATH+'btPause.png')" />
		</composition>
		<composition _name="btRewind" _class="CVideoButton" _x="4" >
			<image _name="img" src="eval(VIDEOPATH+'btBack.png')" />
		</composition>
		<composition _name="btClose" _class="CVideoButton" x="10" _visible="false" >
			<image _name="img" src="eval(VIDEOPATH+'btClose.png')" />
		</composition>
		<composition _name="btCloseDisable" _class="CVideoButton" x="435" y="3" visible="false" >
			<image _name="img" src="eval(VIDEOPATH+'btCloseDisable.png')" />
		</composition>
		<composition _name="btOpen" _class="CVideoButton" _x="10" _visible="false">
			<image _name="img" src="eval(VIDEOPATH+'btOpen.png')" />
		</composition>
		<composition _name="slider" _class="CBaseVideoSlider" _x="10" _visible="false" >
			<script>
				this.wall = parent;
			</script>
		</composition>
		<script>
			function FrameChanged()
			{
				if( onFrameChanged != null)
				{
					if(currentVideo != null)
						onFrameChanged( currentVideo.currentPos);
					else
						onFrameChanged( 0);
				}
			}
		</script>
		<script event="btPlay.onClick">
			SetUIMode("play");
			PlayCurrentVideo();
		</script>
		<script event="btStop.onClick">
			SetUIMode("stop");
			StopCurrentVideo();
		</script>
		<script event="btRewind.onClick">
			SetUIMode("stop");
			slider.SetSliderPositionMS(0);
			RewindCurrentVideo();
			FrameChanged();
		</script>
		<script event="btOpen.onClick">
			ShowNormal();
		</script>
		<script event="btClose.onClick">
			Closing();
		</script>
		<script><![CDATA[
			function setExtraHeight(extra)
			{
				this.extraHeight = extra;
			}

			function CheckLayout()
			{
				wallcenter._y = walltop._height;
				wallcenter._height = this.screenHeight - walltop._height - wallbottom._height + this.extraHeight;
				wallbottom._y = wallcenter._y + wallcenter._height;
				wallHeight = walltop._height + wallcenter._height + wallbottom._height;

				// arrange buttons
				btPlay._y = wallHeight - 30 - this.extraHeight;
				btStop._y = wallHeight - 30 - this.extraHeight;
				btRewind._y = wallHeight - 30 - this.extraHeight;

				// arrange slider
				slider._x = 67;

				slider._y = wallHeight - 27 - this.extraHeight;

				// arrange window controls
				btOpen._x = walltop._width - 19;
				btClose._x = walltop._width - 19;
				btOpen._y = 3;	btClose._y = 3;
			}

			function ShowNormal()
			{
				if( this.screenMode == "opened")	return;
				//btOpen._visible = false;
				btClose._visible = true;
				if( currentVideo != null)
				{
 					slider._visible = true;
 					currentVideo._visible = true;
 					currentVideo.stop();
				}
				SetUIMode(uiMode);
				//SetUIMode("stop");
				this.screenMode = "opened";
				screenHeight = openedHeight;
				CheckLayout();


			}

			function Minimize()
			{
				if( this.screenMode == "closed")	return;
			   	//btOpen._visible = true;
				btClose._visible = false;
				slider._visible = false;
				if( currentVideo != null)
				{
					currentVideo._visible = false;
					StopCurrentVideo();
				}
				SetUIMode("stop");
				SetUIMode("hidden");
				this.screenMode = "closed";
				screenHeight = closedHeight - this.extraHeight;
				CheckLayout();
				fireEvent("evMinimized");

				if( currentVideo!=null && !aFirstPlayed[currentVideo.id])
				{
					aFirstPlayed[currentVideo.id] = true;
					Event.videoId = currentVideo.id;
					fireEvent("evFirstPlayed");
				}
			}
			function Closing()
			{
				if( this.screenMode == "closed")	return;

				this.hide();
				this.modal=false;
				scene.bVideo=false;
 				if( currentVideo != null)
 				{

 					StopCurrentVideo();
 				}
 				SetUIMode("stop");
 				CheckLayout();
 				if( currentVideo!=null && !aFirstPlayed[currentVideo.id])
 				{
 					aFirstPlayed[currentVideo.id] = true;
 					Event.videoId = currentVideo.id;
 					fireEvent("evFirstPlayed");
 				}
			}

		function AddVideo(path,ttxt,for_more_than_one)
		{

				var vd = new Video();
			if (resourceExists(path)){	vd.src = ":"+path;
			}			//vd._visible = false;
				vd._visible = true;
				vd.windowed=false;
				vd._x = 3;
				vd._y = 22;
				vd._depth = -10;
				aVideos[aVideos.length] = vd;
				aPlayedCount[aPlayedCount.length] = 0;
				aFirstPlayed[aFirstPlayed.length] = false;
				vd.id = aVideos.length-1;
				aVideoTxts[aVideos.length-1] = ttxt;
				trace(aVideoTxts);
				if (for_more_than_one!= undefined){
					aVideoNum[aVideos.length-1] = for_more_than_one;  // массив флажков показывает, что ситуация с видео нестандартная
				}
				vd.parent = this;

				vd.onPlayed = function(){
					OnVideoPlayed(this.id);
				};


				if( this.screenMode != "closed" && this.currentVideo == null)
				{
					OnPreviewSelected(aVideos.length-1)
				}
				else
				{
				}


 				var vdtext = new Composition();
 				vdtext._class="CVPreviewBtn";
 			//	vdtext._x = 12 + (aVideos.length-1) * 25;
 				vdtext._x = 6 ;//+ (aVideos.length-1) * 25;
 				vdtext._y = 3;
				vdtext.txt.value = ""+aVideoTxts;
 				vdtext.id = aVideos.length-1;
 				vdtext.name = "preview"+vdtext.id;
				vdtext.parent = this;

  		}

			function SelectVideo(n)
			{
				OnPreviewSelected(n);
			}

			function SelectVideo(n)
			{
				OnPreviewSelected(n);
			}

			function OnPreviewSelected(n)
			{
				scene.idVideo=n;
				for(i=0; i<aVideos.length; i++)
					if( i == n)
					{
						eval("preview"+aVideos[i].id).Activate();
						SetCurrentVideo(aVideos[i]);
					}
					else
					{
						eval("preview"+aVideos[i].id).Activate(false);
						aVideos[i]._visible = false;
					}
				ShowNormal();
			}

			function SetCurrentVideo(vd)
			{
				// stop current video
				if( this.currentVideo != null)
				{
					//this.currentVideo.stop();
					StopCurrentVideo();
				}
				// rewind new video
				this.currentVideo = vd;
				this.currentVideo.rewind();
				slider.Initialize(this.currentVideo._duration);
				slider.SetSliderPositionMS(0);
				slider.SetControlledVideo(this.currentVideo);
				if( screenMode == "opened")
				{
					this.currentVideo._visible = true;
					slider._visible = true;
				}
				else	if( screenMode == "closed")
				{
					this.currentVideo._visible = false;
					slider._visible = false;
				}
			}

			function SetUIMode(amode)
			{
				if(amode == "play")
				{
					btPlay._visible = false;
					btStop._visible = true;
					btRewind.enabled = true;
				}
				else	if(amode == "stop")
				{
					btPlay._visible = true;
					btStop._visible = false;
					btRewind.enabled = true;
				}
				else if(amode == "hidden")
				{
					btStop._visible = false;
				}
				if( amode != "hidden")
				uiMode = amode;
			}

			function PlayCurrentVideo()
			{

				if( this.currentVideo!=null)
				{
					ShowNormal();
					this.currentVideo.play();
					slider.TracePosition(true);
					SetUIMode("play");
				}
				else
				{
					SetUIMode("stop");
					slider.TracePosition(false);
				}
			}

			function StopCurrentVideo()
			{

				if( this.currentVideo!=null)
					this.currentVideo._playing = false;
				SetUIMode("stop");
				slider.TracePosition(false);
			}

			function RewindCurrentVideo()
			{
				if( this.currentVideo!=null)
					this.currentVideo.rewind();
				SetUIMode("stop");
			}

			function SetCurrentVideoPos(pos)
			{
				if( this.currentVideo==null)	return;
				this.currentVideo.currentPos = pos;
				if( uiMode == "play")
					this.currentVideo.play();
			}

			function PauseCurrentVideo()
			{
				if( this.currentVideo!=null)
					this.currentVideo.stop();
			}

			function OnVideoPlayed(id)
			{
				if( id < aPlayedCount.length)
					aPlayedCount[id]++;
				slider.SetSliderPositionMS(0);
				RewindCurrentVideo();
				SetUIMode("stop");
				Event.videoId = id;
				Event.playedCount = aPlayedCount[id];
				fireEvent("evPlayed");
				if( !aFirstPlayed[id])
				{
					aFirstPlayed[id] = true;
					Event.videoId = id;
					fireEvent("evFirstPlayed");
				}
			}

			function GetPlayedCount(id)
			{
				if( id < aPlayedCount.length)	return aPlayedCount[id];
				return 0;
			}
		//	slider.SetLength(255); // 255 для 320х240
			slider.SetLength(380); // 380 для 448х336
		]]></script>

		<script>
			this.needReportHelp =  true;
		</script>


		<sequencer name="seqJournalShown">
			<script>
				7000;
			</script>
			<script>
				if( scene.sengine!=undefined )
					scene.sengine.scplay(45);
			</script>
		</sequencer>
	</composition>
</rmml>
