// ========================================
// Digital Teacher v4.1, Web Component
// Copyright(C) 2001-2002 Francis Software
// Sunnyvale, California
// All rights reserved, April 20, 2002
// Distributed under the license agreement
// ========================================

// --------------------------------------------------------------------------------
// Purpose: To create a new window, and display/play html/multimedia.
// Note: The new window object variable, objNewWin, is global. This is to prevent
//	   the student from attempting to open the second instance of the currently
//	   open object (for the same or another file). If the variable contains
//	   object (that is, a sub window is currently open), we don't allow the
//	   student to open another sub window.
// --------------------------------------------------------------------------------

var objNewWin = null;

function playMedia(fileType, sourceFile, w, h, alt) {

	if ((objNewWin != null) && (!objNewWin.closed)) {
		// The new window is current open. Do nothing.
		alert('The sub window is currently open.\n\nPlease close it first before you attempt\nto open another sub window.');
	}

	else {
		var winW = screen.width*0.5;
		var winH = screen.height*0.5;

		if (fileType=='f') {		// external html file
			if ((w>0)&&(h>0)) {
				objNewWin = window.open(''+ sourceFile +'','mediaWin', 'width='+w*1.1+',height='+h*1.1+',resizable=yes,scrollbars=yes');
			}
			else {
				objNewWin = window.open(''+ sourceFile +'','mediaWin', 'width='+winW+',height='+winH+',resizable=yes,scrollbars=yes');
			}
		}

		else {
			var str = '<HTML><HEAD><TITLE>Multimedia</TITLE></HEAD>';
			str += '<BODY bgcolor="black" onBlur="self.focus()">';

			if (fileType=='i') {	// image
				if ((w>0)&&(h>0)) {
					str += '<IMG SRC="'+ sourceFile + '" WIDTH='+w+' HEIGHT='+h+' ALT="'+alt+'" >';
					objNewWin = window.open('','mediaWin', 'width='+w*1.1+',height='+h*1.1+',resizable=yes');
				}
				else {
					str += '<IMG SRC="'+ sourceFile + '" ALT="'+alt+'" >';
					objNewWin = window.open('','mediaWin', 'width='+winW+',height='+winH+',resizable=yes');
				}
			}	

			else if (fileType=='a') {	// audio

				// You should create the stopAudio.gif image (next line), and store the
				// file in the folder of your choice. Also, change the path accordingly.

				str += '<A HREF =' + '"" onClick="self.close()"; return false;"><img src="stopAudio.gif" width=42 height=32 border=0 alt="Stop Audio"></A>'
				str += '<EMBED SRC="'+ sourceFile + '" AUTOSTART=true HIDDEN=true MASTERSOUND></EMBED>';
				objNewWin = window.open('','mediaWin', 'width=1,height=1');
			}

			else if (fileType=='v') {	// video

				if ((w>0)&&(h>0)) {
					str += '<EMBED SRC="'+ sourceFile + '" AUTOSTART=true  WIDTH='+w+' HEIGHT='+h+'></EMBED>';
					objNewWin = window.open('','mediaWin', 'width='+w*1.1+',height='+h*1.1+',resizable=yes');
				}
				else {
					str += '<EMBED SRC="'+ sourceFile + '" AUTOSTART=true></EMBED>';
					objNewWin = window.open('','mediaWin', 'width='+winW+',height='+winH+',resizable=yes');
				}
			}
			objNewWin.document.open();
			objNewWin.document.write(str);
			objNewWin.document.close();
		}
	}
}
