/*	This new section allows you to create a flash movie on the page, whether it be in a DIV / LAYER
	Or on a page as an object tag!

	It contains a function called "ora_out" which allows you to document.write a whole string.
	And keep a log of what you are outputting.

	startFlash, is slightly different from that of the original, it will still require the
	EndFlash function as before, however, this is modified to output a TABLE instead of
	a backup gif (unless otherwise specified).

	for Instructions on use, please read the ora_flash.txt file in /javascript/documentation/
	or view the web formatted version:

		/cgi-bin/documentation/read.pl?file=ora_flash
*/

var aFlash = new Array();
var bUsedHTML = ((isDOM || isIE || isNetscape) && !isMac) ? true : false

/* Flash Version Info */
var iLatestFlashVersion = 20; /* This allows the script to be scalable */
var iMinimumFlashVersion = 3;
var iFlashVersion = -1;

/* Variable must be global for VBScript to work correctly. */
var thisFlashVersion;

function ora_flash_getIEVersion() {
	document.write('<scr'+'ipt language="VBScript">\n');
	document.write('on error resume next\n');
	document.write('For i = 2 to '+iLatestFlashVersion+'\n');
	document.write('	If Not(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & i))) Then\n');
	document.write('	Else\n');
	document.write('		thisFlashVersion = i\n');
	document.write('	End If\n');
	document.write('Next\n');
	document.write('</scr'+'ipt>\n');

	return thisFlashVersion;
}

function ora_flash_setVersion() {
	if (navigator.plugins.length > 0) {
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) <= 4) {
			/* Plugin detect, no VBScript support */
			navigator.plugins.refresh(false);
		}

		numPlugins = navigator.plugins.length;
		for(var i=0; i<numPlugins; i++)	{
			plugDesc = navigator.plugins[i].description;
			iFlashVersion = (plugDesc.indexOf("Flash") != -1) ? parseInt(plugDesc.charAt(parseInt(plugDesc.indexOf("Flash"))+6)) : 0;
			if(iFlashVersion > 0) {
				return;
			}
		}
	} else if(navigator.userAgent.indexOf("Mac") == -1 && (document.all || navigator.appName.indexOf("Opera") != -1)) {
		/* No plugin detect, VBScript support */
		iFlashVersion = ora_flash_getIEVersion();
	} else {
		/* No plugin detect, no VBScript support */
		iFlashVersion = iLatestFlashVersion;
	}
}

function startLayer(iLeft, iTop, iWidth, iHeight, returnOutput) {
	if(iLeft != 'static') {
		var sFlashID = "FlashLayer" + aFlash.length;

		var sText = '';

		if (isNetscape) {
			sText+= '<LAYER ID="' + sFlashID + '" Z-INDEX="50" POSITION="absolute" TOP="' + iTop + '" LEFT="' + iLeft + '" WIDTH="' + iWidth + '" HEIGHT="' + iHeight + '">';
		} else {
			sText+= '<DIV ID="' + sFlashID + '" STYLE="z-index:50; position:absolute; top:' + iTop + '; left:' + iLeft + '; width:' + iWidth + '; height:' + iHeight + ';">';
		}

		if(returnOutput) {
			return sText;
		} else {
			ora_out(sText);
		}
	}
	if(returnOutput) return;
}

function endLayer(iLeft, returnOutput) {
	if(iLeft != 'static') {
		var sText = (document.layers) ? '</LAYER>' : '</DIV>';
		if(returnOutput) {
			return sText;
		} else {
			ora_out(sText);
		}
	}
	if(returnOutput) return;
}

function startFlash(iLeft, iTop, sFilename, iWidth, iHeight, bGifBakup, iFlashVersionRequired, sBackgroundColour, sBackupMap, returnOutput, outputLayerOnly, sQuality, sId) {
	var sFlashID = (sId) ? sId : sFilename.substring(sFilename.lastIndexOf("/"));
	var sOutput = '';
	var START = '';
	var OBJ = '';
	var END = '';

	iWidth = (outputLayerOnly) ? 1 : iWidth;
	iHeight = (outputLayerOnly) ? 1 : iHeight;

	// iLeft is set to 0 if left out or entered as false, "" or "none"
	iLeft = (iLeft == "" || iLeft == "none" || !iLeft) ? 0 : iLeft;

	// iTop is set to 128 if entered as false, "", or "none"
	// and set to 98 if entered as 0, or "top"
	iTop = (iTop == "absolute") ? 0 : (iTop == 0 || iTop == "top") ? 98 : (iTop == false || iTop == "" || iTop == "none") ? 128 : iTop;

	// sets the minimum Flash Version Required to 3, if not set
	iFlashVersionRequired = (iFlashVersionRequired) ? iFlashVersionRequired : iMinimumFlashVersion;

	// creates an ID for this flash file
	sFlashID = sFlashID.replace(/\W/g,'');

	// Sets the background color to "#000000" DEFAULT, is not entered
	// Must enter colour codes as #?????? and make sure that there is a relevant colour file created
	// in /images/flash_replacement/
	sBackgroundColour = (sBackgroundColour) ? sBackgroundColour : '#000000';

	// Only runs the flash output if the Filename, Width and Height attributes have been parsed
	// and bUsedHTML is set to true (dHTML can be used in this browser)
	if(!isNetscape6 && sFilename && iWidth && iHeight && bUsedHTML && (iFlashVersion >= iFlashVersionRequired)) {
		START = startLayer(iLeft, iTop, iWidth, iHeight, returnOutput);
		OBJ = outputFlashObjectTag(iLeft, sFilename, iWidth, iHeight, sFlashID, returnOutput, sQuality);
		END = endLayer(iLeft, returnOutput);
	}
	sOutput = (outputLayerOnly) ? (START + END) : (START + OBJ + END);
	aFlash[aFlash.length] = new Array(sFlashID, iLeft, iTop, sFilename, iWidth, iHeight, bGifBakup, iFlashVersionRequired, sBackgroundColour, sBackupMap);
	return sOutput;
}

function outputFlashObjectTag(isSTATIC, sFilename, iWidth, iHeight, sFlashID, returnOutput, sQuality, sFlashVars) {
	if(isSTATIC != 'static') {
		var flOut = '';

        sQuality = (sQuality == '') ? 'high' : sQuality;

		// Start Object Tag
		flOut += '<object name="'+ sFlashID +'" id="'+ sFlashID +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ iWidth +'" height="'+ iHeight +'" codebase="'+ location.protocol +'//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">\n';
		flOut += '<param name="movie" value="'+ sFilename +'">\n';
		flOut += '<param name="play" value="true">\n';
		flOut += '<param name="loop" value="true">\n';
		flOut += '<param name="menu" value="false">\n';
		flOut += '<param name="quality" value="'+ sQuality +'">\n';
		flOut += '<param name="scale" value="noscale">\n';
		if (sFlashVars != null && sFlashVars != '') {
			flOut += '<param name="flashVars" value="'+ sFlashVars +'">\n';
		}
		// Start Embed Tag
		flOut += '<embed name="'+ sFlashID +'" id="'+ sFlashID +'" src="'+ sFilename +'" flashVars="'+ sFlashVars +'" width="'+ iWidth +'" height="'+ iHeight +'" menu="false" loop="true" play="true" scale="noscale" quality="best" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="'+ location.protocol +'//www.macromedia.com/go/getflashplayer">';

		// End Tags
		flOut += '</embed>\n';
		flOut += '</object>\n';

		// output sText
		if(returnOutput) {
			return flOut;
		} else {
			ora_out(flOut);
		}

		var oFlash = sFlashID;
	}
	if(returnOutput) return;
}

var ora_sText_output = '';
function ora_out(sText) {
	document.write(sText);
	ora_sText_output += sText+'\n\n';
}
function ora_outAlert() {
	alert(ora_sText_output);
}

function outputBackupGif( aBackupObj, iWidth, iHeight ) {
	var sBackupALT, sBackupIMG, iBackupWidth, iBackupHeight, sBackupLink, sBackupMap;

	sBackupIMG = '/images/flash_replacement/' + aBackupObj[0];
	sBackupALT = (aBackupObj[1]) ? ' ALT="' + aBackupObj[1] + '"' : '';
	iBackupWidth = (aBackupObj[2]) ? aBackupObj[2] : iWidth;
	iBackupHeight = (aBackupObj[3]) ? aBackupObj[3] : iHeight;
	sBackupLink = (aBackupObj[4]) ? '<A HREF="' + aBackupObj[4] + '">##IMG##</A>' : '##IMG##';
	sBackupMap = (aBackupObj[5]) ? ' USEMAP="#'+aBackupObj[5]+'"' : (sBackupMap) ? ' USEMAP="#'+sBackupMap+'"': '';

	return sBackupLink.replace(/##IMG##/,'<IMG SRC="' + sBackupIMG + '" WIDTH="' + iBackupWidth + '" HEIGHT="' + iBackupHeight + '" BORDER="0"' + sBackupALT + sBackupMap + '>');
}

function endFlash(iPosition, returnOutput, aBackupObj, displayNoFlashOnBackupGif, displayNoFlashFinal, sQuality) {
	var sBackupALT, sBackupIMG, iBackupWidth, iBackupHeight, sBackupLink;

	var outStr = '';
	var sFlashID = aFlash[iPosition][0];
	var iLeft = aFlash[iPosition][1];
	var isSTATIC = (iLeft == 'static') ? true : false;
	var sFilename = aFlash[iPosition][3];
	var iWidth = aFlash[iPosition][4];
	var iHeight = aFlash[iPosition][5];
	var bGifBakup = aFlash[iPosition][6];
	var iFlashVersionRequired = aFlash[iPosition][7];
	var sBackgroundColour = aFlash[iPosition][8].toLowerCase();
	var sBackupMap = aFlash[iPosition][9];
	displayNoFlashOnBackupGif = (iFlashVersion >= iFlashVersionRequired) ? false : displayNoFlashOnBackupGif;

	if(displayNoFlashFinal) {

		// Display Backup Gif
		outStr = outputBackupGif( aBackupObj, iWidth, iHeight );
		if(returnOutput) {
			return outStr;
		} else {
			ora_out(outStr);
		}

	} else if((isNetscape6 || !bUsedHTML) && iFlashVersion >= iFlashVersionRequired) {
		returnOutput = (navigator.userAgent.indexOf("Netscape 5") != -1) ? true : returnOutput;
		return outputFlashObjectTag(iLeft, sFilename, iWidth, iHeight, sFlashID, returnOutput, sQuality);
	} else if(!displayNoFlashOnBackupGif && (aBackupObj && !isSTATIC)) {

		// Display Backup Gif
		outStr = outputBackupGif( aBackupObj, iWidth, iHeight );
		if(returnOutput) {
			return outStr;
		} else {
			ora_out(outStr);
		}

	} else {
		sBackupIMG = '/images/flash_replacement/text_dont_worry_' + sBackgroundColour.substring(1) + '.gif'
		sBackupALT = ' ALT="don\'t worry, we havn\'t gone anywhere"';
		iBackupWidth = 215;
		iBackupHeight = 91;
		sBackupMap = (sBackupMap) ? ' USEMAP="#'+sBackupMap+'"' : '';

		var iWidthAvail = (iWidth < iBackupWidth) ? 1 : iBackupWidth;
		var iHeightAvail = (iHeight < iBackupHeight) ? 1 : iBackupHeight;
		var bCanDoImage = ((iWidthAvail > 1) && (iHeightAvail > 1)) ? true : false;
		var backupImage = (bGifBakup && bCanDoImage) ?  sBackupIMG : '/images/clear.gif';
		var backupGifURL = (aBackupObj && aBackupObj[4]) ? '<A HREF="'+aBackupObj[4]+'">#</A>' : '#';

		var sText = '';
		var sFlash = '';

		if(bCanDoImage) {
			// if using a non-dhtml browser, output the object tag here
			if (displayNoFlashOnBackupGif || (iFlashVersion < iFlashVersionRequired)) {
				// outputs the You don't have flash plugin page
				// this needs changing to say "you don't have flash installed"
				sText = displayNoFlash(iWidth, iHeight, sBackgroundColour.substring(1));
			} else if (!bUsedHTML || isSTATIC) {
				// outputs the Flash tag (if dHTML is not supported, and flash works on this machine)
				sFlash = outputFlashObjectTag('', sFilename, iWidth, iHeight, sFlashID, returnOutput, sQuality);
			}
		} else if(iFlashVersion < iFlashVersionRequired) {
			// do Nothing, as the area isn't big enough to output the "you don't have flash" page
		} else if (isSTATIC) {
			sFlash = outputFlashObjectTag('', sFilename, iWidth, iHeight, sFlashID, returnOutput, sQuality);
		}

		if(!isNetscape6 && (((iFlashVersion >= iFlashVersionRequired) && bUsedHTML) || !bCanDoImage)) {
			// outputs the table to appear behind all flash in dHTML capable browsers
			sText+= '<TABLE BGCOLOR="' + sBackgroundColour + '" CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="' + iWidth + '" HEIGHT="' + iHeight + '">';
			sText+= '<TR>';
			sText+= '	<TD VALIGN="top" ALIGN="left" WIDTH="' + iWidth + '" HEIGHT="' + iHeight + '">';
			sText+= backupGifURL.replace(/#/,'	<IMG SRC="' + backupImage + '" WIDTH="' + iWidthAvail + '" HEIGHT="' + iHeightAvail + '" BORDER="0"' + sBackupALT + sBackupMap + '>');
			sText+= '	</TD>';
			sText+= '</TR>';
			sText+= '</TABLE>\n\n';
		}
		if(returnOutput) {
			if(!sFlash) sFlash = sText;
			return sFlash;
		} else {
			ora_out(sText);
		}
	}
}

function hide_all(flash) {
	for (var i=0; i<dMenu.length; hide_menu(i), i++) {
		for (var j=0; j<dSubMenu[i].length; j++) {
			hide_sub(i,j);
		}
	}
	if (flash) {
		hide_flash();
	} else {
		show_flash();
	}
}

var oraFlashDownloadURL = '/cgi-bin/redirect/http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash';
function displayNoFlash(iWidth, iHeight, sBackgroundColour) {
	var sText = '';
	var newFontColor = (typeof sBackgroundColour != "undefined") ? (sBackgroundColour.toUpperCase() == 'FFFFFF') ? ' COLOR="#000000"' : ' COLOR="#FFFFFF"' : '';

	// if Available Height & Width are good, then use the large box!
	if(iWidth >= 196 && iHeight >= 234) {
		sText += '<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="' + iWidth + '" HEIGHT="' + iHeight + '">\n';
		sText += '<TR>\n';
		sText += ' <TD ALIGN="center" VALIGN="middle">\n';
		sText += ' <TABLE BGCOLOR="#' + sBackgroundColour + '" CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="196" HEIGHT="234">\n';
		sText += ' <TR><TD COLSPAN="3" HEIGHT="20"></TD></TR>\n';
		sText += ' <TR>\n';
		sText += '  <TD><IMG SRC="/images/clear.gif" WIDTH="20" HEIGHT="2" BORDER="0"></TD>\n';
		sText += '  <TD WIDTH="190"><FONT FACE="Helvetica, Arial" SIZE="-1"'+newFontColor+'>';
		sText += '  <IMG SRC="/images/javascript/ora_flash/head_just_a_sec_' + sBackgroundColour + '.gif" WIDTH="156" HEIGHT="31" BORDER="0" ALT="just a sec..."><BR>\n';
		sText += '  <IMG SRC="/images/clear.gif" WIDTH="2" HEIGHT="10" BORDER="0"><BR>\n';
		sText += '  To help us connect you to this section of the site, please download the latest version of the flash plugin.<BR><BR>\n';
		sText += '  This won\'t take too long.<BR>\n';
		sText += '  <IMG SRC="/images/clear.gif" WIDTH="2" HEIGHT="25" BORDER="0"><BR>\n';
		sText += '  <IMG SRC="/images/javascript/ora_flash/arrow_down_' + sBackgroundColour + '.gif" WIDTH="28" HEIGHT="32" BORDER="0" HSPACE="4" ALIGN="left">';
		sText += '  <IMG SRC="/images/javascript/ora_flash/head_download_the_latest_' + sBackgroundColour + '.gif" WIDTH="117" HEIGHT="18" BORDER="0" ALT="download the latest"><BR>\n';
		sText += '  <A HREF="' + oraFlashDownloadURL + '" TARGET="_blank" OnMouseOver="MouseOver(\'oraFlashLatestVersion\');" OnMouseOut="MouseOut(\'oraFlashLatestVersion\');"><IMG NAME="oraFlashLatestVersion"SRC="/images/javascript/ora_flash/link_flash_version_' + sBackgroundColour + '.gif" WIDTH="117" HEIGHT="11" BORDER="0" ALT="Flash version"></A>';
		sText += '</FONT></TD>\n';
		sText += '  <TD><IMG SRC="/images/clear.gif" WIDTH="20" HEIGHT="2" BORDER="0"></TD>\n';
		sText += ' </TR>\n';
		sText += ' <TR><TD COLSPAN="3" HEIGHT="20"></TD></TR>\n';
		sText += ' </TABLE>\n';
		sText += ' </TD>\n';
		sText += '</TR>\n';
		sText += '</TABLE>\n';
	} else if(iWidth >= 236 && iHeight >= 194) {
		// Use Wide (You dont have flash box)
		sText += '<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="' + iWidth + '" HEIGHT="' + iHeight + '">\n';
		sText += '<TR>\n';
		sText += ' <TD ALIGN="center" VALIGN="middle">\n';
		sText += ' <TABLE BGCOLOR="#' + sBackgroundColour + '" CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="236" HEIGHT="194">\n';
		sText += ' <TR><TD COLSPAN="3" HEIGHT="20"></TD></TR>\n';
		sText += ' <TR>\n';
		sText += '  <TD><IMG SRC="/images/clear.gif" WIDTH="20" HEIGHT="2" BORDER="0"></TD>\n';
		sText += '  <TD WIDTH="190"><FONT FACE="Helvetica, Arial" SIZE="-1"'+newFontColor+'>';
		sText += '  <IMG SRC="/images/javascript/ora_flash/head_just_a_sec_' + sBackgroundColour + '.gif" WIDTH="156" HEIGHT="31" BORDER="0" ALT="just a sec..."><BR>\n';
		sText += '  <IMG SRC="/images/clear.gif" WIDTH="2" HEIGHT="10" BORDER="0"><BR>\n';
		sText += '  To help us connect you to this section of the site, please download the latest version of the flash plugin.<BR><BR>\n';
		sText += '  This won\'t take too long.<BR>\n';
		sText += '  <IMG SRC="/images/clear.gif" WIDTH="2" HEIGHT="25" BORDER="0"><BR>\n';
		sText += '  <IMG SRC="/images/javascript/ora_flash/arrow_down_' + sBackgroundColour + '.gif" WIDTH="28" HEIGHT="32" BORDER="0" HSPACE="4" ALIGN="left">';
		sText += '  <IMG SRC="/images/javascript/ora_flash/head_download_the_latest_' + sBackgroundColour + '.gif" WIDTH="117" HEIGHT="18" BORDER="0" ALT="download the latest"><BR>\n';
		sText += '  <A HREF="' + oraFlashDownloadURL + '" TARGET="_blank" OnMouseOver="MouseOver(\'oraFlashLatestVersion\');" OnMouseOut="MouseOut(\'oraFlashLatestVersion\');"><IMG NAME="oraFlashLatestVersion"SRC="/images/javascript/ora_flash/link_flash_version_' + sBackgroundColour + '.gif" WIDTH="117" HEIGHT="11" BORDER="0" ALT="Flash version"></A>';
		sText += '</FONT></TD>\n';
		sText += '  <TD><IMG SRC="/images/clear.gif" WIDTH="20" HEIGHT="2" BORDER="0"></TD>\n';
		sText += ' </TR>\n';
		sText += ' <TR><TD COLSPAN="3" HEIGHT="20"></TD></TR>\n';
		sText += ' </TABLE>\n';
		sText += ' </TD>\n';
		sText += '</TR>\n';
		sText += '</TABLE>\n';
	} else if(iWidth >= 128 && iHeight >= 128) {
		// Use small square output
	} else {
		// Don't display anything
	}

	return sText;
}

// Set Flash Version
ora_flash_setVersion();
