Index: /gs2-extensions/video-and-audio/trunk/src/web/script/replayer.js
===================================================================
--- /gs2-extensions/video-and-audio/trunk/src/web/script/replayer.js	(revision 23295)
+++ /gs2-extensions/video-and-audio/trunk/src/web/script/replayer.js	(revision 23295)
@@ -0,0 +1,418 @@
+/*!
+ * Replayme Player v1.0.1
+ * Based on JQueryUI v1.8.4
+ * 
+ *
+ * Copyright 2010, Maxime Rouast
+ * Released under the GPL 2 License.
+ *
+ */
+
+
+var relPosTimer_is_on=0;
+var relpos;
+var user_is_dragging=0;
+var checkStatusTimer;
+var checkVideoSizeTimer;
+var previousHeight=0;
+var previousWidth=0;
+var vlc;
+
+
+//Used for the look and feel of the player
+function checkStatus()
+{
+
+	if(vlc.subtitle.count < 1)
+	{
+		$( "#subtitles" ).button( "option", "disabled", true );
+	}
+	else if (vlc.subtitle.count > 0)
+	{
+		$( "#subtitles" ).button( "option", "disabled", false );
+	}
+
+	if (vlc.input.state == 0) {
+		// current media has stopped
+		//onStop();
+		}
+	else if (vlc.input.state == 1) {
+		// current media is connecting
+		onOpening();
+		}
+	else if (vlc.input.state == 2) {
+		// current media is buffering data
+		onBuffering();
+		}
+	else if (vlc.input.state == 3) {
+		// current media is now playing
+		onPlaying();
+		}
+	else if (vlc.input.state == 4) {
+		// current media is now paused
+		//onPaused();
+		}
+	else if (vlc.input.state == 5) {
+		// current media is stopping
+		//onStopping();
+		}
+	else if (vlc.input.state == 6) {
+		// current media has finished playback
+		onEnd();
+		}
+
+	checkStatusTimer=setTimeout(function(){checkStatus()},1000);
+};
+
+function onOpening()
+{
+	$('#play').button('option', {
+		label: 'pause',
+		icons: {
+			primary: 'ui-icon-pause'
+		}
+	});
+	document.getElementById("status").innerHTML = "&nbsp;&nbsp;<img src='" + bufferImgURL + "'>&nbsp;Connecting...";
+}
+
+function onBuffering()
+{
+	$('#play').button('option', {
+		label: 'pause',
+		icons: {
+			primary: 'ui-icon-pause'
+		}
+	});
+	document.getElementById("status").innerHTML = "&nbsp;&nbsp;<img src='" + bufferImgURL + "'>&nbsp;Buffering...";
+}
+
+function onPlaying()
+{
+	$('#play').button('option', {
+		label: 'pause',
+		icons: {
+			primary: 'ui-icon-pause'
+		}
+	});
+	document.getElementById("status").innerHTML = "";
+}
+
+function onEnd()
+{
+	stop();
+	$('#play').button('option', {
+		label: 'play',
+		icons: {
+			primary: 'ui-icon-play'
+		}
+	});
+	$( "#subtitles" ).button( "option", "disabled", true );
+}
+
+function prepare(mrl)
+{
+//Wait for the player to be initialized before doing anything
+vlc = document.getElementById("vlc");
+var safeMRL = encodeURI(mrl);
+setTimeout(function(){vlc.playlist.add(safeMRL)},350);
+setTimeout(function(){play()},500);
+setTimeout(function(){checkStatus()},500);
+};
+
+function play()
+{
+	vlc.playlist.play();
+	vlc.video.deinterlace.enable("blend");
+	//if (relPosTimer_is_on!=1)
+	//{
+		relPosTimer_is_on=1;
+		showRelPos();
+	//}
+};
+
+function showRelPos()
+{
+	if (relPosTimer_is_on=1)
+	{
+		if (vlc.input.position>=0 && vlc.input.position<=1 && user_is_dragging==0)
+		{
+			$('#slider').slider( "option", "value", vlc.input.position );
+		}
+		relpos=setTimeout(function(){showRelPos()},250);
+	}
+};
+
+function stop()
+{
+	clearTimeout(relpos);
+	clearTimeout(checkStatusTimer);
+	relPosTimer_is_on=0;
+	vlc.playlist.stop();
+	vlc.subtitle.track = 0;
+	$('#slider').slider( "option", "value", 0 );
+	$( "#subtitles" ).button( "option", "label", "Subtitles");
+};
+
+function togglePause()
+{
+	vlc.playlist.togglePause();
+};
+
+function toggleMute()
+{
+    vlc.audio.toggleMute();
+};
+ 
+function getBrowserWidth()
+{
+    xWidth = null;
+    if(window.screen != null)
+      xWidth = window.screen.availWidth;
+ 
+    if(window.innerWidth != null)
+      xWidth = window.innerWidth;
+ 
+    if(document.body != null) {
+		if ((typeof document.compatMode != "undefined")
+		  && (document.compatMode == "CSS1Compat")) {
+			// in Strict mode
+			xWidth =  document.documentElement.clientWidth;
+		}
+		else {
+			// Quirks mode
+			xWidth = document.body.clientWidth;
+		}
+	}
+	
+    return xWidth;
+ };
+ 
+function getBrowserHeight() {
+  xHeight = null;
+  if(window.screen != null)
+    xHeight = window.screen.availHeight;
+ 
+  if(window.innerHeight != null)
+    xHeight =   window.innerHeight;
+ 
+  if(document.body != null){
+		if ((typeof document.compatMode != "undefined")
+		  && (document.compatMode == "CSS1Compat")) {
+			// in Strict mode
+			xHeight =  document.documentElement.clientHeight;
+		}
+		else {
+			// Quirks mode
+			xHeight = document.body.clientHeight;
+		}
+	}
+  return xHeight;
+};
+
+function setFullscreenSize()
+{
+	var height = getBrowserHeight() - 8;
+	var width = getBrowserWidth() - 8;
+	$( "#replaymePlayer" ).dialog( "option", "position", ['left','top'] );
+	$( "#replaymePlayer" ).dialog( "option", "height", height );
+	$( "#replaymePlayer" ).dialog( "option", "width", width );
+	setPlayerSize();
+	checkVideoSizeTimer=setTimeout(function(){setFullscreenSize()},1000);
+}
+
+function toggleFullscreen()
+{
+	vlc.video.toggleFullscreen();
+	
+	if (vlc.video.fullscreen == true)
+	{
+		previousHeight = $( "#replaymePlayer" ).dialog( "option", "height" );
+		previousWidth = $( "#replaymePlayer" ).dialog( "option", "width" );
+		setFullscreenSize();
+	}
+	else if (vlc.video.fullscreen == false)
+	{
+		clearTimeout(checkVideoSizeTimer);
+		$( "#replaymePlayer" ).dialog( "option", "height", previousHeight );
+		$( "#replaymePlayer" ).dialog( "option", "width", previousWidth );
+		setPlayerSize();
+		$( "#replaymePlayer" ).dialog( "option", "position", 'center' );
+	}
+};
+
+function changeSubtitles()
+{
+   if (vlc.subtitle.track == vlc.subtitle.count - 1)
+   {
+		vlc.subtitle.track = 0;
+   }
+   else
+   {
+		vlc.subtitle.track = vlc.subtitle.track + 1;
+   }
+	$( "#subtitles" ).button( "option", "label", "Subtitles: " + vlc.subtitle.description(vlc.subtitle.track) );
+};
+
+function seek()
+{
+	vlc.input.position = $('#slider').slider( "option", "value" );
+	user_is_dragging=0;
+};
+
+function setPlayerSize()
+{
+	var width = 0, height = 0;
+	
+	width = $( "#replaymePlayer" ).dialog( "option", "width" );
+	height = $( "#replaymePlayer" ).dialog( "option", "height" );
+	width = width - 25;
+	height = height - 130;
+
+	if (document.getElementById("vlc") != null)
+	{
+	document.getElementById("vlc").style.height = height + "px";
+	document.getElementById("vlc").style.width = width + "px";
+	}
+};
+
+//JQuery Stuff
+$(function() {
+						
+// Open Video Player link
+				$('#open_player_link').click(function(){
+					$('#replaymePlayer').dialog('open');
+					return false;
+				});
+
+						
+//Video Player window					
+	$("#replaymePlayer").dialog({
+			autoOpen: false,
+			height: 620,
+			width: 645,
+			modal: true,
+			beforeclose: function(event, ui) {
+												onEnd();
+												$('#mute').button({
+													label: 'mute',
+													icons: {
+													primary: 'ui-icon-volume-on'
+													}
+												});
+												$( "#subtitles" ).button( "option", "label", "Subtitles");
+											},
+			resizeStart: function(event, ui) { 
+												document.getElementById("vlc").style.height = "70%";
+												document.getElementById("vlc").style.width = "100%";},
+			resizeStop: function(event, ui) { setPlayerSize(); }
+		});
+		
+//Hover states on the Video Player link
+	$('#open_player_link, ul#icons li').hover(
+				function() { $(this).addClass('ui-state-hover'); }, 
+				function() { $(this).removeClass('ui-state-hover'); }
+		);
+
+		
+//Player toolbar:
+		$('#play').button({
+			text: false,
+			icons: {
+				primary: 'ui-icon-play'
+			}
+		})
+		.click(function() {
+			var options;
+			if ($(this).text() == 'play') {
+			play();
+				options = {
+					label: 'pause',
+					icons: {
+						primary: 'ui-icon-pause'
+					}
+				};
+			} else {
+			togglePause();
+				options = {
+					label: 'play',
+					icons: {
+						primary: 'ui-icon-play'
+					}
+				};
+			}
+			$(this).button('option', options);
+		});
+		
+		$('#stop').button({
+			text: false,
+			icons: {
+				primary: 'ui-icon-stop'
+			}
+		})
+		.click(function() {
+			stop();
+			$('#play').button('option', {
+				label: 'play',
+				icons: {
+					primary: 'ui-icon-play'
+				}
+			});
+		});
+		
+		$('#mute').button({
+			text: false,
+			icons: {
+				primary: 'ui-icon-volume-on'
+			}
+		})
+		.click(function() {
+			var options;
+			if ($(this).text() == 'mute on') {
+			toggleMute();
+				options = {
+					label: 'mute off',
+					icons: {
+						primary: 'ui-icon-volume-on'
+					}
+				};
+			} else {
+			toggleMute();
+				options = {
+					label: 'mute on',
+					icons: {
+						primary: 'ui-icon-volume-off'
+					}
+				};
+			}
+			$(this).button('option', options);
+		});
+		
+		$('#fullscreen').button({
+			text: false,
+			icons: {
+				primary: 'ui-icon-arrow-4-diag'
+			}
+		})
+		.click(function() {
+		toggleFullscreen();
+		});
+		
+		$('#subtitles').button({
+			icons: {primary: 'ui-icon-grip-dotted-horizontal'},
+			disabled: true
+		})
+		.click(function() {
+		changeSubtitles();
+		});
+		
+//Seeking bar
+		$('#slider').slider({
+						start: function(event, ui) {user_is_dragging=1;},
+						stop: function(event, ui) {seek();},
+						animate: true,
+						min: 0,
+						max: 1,
+						step: 0.000125
+						});
+
+});
