var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function getPlaterFlash(){
	var player_smallObj = isInternetExplorer ? document.all.player_small : document.player_small;
	return player_smallObj;
}
function player_small_DoFSCommand(command, args){
	switch(command)
	{
		case 'mute':
			if( args == 'true' )
			{
				Player.settings.mute = false;
			}
			else
			{
				Player.settings.mute = true;
			}
		break;
		case 'play':
			mediaplay();
		break;
		case 'stop':
			hideMedia();
			Player.controls.Stop();
		break;
		case 'setsound':
			Player.settings.volume = args;
		break;
	}
}
var isStop = false;
var onPlayStateChange = function(Player, NewState)
{
	if( NewState == 1 )
	{
		hideMedia();
	}
	else if( NewState == 10 )
	{
		if( isStop )
		{
			hideMedia();
			isStop = false;
		}
		else
		{
		}
	}
	else if( NewState == 8  )
	{
		isStop = true;
	}
};
var onMediaError = function(_errorStr)
{
	var errorSplit = unescape('%u3002');
	alert(_errorStr.replace(new RegExp(errorSplit,'g'),errorSplit+"\n"));
	isStop = true;
};
// Hook for Internet Explorer.
if (navigator.appName && isInternetExplorer && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1)
{
  document.write('<SCRIPT LANGUAGE="JScript" FOR="Player" EVENT="PlayStateChange(NewState)">\
      try{  onPlayStateChange(Player, NewState); }catch(e){}\
    </SCRIPT>\
    <SCRIPT LANGUAGE="JScript" FOR="Player" EVENT="Error()">\
      try{\
      var max = Player.error.errorCount;\
      var err = Player.error.item(max-1);\
      onMediaError(err.errorDescription);\
      }catch(e){}\
    </SCRIPT>');
  document.write('<script language=\"VBScript\"\>\n');
  document.write('On Error Resume Next\n');
  document.write('Sub player_small_FSCommand(ByVal command, ByVal args)\n');
  document.write('	Call player_small_DoFSCommand(command, args)\n');
  document.write('End Sub\n');
  document.write('</script\>');
}
function writeFlash(path)
{
  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="player_small" width="130" height="34" align="middle">\
      <param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" />\
      <param name="movie" value="'+path+'/player_small.swf" /><param name="quality" value="high" /><embed src="'+path+'/player_small.swf" quality="high"wmode="transparent" width="130" height="34" swLiveConnect=true id="player_small" name="player_small" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
    </object>');
}          
function mediaplay()
{
	var flashobj = getPlaterFlash();
	if( flashobj )
	{
		flashobj.setVariable('showplay','false');
	}
	var obj_ie = document.getElementById('player_ie');
	if( obj_ie )
	{
		var playbtn = document.getElementById('playbtn');
		if( playbtn )
		{
			obj_ie.style.display = '';
			playbtn.style.display = 'none';
			Player.controls.play();
		}
	}
}
function hideMedia()
{
	var flashobj = getPlaterFlash();
	if( flashobj )
	{
		flashobj.setVariable('showplay','true');
	}
	var obj_ie = document.getElementById('player_ie');
	if( obj_ie )
	{
		var playbtn = document.getElementById('playbtn');
		if( playbtn )
		{
			obj_ie.style.display = 'none';
			playbtn.style.display = '';
		}
	}
}
function setMedia(thefileurl,title)
{
	var obj = document.getElementById('playerarea');
	if( obj )
	{
		var isieset = false;
		if( isInternetExplorer )
		{
			var obj_ie = document.getElementById('player_ie');
			if(obj_ie)
			{
				obj_ie.innerHTML = "<object id='Player' width='257' height='133' classid='CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=9,0,0,0' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>\
					<param name='url' value='"+thefileurl+"'><param name='enableContextMenu' value='false'>\
					<param name='volume' value='50' />\
					<param name='autoStart' value='0'>\
					<param name='uiMode' value='none'>\
					<param name='windowlessVideo' value='true'>\
				</object>";
				isieset = true;
				hideMedia();
			}
		}
		if( isieset == false )
		{
			obj.innerHTML = "<embed id='Player' type='application/x-mplayer2' width='257' height='158' src='"+thefileurl+"' showPositionControls='0' enableContextMenu='0' autoStart='0' windowlessVideo='0' pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/'></embed>\
			  <div style='width:250px' align='right' class='t12black'>"+title+"</div>";
		}
		obj.style.display = '';
	}
}
