/* 
 *
 *  Swallow (c) Binham Communcations Corporation, Inc. 2001
 *
 *  20010324	implemented Win WMP detection on IE (ah)
 *	20010323	implemented Mac QT detection on Nav/IE (ah)			
 *  20010322 	created (ah)
 *
 */


// initialize global variables
var mac=false; var win=false; var lux=false;
var nav=false; var exp=false; var opr=false; var bvr=0;
var qtp=false; var wmp=false; var rmp=false;
var qtpver=0; var wmpver=0; var rmpver= -1;
var detectableWithVB = false;
var pluginFound = false;

/* 
 *
 *	Plugin Determination
 *
 */

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

function detectQuickTime() {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectQuickTimeActiveXControl();
    }
    if (pluginFound) return true;
} // detectQuickTime

function detectReal() {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
                       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
                       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }   
    if (pluginFound) return true;
} //detectReal

function detectWindowsMedia() {
    pluginFound = detectPlugin('Windows Media Player');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    if (pluginFound) return true;
} // detectWindowsMedia

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = 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) {
                pluginFound = true;
                // if we've found the plugin, we can stop looking through at the rest of the plugins
                break;
            }
        }
    }
    return pluginFound;
} // detectPlugin


// 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 most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles 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(1) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('        qtpver = hasQuickTimeChecker.QuickTimeVersion');
    //document.writeln('        MsgBox qtpver');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

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


/* 
 *
 *	File Chooser Function
 *
 */
	function choose_files() {

		var bob = "none";

		if (allow_wmp && wmp) {
			if (wmpver >= 7) {
				video = WMV_VIDEO;
				file = WMV_PAGE;
			} else {
				if (wmpver >= 6) {
					video = MPG_VIDEO;
					file = MPG_PAGE;
				} else {
					video = AVI_VIDEO;
					file = AVI_PAGE;
				}
			}
			play = true;
			bob = "Windows Media Player";
		}
		if (allow_qtp && (qtp && (qtpver > 2))) {
			// choose video file
			if ("3" == qtpver) {
				video = QT3_VIDEO;
				file = QT3_PAGE;
			}
			else {
				video = QT4_VIDEO;
				file = QT4_PAGE;
			}
			play = true;
			bob = "QuickTime Player";
		}
		return bob;
	} // choose_files

/* 
 *
 *	Preload Function
 *
 */

	function preload (lvideo) {
		if (exp && wmp) {
			if (wmpver < 7) {
			  	document.write("<OBJECT ID=MediaPlayer width=5 height=5 ")
	          	document.write(" CLASSID=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 ")
	          	//document.write(" CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715")
	          	//document.write(" standby='Loading Microsoft Windows Media Player components...' ")
	          	document.write(" TYPE='application/x-oleobject'> ")
	          	document.write("  <PARAM NAME='FileName' VALUE='"+lvideo+"'> ")
	          	document.write("  <PARAM NAME='AutoStart' VALUE='false'> ")
	          	document.write("  <PARAM NAME='ShowControls' VALUE='false'> ")
	          	document.write("  <PARAM NAME='ShowDisplay' VALUE='false'> ")
	          	document.write("  <PARAM NAME='AnimationatStart' VALUE='false'> ")
	          	document.write("  <PARAM NAME='TransparentatStart' VALUE='true'> ")
	         	document.write("</OBJECT>")
	    	} else {
			  	document.write("<OBJECT ID=MediaPlayer width=5 height=5 ")
	          	document.write(" CLASSID=CLSID:6bf52a52-394a-11d3-b153-00c04f79faa6 ")
	          	//document.write(" CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715")
	          	//document.write(" standby='Loading Microsoft Windows Media Player components...' ")
	          	document.write(" TYPE='application/x-oleobject'> ")
	          	document.write("  <PARAM NAME='FileName' VALUE='"+lvideo+"'> ")
	          	document.write("  <PARAM NAME='AutoStart' VALUE='false'> ")
	          	document.write("  <PARAM NAME='ShowControls' VALUE='false'> ")
	          	document.write("  <PARAM NAME='ShowDisplay' VALUE='false'> ")
	          	document.write("  <PARAM NAME='AnimationatStart' VALUE='false'> ")
	          	document.write("  <PARAM NAME='TransparentatStart' VALUE='true'> ")
	         	document.write("</OBJECT>")	    		
	    	}
		}
		else {
			if (exp && qtp) {
				document.write('<EMBED SRC='+lvideo+' type="video/quicktime" CACHE="true" VOLUME="0" hidden></embed>');
								//document.write('<OBJECT DATA='+video+' VOLUME=0 SOUND=0 AUTOPLAY=false cache=true hidden></OBJECT">');
			}
		}
		
		if (nav && wmp) {
			if (wmpver < 6) {
				document.write("<EMBED TYPE='application/x-mplayer2' "); 
	       		// document.write("PLUGINSPAGE='http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&'");
				document.write("SRC='"+lvideo+"' ");
	       		document.write("NAME='MediaPlayer' ");
	       		document.write("ID='MediaPlayer' ");
	       		document.write("WIDTH=0 ");
	       		document.write("HEIGHT=0 ");
	       		document.write("ShowControls=0 ");
	       		document.write("ShowDisplay=0 ");
	       		document.write("ShowStatusBar=0 ");
	       		document.write("AutoStart=0 ");
	       		document.write("TransparentatStart=1> ");
	       		document.write("</EMBED>");
	       	} else {
		       	document.write("<EMBED TYPE='video/x-ms-wmv' "); 
	       		// document.write("PLUGINSPAGE='http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&'");
				document.write("SRC='"+lvideo+"' ");
	       		document.write("NAME='MediaPlayer' ");
	       		document.write("ID='MediaPlayer' ");
	       		document.write("WIDTH=0 ");
	       		document.write("HEIGHT=0 ");
	       		document.write("ShowControls=0 ");
	       		document.write("ShowDisplay=0 ");
	       		document.write("ShowStatusBar=0 ");
	       		document.write("AutoStart=0 ");
	       		document.write("TransparentatStart=1> ");
	       		document.write("</EMBED>");
	       	}
		}
		
		else {
			if (nav && qtp) {
				document.write("<embed src='"+lvideo+"' type='video/quicktime' volume='0' name='zygote' hidden></embed>");
			}
		}		
	}

/* 
 *
 *	Spawn Function
 *
 */
	
	function flugelhorn() {
		//if (qtp) {
			vw = window.open(file,"video_window","height="+SPAWN_HEIGHT+",width="+SPAWN_WIDTH+",top=0,left=0")
		//} else if (wmp) {
		//	if (activex) {
				
		//	} else {
			
		//	}
		//}
	}





/*
 *
 *	Main
 *
 */


/* 
 *
 *	Platform & Browser Determination
 *
 */


// Determine platform
	mac = (navigator.platform.indexOf("Mac") >= 0);
	win = (navigator.platform.indexOf("Win") >= 0);
	lux = (navigator.platform.indexOf("Linux") >=0);

// Determine browser
	nav = (navigator.appName.indexOf("Netscape") >= 0);
	exp = (navigator.appName.indexOf("Microsoft") >= 0);
	opr = (navigator.appName.indexOf("Opera") >= 0);


// Determine Browser version
	if (exp) {
		start = navigator.appVersion.indexOf("MSIE") + 5;
		bvr = parseInt(navigator.appVersion.substr(start,1))
	} else {
		if (nav) {
			bvr = parseInt(navigator.appVersion)
		}
	}


if (canDetectPlugins()) {
	qtp = detectQuickTime();
	wmp = detectWindowsMedia();
	rmp = detectReal();
}

// If QuickTime is present determine version
if (qtp && (nav || mac)) {
	for (i=0;i<navigator.plugins.length;i++) {
	  if (navigator.plugins[i].name.indexOf("QuickTime ") >= 0) {
	  	dot = navigator.plugins[i].name.indexOf(".");
	  	qtpver = parseInt(navigator.plugins[i].name.substr(dot-1, dot));
	  }
	}
}

/*
if (qtp && nav && win)) {
	for (i=0;i<navigator.plugins.length;i++) {
	  if (navigator.plugins[i].name.indexOf("QuickTime ") >= 0) {
	  	dot = navigator.plugins[i].name.indexOf(".");
	  	qtpver = parseInt(navigator.plugins[i].name.substr(dot-1, dot));
	  }
	}
}
*/

// If WMP is present determine version
if (wmp) {
	if (nav) {
		if (navigator.mimeTypes["video/x-ms-wm"] && navigator.mimeTypes["video/x-ms-wm"].enabledPlugin && navigator.mimeTypes["video/x-ms-wmv"] && navigator.mimeTypes["video/x-ms-wmv"].enabledPlugin) {
			wmpver = 6;
		}
	} else {
		if (exp) {
			document.writeln('<script language="VBscript">');
			document.writeln('  on error resume next');
			document.writeln('  Set stimpy = CreateObject("MediaPlayer.MediaPlayer.1")');
			document.writeln('  fHasWMP52 = (IsObject(stimpy))');
			document.writeln('  fHasWMP64 = (stimpy.FileName="")');
			document.writeln('  fHasWMP7 = (stimpy.URL="")');
			document.writeln('  If fHasWMP52 Then');
			document.writeln('    wmpver = 5');
		    document.writeln('  End If');
			document.writeln('  If fHasWMP64 Then');
			document.writeln('    wmpver = 6');
		    document.writeln('  End If');
			document.writeln('  If fHasWMP7 Then');
			document.writeln('    wmpver = 7');
		    document.writeln('  End If');
		    document.writeln('</scr' + 'ipt>');
		}
	}
}

// override
wmpver = 7;