//<!--
// Multimedia Listings Helper Javascripts
// --------------------------------------
// Copyright 2005 Sherman J. Silber.  The Infertility Center of Saint Louis.  http://www.infertile.com


// PRINTING MOVIE CHOICES //
/* NOTE, the valid options for messageToPrint:
				 'unlisted' -- Our error.  It means that a valid listing for the movie's path could not be found.
		 '' or 'no_comment' -- The user has the latest necessary QuickTime software.
		 'upgrade_optional' -- The user could view higher quality video with later version QT, but doesn't need to.
		'upgrade_mandatory' -- The user's QT version is too low, must install a newer version.
			'get_quicktime' -- The user has too low a version of QT or no QT at all, and must install it. */
function printVideoChoices(messageToPrint, slowConxnPath, fastConxnPath)
{
	movieDIVNumber++;
	var movieLoadingExpression_slow = 'loadMovieFile(' + movieDIVNumber + ',\'' + slowConxnPath + '\', 320, 256)'; 
	var movieLoadingExpression_fast = 'loadMovieFile(' + movieDIVNumber + ',\'' + fastConxnPath + '\', 320, 256)'; 
	var slowConxnLabel = 'dial-up or<br>slow-speed broadband';
	var fastConxnLabel = 'high-speed broadband';
	var onlyOneKnownPath = false;

	
	if (slowConxnPath && fastConxnPath) {
		var slowConxnHTML = '<a href="#" onClick="eval(' + movieLoadingExpression_slow + ')">' + slowConxnLabel + '</a><br>';
		var fastConxnHTML = '<a href="#" onClick="eval(' + movieLoadingExpression_fast + ')">' + fastConxnLabel + '</a><br>';
	} else if (slowConxnPath) {
		var slowConxnHTML = '<a href="#" onClick="eval(' + movieLoadingExpression_slow + ')">play video</a><br>';
		onlyOneKnownPath = true;
	} else if (fastConxnPath) {
		var fastConxnHTML = '<a href="#" onClick="eval(' + movieLoadingExpression_fast + ')">>play video</a><br>';
		onlyOneKnownPath = true;
	}
	
	openMovieDIV(movieDIVNumber);
	printPlayerHeader(320, 252, 'MOVIE PLAYER');
	
	switch (messageToPrint) {
		case 'unlisted':
			printMovieNotFound();
			break;
			
		case 'get_quicktime':
		case 'upgrade_mandatory':
			document.write('<br><span class="modif12pix">This video requires ');
			printWhereToGetQuicktime(messageToPrint);
			document.write('<span class="modif12pix">If you would like to try viewing the video anyway, you can use ');
	/*		var spacer = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&bull;&nbsp;';*/
			if (onlyOneKnownPath) {
				document.write('this link:<br>');
				document.write('<ul style:"margin:0 10px 10px 10px"><li>' + '<a href="');
				(slowConxnPath) ? document.write(slowConxnPath) : document.write(fastConxnPath);
				document.write('">video file</a><br>');
			} else if (slowConxnPath && fastConxnPath) {
				document.write('these links:<br>');
				document.write('<ul style:"margin:0 10px 10px 10px"><li>' + '<a href="' + slowConxnPath + '">' + slowConxnLabel + '</a></li>');
				document.write('<li>' + '<a href="' + fastConxnPath + '">' + fastConxnLabel + '</a></li></ul>');
			}
			break;
		
		default:
		case 'no_comment':
		case 'upgrade_optional':
			document.write('<span class="modif12pix"><br><br>');
/*			var spacer = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&bull;&nbsp;';*/
			if (onlyOneKnownPath) {
				document.write('&nbsp;&nbsp;Click to watch:</span><br><br>');
				document.write('<p>&nbsp;</p>');
				(slowConxnHTML) ? document.write(slowConxnHTML) : document.write(fastConxnHTML);
			} else if (slowConxnHTML && fastConxnHTML) {
				document.write('Choose your download speed:</span><br><br>');
				document.write('<ul style:"margin:0 10px 10px 10px"><li>' + slowConxnHTML + '</li>');
				document.write('<p>&nbsp;</p>');
				document.write('<li>' + fastConxnHTML + '</li></ul>');
			}
			if (messageToPrint == 'upgrade_optional') {
				document.write('<br><br><br><br><br>');
				document.write('<center><span style="font-size:11px">');
				document.write('(get the latest <a href="http://www.apple.com/quicktime">QuickTime</a> for higher quality video)</span>');
				document.write('</center>');
			}
			break;	
	}
	
	printPlayerFooter();
	closeMovieDIV();
}

function printAudioChoices(messageToPrint, audioPath) {
	movieDIVNumber++;
	var movieLoadingExpression = 'loadMovieFile(' + movieDIVNumber + ',\'' + audioPath + '\', 320, 30)'; 
											 
	openMovieDIV(movieDIVNumber);
	printPlayerHeader(320, 30, 'AUDIO PLAYER');
	
	switch (messageToPrint) {
		case 'unlisted':
			printMovieNotFound();
			break;
		
		case 'get_quicktime':
		case 'upgrade_mandatory':
			document.write('<br><span class="modif12pix">This audio file requires ');
			printWhereToGetQuicktime(messageToPrint);
			document.write('<span class="modif12pix">If you would like to try listening to the audio anyway, you can use this link:&nbsp;&nbsp;');
			document.write('<a href="' + audioPath + '">audio file</a></span>');
			break;
		
		default:
		case 'no_comment':
		case 'upgrade_optional':
			document.write('<span class="modif12pix"><br>&nbsp;&nbsp;Click to listen:&nbsp;&nbsp;');
			document.write('<a href="#" onClick="eval(' + movieLoadingExpression + ')">play audio</a></span>');
			break;
	}
	document.write('<br><br>');
	
	printPlayerFooter();
	closeMovieDIV();
}

// OTHER STUFF //
function openMovieDIV(number) {
	document.write('<div id="movieFrame' + number + '">');
}
function closeMovieDIV() {
	document.write('</div>');
}

// Creates a table with an open cell, therefore this cell and table must later be closed by printPlayerFooter().
function printPlayerHeader(theWidth, theHeight, theTitle) {
	document.write('<table width="' + theWidth + '" border="1" cellpadding="0" cellspacing="0" bordercolor="#000066" bgcolor="#CCCCCC"><tr><td>');
	document.write('<table border="0" cellpadding="0" cellspacing="0">'); // Yes, it's a second table nested inside.
	document.write('<tr><td width="7"></td>');
	document.write('<td width="' + (theWidth - 12) + '" height="' + theHeight + '" valign="top" class="movieEmbedConxn">');
	document.write('<span style="font-weight:bold;color:#000066;font-style:italic;">&nbsp;&nbsp;&nbsp;' + theTitle + '</span><hr>');
}
function printPlayerFooter() {
	document.write('</td><td width="5"></td></tr></table>');
	document.write('</td></tr></table>');
}

function loadMovieFile(theDIVNumber, theMoviePath, theWidth, theHeight) {
	var DIVToSwitch     = 'movieFrame' + theDIVNumber;
	var embedExpression = '<embed src="' + theMoviePath + '" width="' + theWidth + '" height="' + theHeight + '" autoplay="TRUE" controller="TRUE"></embed>';
	document.getElementById(DIVToSwitch).innerHTML = embedExpression;
}

function printMovieNotFound() {
	document.write('<br>Apologies, but the requested multimedia file could not be found.<br><br>');
	document.write('<span class="modif12pix">This error may be reported to the webmaster by clicking "about this site" at the bottom of the page.</span>');
}

function printWhereToGetQuicktime(theComment) {
	if (theComment == 'upgrade_mandatory') document.write('a later version of ');
	document.write('QuickTime, which is available (free) at:<br><br></span>');
	document.write('<center><a href="http://www.apple.com/quicktime">www.apple.com/quicktime</a></center><br>');
	document.write('<br><br>');
}

function getFastPath(slowPath) {
	return ((slowPath.substr(slowPath.length - 12) == '28k-only.mov') ? '' : slowPath.replace('28k','256'));
}