/** xmoov edit **/
var FlashPlayers = {}

FlashPlayers.old = "flash_player/preview.swf";
FlashPlayers.xmoovStream_1_0 = "/apps/flash/video/player.swf";
/** end xmoov edit **/

var VideoPlayer = {}

VideoPlayer.CenterBy = "";
VideoPlayer.Container = "";
VideoPlayer.VideoUrl = "";
VideoPlayer.ClickToPlayId = "";
VideoPlayer.VideoWidth = 0;
VideoPlayer.VideoHeight = 0;
VideoPlayer.Type = 0;
/** xmoov edit **/
VideoPlayer.FlashSwf = FlashPlayers.xmoovStream_1_0;
/** end xmoov edit **/
VideoPlayer.ClickToPlay = function()
{
	if(!document.getElementById(VideoPlayer.ClickToPlayId)) return false;
	Data = "<img src='/images/click_to_play.png' style='position:absolute; z-index:9999; display:block; visibility:hidden; left:0; top:0; cursor:pointer;' onclick='VideoPlayer.ClickedToPlay();' id='click_to_play'/>";
	document.getElementById(VideoPlayer.ClickToPlayId).innerHTML = Data;
	center('click_to_play',VideoPlayer.CenterBy);
	document.getElementById("click_to_play").style.visibility = "visible";	
}
function is_iDevice()
{
	if (Navigator.match("iPhone") || Navigator.match("iPod") || Navigator.match("iPad")) return true;
	return false;
}
VideoPlayer.ClickedToPlay = function()
{
	if (is_iDevice())
	{
		window.open(VideoPlayer.VideoUrl,'video');
		//window.location = VideoPlayer.VideoUrl;
		return;
	}
	else if(VideoPlayer.Type == "mobile")
	{
		var Data = VideoPlayer.MobilePlayer();
	}
	else if(VideoPlayer.Type == "flv")
	{
		var Data = VideoPlayer.FlvVideo();
	}	
	else if(VideoPlayer.Type == "embed")
	{
		var Data = VideoPlayer.EmbededVideo();
	}
	else if(VideoPlayer.Type == "mpg")
	{
		var Data = VideoPlayer.MpgVideo();
	}
	else if(VideoPlayer.Type == "avi")
	{
		var Data = VideoPlayer.AviVideo();
	}		
	xmoov_debug('isMobile='+isMobile());
	xmoov_debug('VideoPlayer.Type='+VideoPlayer.Type);
	xmoov_debug('VideoPlayer.VideoUrl='+VideoPlayer.VideoUrl);
	
	
	document.getElementById(VideoPlayer.Container).innerHTML = Data;
	
	if(document.getElementById("videoembeded"))
		document.getElementById("videoembeded").play();
	
	/** xmoov edit **/
	
	/*if(VideoPlayer.Type == "flv")
	{
		// <![CDATA[
		var so = new SWFObject(VideoPlayer.FlashSwf, "main", VideoPlayer.VideoWidth, VideoPlayer.VideoHeight, "8", "#000000");
		
		so.addParam("allowFullScreen", "true");
		so.addVariable("MediaLink", VideoPlayer.VideoUrl);

		so.addVariable("playOnStart", "true");
		so.addVariable("startVolume", "70");
		so.addVariable("autoHideOther", "false");
		so.addVariable("autoHideVideoControls", "false");
		so.addVariable("onStartShowControls", "true");
		so.addVariable("fullVideoScale", "false");
		so.addVariable("showPlayButton", "true");
		so.addVariable("share", "false");

		so.write("flashdiv");
		// ]]>
		
	}*/
	
	if(VideoPlayer.Type == "flv")
	{
		// <![CDATA[
		var so = new SWFObject(VideoPlayer.FlashSwf, "main", VideoPlayer.VideoWidth, VideoPlayer.VideoHeight, "8", "#000000");
		so.addParam("allowFullScreen", "true");
		so.addVariable("video", VideoPlayer.VideoUrl);
		/*so.addVariable("streamer", "true");*/

		so.write("flashdiv");
		// ]]>
		
	}
	
	/** end xmoov edit **/
	
	document.getElementById(VideoPlayer.ClickToPlayId).innerHTML = "";
	
	
}

VideoPlayer.EmbededVideo = function()
{
	var Data = "";

	Data='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="320" '
	+'height="30" codebase="http://www.apple.com/qtactivex/qtplugin.cab">'
	+'<param name="src" value="'+ VideoPlayer.VideoUrl +'">'
	+'<param name="qtnext1" value="<binairyproxy.php?enc_url=aHR0cDovL2xvY2FsaG9zdDozNjg5L2RhdGFiYXNlcy8xL2l0ZW1zLzcw> T<myself>">'
	+'<param name="autoplay" value="true">'
	+'<param name="controller" value="true">'
	+'<param name="loop" value="false">'
	+'<embed src="'+ VideoPlayer.VideoUrl +'"'
	+' bgcolor="000000"'
	+' width="320" height="255" autoplay="true"'
	+' qtnext1="<binairyproxy.php?enc_url=aHR0cDovL2xvY2FsaG9zdDozNjg5L2RhdGFiYXNlcy8xL2l0ZW1zLzcw> T<myself>" '
	+'controller="true" loop="false" pluginspage="http://www.apple.com/quicktime/download/"></embed>'
	+'</object>';	
	//return Data;
}

VideoPlayer.FlvVideo = function()
{

	
	Data = Data + '<div id="VideoPlayerObj" style="width:'+VideoPlayer.VideoWidth+'px;width:'+VideoPlayer.VideoHeight+'px; position:absolute; margin-top:'+VideoPlayer.VideoTop+'px; margin-left:'+VideoPlayer.VideoLeft+'px;">';	


		Data = Data + '<div id="flashdiv"><strong>You need to upgrade your Flash Player</strong>';
		Data = Data + '</div>';

	Data = Data + '</div>';
	
	
	return Data;
	
}

VideoPlayer.AviVideo = function()
{
	var Data = "";
	Data = Data + '<div style="width:'+VideoPlayer.VideoWidth+'px;width:'+VideoPlayer.VideoHeight+'px; position:absolute; margin-top:'+VideoPlayer.VideoTop+'px; margin-left:'+VideoPlayer.VideoLeft+'px;">';	


	Data = Data + '<object type="video/avi" data="'+VideoPlayer.VideoUrl+'" width="'+VideoPlayer.VideoWidth+'" height="'+VideoPlayer.VideoHeight+'">';
	Data = Data + '<param name="autoplay" value="true" />';
	Data = Data + ' <param name="src" value="'+VideoPlayer.VideoUrl+'" />';	
	Data = Data + '</object>';

	Data = Data + '</div>';
	
	return Data;
	
}

VideoPlayer.MpgVideo = function()
{
	var Data = "";
	Navigator = navigator.userAgent;
	if(Navigator.match("Firefox"))
	{	
		VideoPlayer.VideoWidth = Number(VideoPlayer.VideoWidth) - 32;
		VideoPlayer.VideoHeight = Number(VideoPlayer.VideoHeight) - 24;
	}
	else if(Navigator.match("Safari") || Navigator.match("Opera"))
	{
		VideoPlayer.VideoHeight = Number(VideoPlayer.VideoHeight) + 16;
	}

	Data = Data + '<div style="width:'+VideoPlayer.VideoWidth+'px;width:'+VideoPlayer.VideoHeight+'px; position:absolute; margin-top:'+VideoPlayer.VideoTop+'px; margin-left:'+VideoPlayer.VideoLeft+'px;">';	


	Data = Data + '<object type="video/mpeg" data="'+VideoPlayer.VideoUrl+'" width="'+VideoPlayer.VideoWidth+'" height="'+VideoPlayer.VideoHeight+'">';
	Data = Data + '<param name="autoplay" value="true" />';
	Data = Data + ' <param name="src" value="'+VideoPlayer.VideoUrl+'" />';	
	Data = Data + '</object>';

	Data = Data + '</div>';
	
	return Data;
	
}


VideoPlayer.MobilePlayer = function()
{
	var Data = "";
	Navigator = navigator.userAgent;
	if(Navigator.match("Firefox"))
	{	
		VideoPlayer.VideoWidth = Number(VideoPlayer.VideoWidth) - 32;
		VideoPlayer.VideoHeight = Number(VideoPlayer.VideoHeight) - 12;
		VideoPlayer.VideoLeft= OpenMidSize.ImageTop(VideoPlayer.VideoWidth);
		VideoPlayer.VideoTop = OpenMidSize.ImageLeft(VideoPlayer.VideoHeight);		
	}
	else if(Navigator.match("Safari") || Navigator.match("Opera"))
	{
		VideoPlayer.VideoHeight = Number(VideoPlayer.VideoHeight) + 16;
	}
	
	Data = Data + '<div style="width:'+VideoPlayer.VideoWidth+'px;height:'+VideoPlayer.VideoHeight+'px; position:absolute; text-align:center; margin-top:'+VideoPlayer.VideoTop+'px; margin-left:'+VideoPlayer.VideoLeft+'px;">';	

	//Data = Data + '	<embed id="videoembeded"  src="'+VideoPlayer.VideoUrl+'" width="320" height="240" href="/thumb/fecbb9f6c4f5-955be9ed-347eeab5-a26154be.jpg" autoplay="true" showlogo=false" target="myselft" autohref="true">';
	Data = Data + '	<embed id="videoembeded"  src="'+VideoPlayer.VideoUrl+'" width="320" height="240" autoplay="true" showlogo=false" autohref="true"></embed>';

	Data = Data + '</div>';
	return Data;
	
}

/*
function _FixIEController(element)
{
	if(navigator.appName != "Microsoft Internet Explorer")
		return;

	var movieObj = element.lastChild;

	if(!movieObj.GetControllerVisible());
		setTimeout( function() { movieObj.SetControllerVisible(true); }, 100);
}

function _FixOperaOpacity(element)
{
	if(navigator.appName != "Opera")
		return;

	element.style.opacity = "1.0";
}

function QT_ReplaceWithPoster()
{
	
      var args = Array.prototype.slice.call(arguments);
	 
	//  alert(args);
      var clickText = args.shift();
	 
      var posterSrc = args.shift();
	
	//  alert(args);
      var element = args.shift();
	 // alert(element);

      var src = args[0];
	
      var width = args[1];

      var height = args[2];

		if (navigator.platform.indexOf('iPhone') > -1) 
		{
		
 			QT_ReplaceElementContents(element, 
        posterSrc,
				width, height, '',
				'href', src,
				'target', 'myself',
				'controller', 'false', 
				'autoplay', 'true', 
				'scale', 'aspect');
				
				
		}
		else
		{
		
			

			
			//element.style.position = 'relative';
			element.style.width = width + 'px';
			
			element.style.height = height + 'px';
			//element.style.textAlign = 'center';
			element.style.backgroundImage = 'url(' + posterSrc + ')';
			element.style.backgroundRepeat = 'no-repeat';
			element.style.backgroundPosition = 'top center';
			element.args = args;

			var play = element.appendChild(document.createElement('span'));
			play.innerHTML = clickText;
			play.className = 'playButton';
			_FixOperaOpacity(play);

			element.onclick = function() {


			if(OpenMidSize.PlayVideo() == false)
			{

				return false;
			}
			
			
        element.onclick = '';
        play.style.display = 'none';
        var playBackground = element.appendChild(document.createElement('div'));
        playBackground.className = 'playBackground';
        playBackground.style.opacity = '0';
        playBackground.style.width = element.style.width;
        playBackground.style.height = element.style.height;

        var intervalId = setInterval(function() {
          var opacity = parseFloat(playBackground.style.opacity);
          opacity = Math.min(1.0, opacity + 0.2);
          playBackground.style.opacity = opacity;
          playBackground.style.filter = 'alpha(opacity='+(opacity*100)+')';
          }, 25);


        setTimeout(function() {
            clearInterval(intervalId); 
            element.style.backgroundImage = '';
            element.style.backgroundColor = 'rgb(0,0,0)';
            playBackground.style.opacity = '1.';
            playBackground.style.filter = 'alpha(opacity=100)';

            var	txt = QT._Generate("QT_WriteOBJECT_XHTML", true, args);
            if(txt.length > 0)
              element.innerHTML = txt;

              _FixIEController(this);
          }, 250);
      }
		}
}

function QT_WritePoster_XHTML()
{
	var args = Array.prototype.slice.call(arguments);
	var clickText = args.shift();
	var posterSrc = args.shift();
	var src = args[0];
	var width = args[1];
	var height = args[2];

	if (navigator.platform.indexOf('iPhone') > -1) 
	{
		QT_WriteOBJECT_XHTML( posterSrc,
			width, height, '',
			'href', src,
			'target', 'myself',
			'controller', 'false', 
			'autoplay', 'true', 
			'scale', 'aspect');
	}
	else
	{
		var id = 'datadiv2';
		document.getElementById("GalleryVideoPlay").innerHTML='<div id="'+id+'"></div>';
		var element = document.getElementById(id);
		element.id = 'datadiv2';
		element.style.position = 'relative';
		element.style.width = width + 'px';
		element.style.height = height + 'px';
		element.style.textAlign = 'center';
		element.style.backgroundImage = 'url(' + posterSrc + ')';
		element.style.backgroundRepeat = 'no-repeat';
		element.style.backgroundPosition = 'top center';

		var play = element.appendChild(document.createElement('span'));
		play.innerHTML = clickText;
		play.className = 'playButton';
		_FixOperaOpacity(play);

		element.onclick = function() { 
			element.onclick = '';
			play.style.display = 'none';
			var playBackground = element.appendChild(document.createElement('div'));
			playBackground.className = 'playBackground';
			playBackground.style.opacity = '0';
			playBackground.style.width = element.style.width;
			playBackground.style.height = element.style.height;

			var intervalId = setInterval(function() {
			var opacity = parseFloat(playBackground.style.opacity);
			opacity = Math.min(1.0, opacity + 0.2);
			playBackground.style.opacity = opacity;
			playBackground.style.filter = 'alpha(opacity='+(opacity*100)+')';
			}, 25);


			setTimeout(function() {
				clearInterval(intervalId); 
				element.style.backgroundImage = '';
				element.style.backgroundColor = 'rgb(0,0,0)';
				playBackground.style.opacity = '1.';
				playBackground.style.filter = 'alpha(opacity=100)';

				var txt = _QTGenerate("QT_WriteOBJECT_XHTML", true, args);
				if(txt.length > 0)
				element.innerHTML = txt;

				_FixIEController(element);
			}, 250);
		}
	}
}
*/
