// globals for All Pages
// browser
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isIE5 = (navigator.appVersion.indexOf("5.") != -1) ? true : false;
var isIE6 = (navigator.appVersion.indexOf("6.") != -1) ? true : false;
var isNS = (navigator.appName.indexOf("Netscape") != -1) ? true : false;

// platform 
var isWin = (navigator.appVersion.indexOf("Win") != -1) ? true : false;
var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;

// Flash Plugin yes/no
var isFlashinstalled = false;

// image variables
var preloadFlag = false;
var page = '';

function setWindowStatus(statusText){
	window.status = statusText;
	return true;
}

/********************   FLASH DETECTION  ******************************/

// -->

// Write out VB Functions
document.write('<SCR' + 'IPT LANGUAGE="VBScript"\>   \n');
// detect presence of ActiveX controls
document.write(' on error resume next  \n');

document.write(' Function detectFlashPC(lVersion)  \n');
document.write('   on error resume next  \n');
document.write('   Dim i, obj : obj = null \n ');
document.write('   flashVersion = 4                \n ');
document.write('    For i = lVersion To 4 Step - 1  \n');
document.write('	  Set obj = CreateObject("ShockwaveFlash.ShockwaveFlash." & i )   \n');
document.write('      If IsObject(obj) Then \n');
document.write('			 flashVersion = i \n');
document.write('			 Set obj = nothing \n');
document.write('			 Exit For \n');
document.write('	  End IF		 \n');	
document.write('    Next \n');
document.write('    detectFlashPC = flashVersion \n ');
document.write(' End Function ');
document.write('</SCR' + 'IPT\>     \n'); // break up end tag so it doesn't end our script

// -------------------------   Start  Detection function  -------------------------------

function detectFlash(lVersionToDetect, src, h, w, objectID, sRedirectPage){
	// Things we are looking for
	var flashVersion = 1;
	var bRedirect = false;
	
	// for redirection
	if(sRedirectPage.length > 0 && sRedirectPage != 'undefined'){ bRedirect = true;}
				
	flashVersion = getFlashVersion(lVersionToDetect);
	
	if(flashVersion > 3){
		isFlashinstalled = true;
	}
											
	// now we should have the version to detect for
	// if a mac with less than IE 5, can't do anything, user disgretion
	if((isIE && !isIE5) && isMac){
		var go = confirm(" You have a Mac with IE 4.x.  Do you have the flash plugin? Click Ok to continue to Flash Site, or cancel to get html version.");

		// download page
		if(!go)
			if(bRedirect)
				location.replace (sRedirectPage);
				
	}
	
	// now check everything else:		
	if ((!isFlashinstalled ) || (flashVersion  < lVersionToDetect)){
		var bgetFlash = confirm("Flash "+ lVersionToDetect + " or greater was not detected on your machine.  Please click Ok to download, or cancel to get html version. ");
		if (bgetFlash){
			getBrowserPlugin('flashplayer');	
		} else {
			// goto HTML Version, and pop up something on them
			getBrowserPlugin('flashplayer');
			if(bRedirect) 
				location.replace (sRedirectPage); 
		}
	}
	
	
	// all checks went through, render Flash Object
	if(src.length > 0 && src != 'undefined')
		renderFlashObject(src, h, w, objectID);
		
} // end of flash detectiion function

// ----------------------------------------------	//

function detectFlashNetscape(){
	var lVersion;
	if (navigator.plugins["Shockwave Flash 2.0"] 	// yes>> then is Flash 2 
		|| navigator.plugins["Shockwave Flash"]){		// or flash 3+ installed?
			isFlashinstalled = true;
			// set convenient references to flash 2 and the plugin description
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			// a flash plugin-description looks like this: Shockwave Flash 4.0 r5
			// so we can get the major version by grabbing the character before the period
			// note that we don't bother with minor version detection. do that in your movie with $version
			lVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
	}
	return lVersion;
} // end fo function

// ----------------------------------------------	//	

function getFlashVersion(lVersion){
	var lFlashVersion = 0;
	// Detect Flash Version for NetScape
	if (isNS || (isMac && (isIE5 || isIE6))){// does navigator.plugins exist?
		lFlashVersion = detectFlashNetscape();
	}
	// end of detecting flash for Netscrape
	
	// detection script for IE/Windows			
	if(((isIE) || (isIE5)) && isWin && !isNS ){ // don't write vbscript tags on anything but ie win
		lFlashVersion = detectFlashPC(lVersion);
	}
	// end of IE (PC) detection
	return lFlashVersion;
} // end of function

function renderFlashObject(src, h, w, objectid){
	// function will render Flash Object
	
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
	document.write('	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" \n');
	document.write('	width="'+ w +'" height="'+ h + '" \n');
	document.write('	id="'+ objectid +'" name="'+ objectid +'">     \n'); // end of object Tag
	document.write('	<param name="quality" value="high">\n');
	document.write('	<param name="movie" value="'+ src + '">\n');
	document.write('	<param name="menu" value="false">\n');
	document.write('	<EMBED src="'+ src +'"       \n');
	document.write('		quality=high Menu=false  \n');
	document.write('		width="'+ w +'" height="'+ h +'"\n');
	document.write('		type="application/x-shockwave-flash" \n');
	document.write('		PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">\n');
	document.write('</embed></object>\n');
}

function getBrowserPlugin(sPlugin){
	// function
	// opens window with plugin
	var sUrl, swindowoptions;
		
	sUrl = 'http://www.nylearns.org/utilities/getPlugin.asp?plugin=' + sPlugin ; 
	windowoptions = 'width=600,height=500,left=75,top=50,screenX=75,screenY=50, toolbars=no, scrollbars=yes, menubar=no,';
		
	var w = window.open(sUrl, 'plugin', windowoptions);
	w.focus();
}	

