// error handling
self.onerror = function () { return true; }

// flash detection
var requiredVersion = 6;	// version of Flash Player required to display the Flash content.
var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var maxVersion = 7;
var actualVersion = 0;
var flashEnabled = false;

var ie = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var win = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

if (ie && win) {
	document.write('<scr' + 'ipt language=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installed =	(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('flash3Installed =	(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")))	\n');
	document.write('flash4Installed =	(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")))	\n');
	document.write('flash5Installed =	(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))	\n');  
	document.write('flash6Installed =	(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))	\n');  
	document.write('flash6Installed =	(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7")))	\n');  
	document.write('</scr' + 'ipt\> \n');
}

function detectFlash() {
	// this function only runs if the test results are not retreived from the cookie
	if (navigator.plugins) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"]	? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".")	- 1));
			flash2Installed	= flashVersion == 2;	  
			flash3Installed = flashVersion == 3;
			flash4Installed = flashVersion == 4;
			flash5Installed = flashVersion == 5;
			flash6Installed = flashVersion == 6;
			flash7Installed = flashVersion >= 7;
		}
	}
	for (var i = 2; i <= maxVersion; i++) {  
		if (eval("flash" + i + "Installed")) actualVersion = i;
	}
	if (navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3; 
	if (actualVersion >= requiredVersion) flashEnabled = true;
	return;
}


function InsertContent () {
	// check for flash plugin
	detectFlash();
	// create codestring
	var code = "\n";
	if (flashEnabled) {
		var swfUrl = "intro.swf";
		code += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="845" height="585" id="pha" align="middle">' + "\n\t";
		code += '<param name=movie value="' + swfUrl + '">' + "\n\t";
		code += '<param name=quality value=high>' + "\n\t";
		code += '<param name=menu value=false>' + "\n\t";
		code += '<param name=bgcolor value=#000000>' + "\n\t";
		code += '<embed src="' + swfUrl + '" quality=high bgcolor=#000000 menu=false width="845" height="585" name="pha" align="center" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' + "\n";
		code += '</object>' + "\n";
	} else {
		code += '<map name="flashlink"><area shape="rect" coords="35,15,90,30" target="_blank" href="http://www.macromedia.com/go/getflashplayer"></map>';
		code += '<table border=0 width=760 cellspacing=0 cellpadding=0>';
		code += '<tr height=50><td align=left>';
		code += '<image src="images/pha_logo.jpg" width=220 height=50 border=0 alt="Peter Hossack Architect Inc.">';
		code += '</td></tr>';
		code += '<tr height=30><td align=left>';
		code += '<image src="images/pha_noflash.jpg" width=340 height=30 border=0 alt="You need the Flash 7 Player" usemap="#flashlink">';
		code += '</td></tr>';
		code += '</table>';
	}
	// insert the code into the document
	document.write(code);
}
