// initialize global variables
var detectableWithVB = false;
var QuicktimePluginFound = false;
var quickTime = false;

function candetectPluginQuicktimes() {
	if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
	} else {
	return false;
	}
}

function detectQuickTime() {
	QuicktimePluginFound = detectPluginQuicktime('QuickTime');
	// if not found, try to detect with VisualBasic
	if(!QuicktimePluginFound && detectableWithVB) {
		QuicktimePluginFound = detectQuickTimeActiveXControl();
	}
	// QUICKTIME VERSION CHECKING
	quickTime = new Object();
	quickTime.installed=false;
	quickTime.version='0.0';
	
	// Quicktime Detection  v1.0
	// documentation: http://www.dithered.com/javascript/quicktime_detect/index.html
	// license: http://creativecommons.org/licenses/by/1.0/
	// code by Chris Nott (chris[at]dithered[dot]com)
	// Modified by William Jamieson
	agent = navigator.userAgent.toLowerCase(); 
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Quicktime plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
	  for (i=0; i < navigator.plugins.length; i++ ) {
		 plugin = navigator.plugins[i];
		 if (plugin.name.indexOf("QuickTime") > -1) {
			quickTime.version = parseFloat(plugin.name.substring(18));
			quickTime.installed = true;
		 }
	  }
	} else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
		quickTimeVersion = '0.0';
		quickTimeInstalled = false;
/*		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obQuicktime \n');
		document.write('set obQuicktime = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1") \n');
		document.write('if IsObject(obQuicktime) then \n');
		document.write('   if obQuicktime.IsQuickTimeAvailable(0) then \n');
		document.write('      quickTimeVersion = CInt(Hex(obQuicktime.QuickTimeVersion) / 1000000) \n');
		document.write('      quickTimeInstalled = True \n');
		document.write('   end if \n');
		document.write('end if \n');
		document.write('</scr' + 'ipt\> \n');//*/

		//Create a 'script' element	
		var scrptE = document.createElement("script");
		// Set it's 'language' attribute
		scrptE.setAttribute("language", "VBScript");
		// Set it's 'src' attribute
		scrptE.setAttribute("src", "/js/createActiveXControl.js");
		// Now add this new element to the head tag
		document.getElementsByTagName("head")[0].appendChild(scrptE);

		quickTime.version = quickTimeVersion;
		quickTime.installed = quickTimeInstalled;
	} else {
		// Can't detect in all other cases
	}
	quickTime.intVersion=parseInt(quickTime.version);
	return QuicktimePluginFound;
}

function detectPluginQuicktime() {
	// allow for multiple checks in a single pass
	var daPlugins = detectPluginQuicktime.arguments;
	// consider QuicktimePluginFound to be false until proven true
	var QuicktimePluginFound = false;
	// if plugins array is there and not fake
	if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
		// loop through all desired names and check each against the current plugin name
		var numFound = 0;
		for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
			(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
			// this name was found
			numFound++;
		}   
		}
		// now that we have checked all the required names against this one plugin,
		// if the number we found matches the total number provided then we were successful
		if(numFound == daPlugins.length) {
		QuicktimePluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
		}
	}
	}
	return QuicktimePluginFound;
} // detectPluginQuicktime


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
	document.writeln('<script language="VBscript">');

	document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
	document.writeln('detectableWithVB = False');
	document.writeln('If ScriptEngineMajorVersion >= 2 then');
	document.writeln('  detectableWithVB = True');
	document.writeln('End If');

	document.writeln('\'this next function will detect QuickTime');
	document.writeln('Function detectQuickTimeActiveXControl()');
	document.writeln('  on error resume next');
	document.writeln('  detectQuickTimeActiveXControl = False');
	document.writeln('  If detectableWithVB Then');
	document.writeln('    detectQuickTimeActiveXControl = False');
	document.writeln('    hasQuickTimeChecker = false');
	document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
	document.writeln('    If IsObject(hasQuickTimeChecker) Then');
	document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
	document.writeln('        detectQuickTimeActiveXControl = True');
	document.writeln('      End If');
	document.writeln('    End If');
	document.writeln('  End If');
	document.writeln('End Function');

	document.writeln('</scr' + 'ipt>');
}