// ====================================================
// force netscape 4.x to reload page on resize
// ====================================================
function reloadPage(init) { 
	if (init == true) {
		if ((navigator.appName=="Netscape") && (parseInt(navigator.appVersion)==4)) {
	    	document.MM_pgW = window.innerWidth; 
			document.MM_pgH = window.innerHeight; 
			// register onResize event handler
			window.onresize = reloadPage; 
			// additionally check for resize every 1000 ms (NN 4.78 + flash somehow blocked the event handler)
			setTimeout("reloadPage(false)", 1000);
		}
	} else if (window.innerWidth != document.MM_pgW || window.innerHeight != document.MM_pgH) {
	   location.reload();
	} else {
		// next check in 1000 ms 
		setTimeout("reloadPage(false)", 1000);
	}
}

// install handler
if ( ! ((navigator.appVersion.indexOf("Mac") != -1) && (navigator.appName=="Netscape") && (parseInt(navigator.appVersion)==4))) {
	reloadPage(true);
}

// ====================================================
// flash version checking starting here
// ====================================================

// returns whether checking is to be done using the navigator.mimeTypes array
function Flash_checkUseMimeTypes() {
	return (navigator.mimeTypes && (navigator.mimeTypes.length > 0));
}

// return whether checking is to be done using ActiveX (MS IE >= 4.0 on Windows)
function Flash_checkUseActiveX() {
	return ( (navigator.appName.indexOf("Microsoft") != -1) && (navigator.appVersion.indexOf("Windows") != -1) && (parseFloat(navigator.appVersion) >= 4) );
}

// check for flash using navigator.mimeTypes
function Flash_checkForPlugIn(minVersion) {
  var plugin = (navigator.mimeTypes &&
  navigator.mimeTypes["application/x-shockwave-flash"]) ?
  navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
  if (plugin) {
    var pluginversion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) 
    if (pluginversion >= minVersion) {return true;}
  }
  return false;
}

// check for flash using ActiveX
if (Flash_checkUseActiveX()) {
  document.write(
    '<script language=VBScript>' + '\n' +
    'Function Flash_checkForActiveX(minVersion)' + '\n' +
    'Dim hasPlayer, playerversion' + '\n' +
    'hasPlayer = false' + '\n' +
    'playerversion = 10' + '\n' +
    'Do While playerversion >= minVersion' + '\n' +
    'On Error Resume Next' + '\n' +
    'hasPlayer = (IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" & playerversion & \"\")))' + '\n' +
    'If hasPlayer = true Then Exit Do' + '\n' +
    'playerversion = playerversion - 1' + '\n' +
    'Loop' + '\n' +
    'Flash_checkForActiveX = hasPlayer' + '\n' +
    'End Function' + '\n' +
    '<\/script>'
  );
}

// result of first checkFlash call is stored here, later calls use this value
var __flashCheck;

// returns if minimum flashversion is installed
function checkFlash() {
	// this is the minimum required flash version
	FLASH_MIN_VERSION = 5;	
	if (__flashCheck == null) {
		// not checked yet: do check

		// ******************************************************************
		// work-around: disable Flash for Macs
		//if (navigator.appVersion.indexOf("Mac") != -1) {
		//	return (__flashCheck = false);
		//}
		// ******************************************************************

		// use appropriate check for user agent
		if (Flash_checkUseMimeTypes()) return (__flashCheck = Flash_checkForPlugIn(FLASH_MIN_VERSION));
		if (Flash_checkUseActiveX()) return (__flashCheck = Flash_checkForActiveX(FLASH_MIN_VERSION));
		// unsupported browser
		return (__flashCheck = false);
	} else {
		// already checked: return stored result
		return __flashCheck;
	}
}

// inserts HTML object/embed tags for loading flash if minimum requirements are met
function insertFlash(source, id, width, height) {
	if (checkFlash()) {	
		heightCode = (height == null) ? "" : 'height="' + height + '"';	
		document.writeln('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="' + id + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH="' + width + '" ' + heightCode + ' standby="...">'); 
		document.writeln('<PARAM NAME="movie" VALUE="' + source + '">');
		document.writeln('<PARAM NAME="quality" VALUE="high">');
		document.writeln('<PARAM NAME="bgcolor" VALUE="#FFFFFF">');								
		document.writeln('<EMBED src="' + source + '" name="' + id + '" quality="high" bgcolor="#FFFFFF" WIDTH="' + width + '" ' + heightCode + ' ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
		document.writeln('</OBJECT>');
	}
}
