function bindMediaPlayerEvent(eventname,bindeventname)
{
	if( bindeventname == null )
		bindeventname = eventname;
	if( jQuery.browser.mozilla )
	{
		eventname = "OnDS"+eventname+"Evt";
		var tag = '%3Cscript%3Efunction '+eventname+'(){'+bindeventname+'.apply(this,arguments);}%3C/script%3E';
		document.write(unescape(tag));
	}
	else if( jQuery.browser.msie )
	{
		var tag = '%3Cscript for="Player" language="jscript" event="'+eventname+'()"%3E'+bindeventname+'.apply(this,arguments);%3C/script%3E';
		document.write(unescape(tag));
	}
}
function changeMediaPlayerURL(URL)
{
	if( jmedia )
	{
		try
		{
			if( jQuery.browser.msie )
				Player.URL = URL;
			else
				document.getElementById("Player").setAttribute("src",URL);
		}catch(e)
		{
		}
	}
}
function MediaPlayerPlay()
{
	if( jmedia )
	{
		try
		{
			if( jQuery.browser.msie )
				Player.controls.play();
			else
				document.getElementById("Player").setAttribute("autoStart","1");
		}catch(e)
		{
		}
	}
}
function MediaPlayerStop()
{
	if( jmedia )
	{
		try
		{
			if( jQuery.browser.msie )
				Player.controls.stop();
			else
				document.getElementById("Player").setAttribute("autoStart","0");
		}catch(e)
		{
		}
	}
}
function MediaPlayerPause()
{
	if( jmedia )
	{
		try
		{
			Player.controls.pause();
		}catch(e)
		{
		}
	}
}
var printerror = false;
function ErrorEvent()
{
	var max = Player.error.errorCount;
	if( max > 0 )
	{
		printerror = true;
		var err = Player.error.item(max-1);
		var errDesc = err.errorDescription;
		Player.error.clearErrorQueue();
		var errorSplit = unescape('%u3002');
		MediaPlayerStop();
		alert(errDesc.replace(new RegExp(errorSplit,'g'),errorSplit+"\n"));
		
	}
}
var jmedia = null;
function makeMediaPlayer(objid,URL,options)
{
	var windowlessVideo = false;
	var BufferingTime = 3;
	var stretchToFit = true;
	var enableContextMenu = false;
	var autostart = true;
	var uiMode = "none";
	var _width = null;
	var _height = null;
	var volume = 50;
	
	if( options )
	{
		if( options.windowlessVideo != null )
			windowlessVideo = options.windowlessVideo;
		if( options.volume != null )
			volume = options.volume;
		if( options.BufferingTime != null )
			BufferingTime = options.BufferingTime;
		if( options.stretchToFit != null )
			stretchToFit = options.stretchToFit;
		if( options.enableContextMenu != null )
			enableContextMenu = options.enableContextMenu;
		if( options.autostart != null )
			autostart = options.autostart;
		if( options.uiMode != null )
			uiMode = options.uiMode;
		if( options.width != null )
			_width = options.width;
		if( options.height != null )
			_height = options.height;
	}
	
	jmedia = jQuery("#"+objid);
	if( jmedia.length == 1 )
	{
		if( _width == null )
			_width = ( jmedia.width() > 0 )?jmedia.width():(parseInt(jmedia[0].style.width)>0?parseInt(jmedia[0].style.width):320);
		if( _height == null )
			_height = ( jmedia.height() > 0 )?jmedia.height():(parseInt(jmedia[0].style.height)>0?parseInt(jmedia[0].style.height):240);
		if(jQuery.browser.msie )// || jQuery.browser.mozilla
		{
			bindMediaPlayerEvent("Error","ErrorEvent");
			var tag = '<OBJECT id="Player" ';
			//if( jQuery.browser.mozilla )
			//	tag += 'type="application/x-ms-wmp" ';
			//else
				tag += ' classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=9,0,0,0" ';
			tag += 'width="'+_width+'" height="'+_height+'"><param name="windowlessVideo" value="'+ windowlessVideo +'"/><param name="volume" value="'+ volume +'"/>\
<param name="BufferingTime" value="'+ BufferingTime +'"/><param name="stretchToFit" value="'+ stretchToFit +'"/><param name="enableContextMenu" value="'+ enableContextMenu +'"/>\
<param name="autoStart" value="'+ autostart +'"/><param name="uiMode" value="'+ uiMode +'"/><param name="url" value="'+ URL +'"/></OBJECT>';
			jmedia[0].innerHTML = tag;
		}
		else
		{
			_height += 38;
			var tag = '<embed id="Player"';
			tag += 'type="application/x-mplayer2" width="'+_width+'" height="'+_height+'" windowlessVideo="'+ windowlessVideo +'"\
 showStatusBar="1" showPositionControls="0" AutoSize="1" volume="'+ volume +'"\
 BufferingTime="'+ BufferingTime +'" stretchToFit="'+ stretchToFit +'" enableContextMenu="'+ enableContextMenu +'"\
 autoStart="'+ autostart +'" src="'+ URL +'" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" ></embed>';
			jmedia[0].innerHTML = tag;
			SetMedia();
			//jmedia.html('Player目前尚未支援此瀏覽器');
			//jmedia = null;
		}
	}
	else
	{
		jmedia = null;
	}
}
function getCookieOnly(name)
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 )
	{
		var end = document.cookie.indexOf( "=", len );
		if ( end == -1 )
		{
			end = document.cookie.length;
		}
	}
	return unescape( document.cookie.substring( len, end ) );
}
function statusword(status)
{
	switch(status)
	{
		case 0:
			return "Undefined";//Windows Media Player is in an undefined state.
		case 1:
			return "Stopped";//Playback of the current media item is stopped. 
		case 2:
			return "Paused";//Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location. 
		case 3:
			return "Playing";//The current media item is playing. 
		case 4:
			return "ScanForward";//The current media item is fast forwarding. 
		case 5:
			return "ScanReverse";//The current media item is fast rewinding. 
		case 6:
			return "Buffering";//The current media item is getting additional data from the server. 
		case 7:
			return "Waiting";//Connection is established, but the server is not sending data. Waiting for session to begin. 
		case 8:
			return "MediaEnded";//Media item has completed playback.  
		case 9:
			return "Transitioning";//Preparing new media item. 
		case 10:
			return "Ready";//Ready to begin playing. 
		case 11:
			return "Reconnecting";//Reconnecting to stream.
	}
	return status;
}