/**
 *  mo-quicktime.js
 *
 *  This file is used by MasterObjects-enhanced web pages and scripts.
 *  (c) 2008 MasterObjects, Inc. (http://www.masterobjects.com) 
 *
 */

var gMoQuickTimeBuild = 2;  // February 1, 2008
var gMoQuickTimeDisabled = false;

function MoQuickTime() {

	// private functions

	function checkAttribute(theConfig,theName,theAttribute) {
		if (typeof theConfig[theAttribute] == "undefined") {
			MO.message.oneTimeWarning("qt" + theAttribute,
				'There is a problem with a movie on this page.\n\nMissing parameter in ' +
				theName + ': ' + theAttribute,
				gMoQuickTimeDisabled);
			return false;
		}
		return true;
	}

	// public functions

	this.insertMovie = function (theConfig) {
		document.write(this.createMovie(theConfig));
		return theConfig;
	}
	
	this.createMovie = function (theConfig) {
		if (this.checkMovie(theConfig) == false) {
			return('<span class="moWarning">Cannot create QuickTime movie without an id.</span>');
		}
		
		if (gMoQuickTimeDisabled == true) {
			var theXHTML = 
				'<table id="' + theConfig.id + 
					'" style="width:' + theConfig.width + 'px;height:' + theConfig.height + 
					'px"><tr height="' + theConfig.height + '"><td class="moWarning" width="' +
					theConfig.width + '" align="center" valign="middle">' + 
					'This QuickTime movie was disabled.</td></tr>' + 
				'</table>';
		} else {
			var theXHTML =
				'<object id="' + theConfig.id + 
						'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' +
						theConfig.width + '" height="' + theConfig.height +
						'" codebase="http://www.apple.com/qtactivex/qtplugin.cab">\n' +
					'<param name="SRC" value="' + theConfig.src + '" \/>\n' +
					'<param name="AUTOPLAY" value="' + theConfig.autoplay + '" \/>\n' +
					'<param name="CONTROLLER" value="' + theConfig.controller + '" \/>\n' +
					'<embed src="' + theConfig.src + 
						'" width="' + theConfig.width + 
						'" height="' + theConfig.height +
						'" autoplay="' + theConfig.autoplay +
						'" controller="' + theConfig.controller + 
						'" pluginspage="http://www.apple.com/quicktime/download/">\n' +
					'</embed>\n' +
				'</object>';
		}
		return theXHTML;
	}
		
	this.checkMovie = function (theConfig) {
		if (!checkAttribute(theConfig,'movie','id')) {gMoQuickTimeDisabled = true;return false;}
		if (!checkAttribute(theConfig,theConfig.id,'width')) {gMoQuickTimeDisabled = true;}
		if (!checkAttribute(theConfig,theConfig.id,'height')) {gMoQuickTimeDisabled = true;}
		if (!checkAttribute(theConfig,theConfig.id,'src')) {gMoQuickTimeDisabled = true;}
		if (typeof theConfig.autoplay == "undefined") {
			theConfig.autoplay = "false";
		}
		if (typeof theConfig.controller == "undefined") {
			theConfig.controller = "true";
		}
		return true;
	}
}

if (typeof MO.message.oneTimeWarning == "undefined") {
	alert('Movies on this page may not function properly.\n\nIn order to play QuickTime movies in this page, please include script mo-common.js before script mo-quicktime.js');
	var mosQuickTime = null;
} else {
	var mosQuickTime = new MoQuickTime();
}							
