/********************************************************************************************************************************************************************************************
                                                                      WINDOWS-MEDIA.JS

Copyright © 2007 Illusionator, Inc.

Functions that support the playing of media files.

********************************************************************************************************************************************************************************************/


// IlsInlineMedia(sPath, nWidth, nHeight, bShowControls, bAutoStart, nRepeat)
//		sPath:			Path, relative to the page that invokes this function, of the media file to be played.  Supports .wmv, .wma, and other file types.
//		nWidth:			Width, in pixels of the media to be played.
//		nHeight:		Height, in pixels, of the media to be played (not counting the controls bar displayed by Windows Media Player)
//		bShowControls:	true iff the controls bar should be displayed beneath the media.  If this value is false, "bAutoStart" should be true; otherwise, there will be no way to play
//						the media.
//		bAutoStart:		true iff the media should start immediately playing.  Take care if this value is false, because Netscape 8.1 (and perhaps other versions of Netscape?) appears to
//						have a bug where when this value is false, the video displays as blank.  IE 7.0, Firefox 2.0.0.3, and Opera 9.2 do not have this bug.
//		nRepeat:		If a positive integer, this is the number of times the media will repeat.  If -1, the media will repeat "forever."  Do not use zero, as its behavior is
//						not documented.
//	returns:	Nothing
//
// Displays a media file (video, music, etc.) using Windows Media Player at the place in the HTML file where this function is invoked.

function IlsInlineMedia(sPath, nWidth, nHeight, bShowControls, bAutoStart, nRepeat)
{
	// The height, in pixels, of the controls bar that the embedded Windows Media Player puts beneath the media.  Netscape, Firefox, and Opera all need this value.  In IE, a value of 40
	// works fine, but 45 makes no difference in the display with IE, so we use 45 for all 4 browsers.  Discovered by trial and error.
	var nControlsHeight = 45;

	document.write(
		// Netscape 8.1, Firefox 2.0.0.3, and Opera 9.2 all recognize the <embed> tag here, but not the <object> tag.  IE 7.0 recognizes either tag, so one might think we could just use
		// the <embed> tag here, with no <object> tag.  But countless places on the Internet, including Microsoft's own web site, say to use the <object> tag (for IE) together with the
		// <embed> tag (for Netscape, Firefox, and Opera), and they also say that future standards will recognize only the <object> tag and not the <embed> tag, so we generate both tags
		// here, as instructed.  Note that with this particular "classid", we are actually asking Windows Media Player to simulate version 6.4 of the player, rather than a later version,
		// so that this page will run even with an old version of Windows Media Player.
		'<object width="', nWidth, '" height="', bShowControls ? (nHeight + nControlsHeight) : nHeight, '" ',
		'classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/ mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ',
		'standby="Loading Microsoft Windows® Media Player components..." TYPE="application/x-oleobject">',
		'<param name="fileName" value="', sPath, '">',
		'<param name="showControls" value="', bShowControls, '">',
		'<param name="autoStart" value="', bAutoStart, '">',
		'<param name="playCount" value="', (nRepeat == -1) ? '9999' : nRepeat, '">',
		'<param name="animationatStart" value="true">',
		'<param name="transparentatStart" value="true">',
		'<embed width="', nWidth, '" ', 'height="', bShowControls ? (nHeight + nControlsHeight) : nHeight, '" ', 'src="', sPath, '" ',

		// Netscape, Firefox, and Opera don't recognize "false" for "autoStart", but they do recognize "0"
		'autoStart="', (bAutoStart ? '1' : '0'), '" ',
		'showControls="', bShowControls, '" ',

		// In my experiments, using "0" for "playCount" makes it repeat forever, but this is not documented behavior, and might not be true in all versions of Windows Media Player.
		// Thus, we just use the very large number of 9999 instead, to make it repeat "forever"
		'playCount="', (nRepeat == -1) ? '9999' : nRepeat, '" ',

		'type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/ en/download/">',
		'</object>');
} // IlsInlineMedia
