/*
	## Macromedia Detection Kit
	## Library downloaded: 11/17/2005
	## http://www.macromedia.com/software/flashplayer/download/detection_kit/
*/
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 6;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 65;
// the version of javascript supported
var jsVersion = 1.1;
// -----------------------------------------------------------------------------

// Detect Client Browser type
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		flashVer = -1;
	}
	return flashVer;
} 
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
	//# CUSTOM CODE (NOT PART OF DETCTION SCRIPT)
	//  Allows for a query string paramerter to force flash detection to return true or false
	if ( location.search.toLowerCase().indexOf("forceflash=on") > -1 )
		return true;
	else if ( location.search.toLowerCase().indexOf("forceflash=off") > -1 )
		return false;
	//# END CUSTOM CODE
	
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
}
hasReqestedFlashVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
// End Macromedia Detection Kit

/*	Unobtrusive Flash Objects (UFO) v2.0 <http://www.bobbyvandersluis.com/ufo/>
	Copyright 2005 Bobby van der Sluis
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
	
	!! NOTE !!
	This library has been modfied from its orginal in order to utilize the Macromedia Detection Kit.
	The UFO parameters "majorversion", "build" are currently ignored. Minimum required flash version
	is now controlled by the Macromedia Detection Kit above. See comments with "##" for specific details
*/

var UFO = {
	//requiredAttrParams: ["movie", "width", "height", "majorversion", "build"], # Removed requirement for majorversion and build. Set globally with Detection Kit vars above
	requiredAttrParams: ["movie", "width", "height"],
	optionalAttrEmb: ["name", "swliveconnect", "align"],
	optionalAttrObj: ["id", "align"],
	optionalAttrParams: ["play", "loop", "menu", "quality", "scale", "salign", "wmode", "bgcolor", "base", "flashvars", "devicefont", "allowscriptaccess"],
	hsName: "visibility",
	hsShow: "visible",
	hsHide: "hidden",
	xiEnabled: false,
	xiMovie: "ufo.swf",
	xiWidth: "215",
	xiHeight: "138",
	
	create: function(FO, id) {
		if (!UFO.is_w3cdom) return;
		UFO.init(FO);
		//UFO.createStyleRule("#" + id, UFO.hsName + ":" + UFO.hsHide + ";"); ## Moved into flash detect block so element is only modified if flash is true
		//																	  ## Modfied so that the block with static content takes up the same space as the floated Flash piece, perserving layout structure
		var loadfn = function() {
			//UFO.setElementStyleById(id, UFO.hsName, UFO.hsHide); ## Moved into flash detect block so element is only modified if flash is true
			if (UFO.hasRequiredAttrParams(FO)) {
				//if (UFO.hasFlashVersion(FO.majorversion, FO.build)) { ## Replaced by Detection Kit function and vars
				if ( hasReqestedFlashVersion ) {
					UFO.createStyleRule("#" + id, UFO.hsName + ":" + UFO.hsHide + ";height:" + FO.height + "px;width:" + FO.width + "px;");
					UFO.setElementStyleById(id, UFO.hsName, UFO.hsHide);
					UFO.writeFlashObject(FO, id);
				}
				//else if (UFO.xiEnabled && UFO.hasFlashVersion("6", "65")) { ## Replaced by Detection Kit function
				else if (UFO.xiEnabled && DetectFlashVer(6, 0, 65)) {
					UFO.createModalDialog(FO);
				}
			}
			UFO.setElementStyleById(id, UFO.hsName, UFO.hsShow);
		};
		//UFO.addLoadEvent(loadfn); ## Removed as contents are to be displayed immediately on the call to initUFO (custom wrapper)
		loadfn();
	},
	
	is_w3cdom: function() {
		return (document.getElementById && document.getElementsByTagName && (document.createElement || document.createElementNS));
	},

	init: function(FO) {
		var agt = navigator.userAgent.toLowerCase();
		var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
		UFO.is_iewin = (is_ie && (agt.indexOf("win") != -1));
		UFO.is_iemac = (is_ie && (agt.indexOf("mac") != -1));
		UFO.is_safari = (agt.indexOf("safari") != -1);
		UFO.is_XML = (typeof document.contentType != "undefined" && document.contentType.indexOf("xml") > -1);
		if (typeof FO.hideshow != "undefined" && FO.hideshow == "display") {
			UFO.hsName = "display";
			UFO.hsShow = "block";
			UFO.hsHide = "none";
		}
		if (typeof FO.xi != "undefined" && FO.xi == "true") {
			UFO.xiEnabled = true;
			if (typeof FO.ximovie != "undefined") UFO.xiMovie = FO.ximovie;
			if (typeof FO.xiwidth != "undefined") UFO.xiWidth = FO.xiwidth;
			if (typeof FO.xiheight != "undefined") UFO.xiHeight = FO.xiheight;
		}
	},

	createStyleRule: function(selector, declaration) {
		if (UFO.is_iemac) return; // bugs in IE/Mac
		var head = document.getElementsByTagName("head")[0]; 
		var style = UFO.createElement("style");
		if (!UFO.is_iewin) {
			var styleRule = document.createTextNode(selector + " {" + declaration + "}");
			style.appendChild(styleRule); // bugs in IE/Win
		}
		style.setAttribute("type", "text/css");
		style.setAttribute("media", "screen"); 
		head.appendChild(style);
		if (UFO.is_safari && UFO.is_XML) { head.innerHTML += ""; } // force Safari repaint for MIME type application/xhtml+xml
		if (UFO.is_iewin && document.styleSheets && document.styleSheets.length > 0) {
			var lastStyle = document.styleSheets[document.styleSheets.length - 1];
			if (typeof lastStyle.addRule == "object") {
				lastStyle.addRule(selector, declaration);
			}
		}
	},

	setElementStyleById: function(id, propName, propValue) {
		document.getElementById(id).style[propName] = propValue;
	},
	
	hasRequiredAttrParams: function(FO) {
		for (var i = 0; i < UFO.requiredAttrParams.length; i++) {
			if (typeof FO[UFO.requiredAttrParams[i]] == "undefined") return false;
		}
		return true;
	},
	
	//hasFlashVersion: ## Replaced by Detection Kit function

	writeFlashObject: function(FO, id) {
		var el = document.getElementById(id);
		if (typeof el.innerHTML == "undefined") return;
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			try	{ // Gecko only supports innerHTML get and not set
				el.innerHTML = "ufo-test";
			}
			catch (e) {}
			if (el.innerHTML != "ufo-test") {
				while(el.hasChildNodes()) {
					el.removeChild(el.firstChild);
				}
				var embed = UFO.createElement("embed");
				embed.setAttribute("type", "application/x-shockwave-flash");
				embed.setAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
				embed.setAttribute("src", FO.movie);
				embed.setAttribute("width", FO.width);
				embed.setAttribute("height", FO.height);
				for (var i = 0; i < UFO.optionalAttrEmb.length; i++) {
					if (typeof FO[UFO.optionalAttrEmb[i]] != "undefined") {
						embed.setAttribute(UFO.optionalAttrEmb[i], FO[UFO.optionalAttrEmb[i]]);
					}
				}
				for (var i = 0; i < UFO.optionalAttrParams.length; i++) {
					if (typeof FO[UFO.optionalAttrParams[i]] != "undefined") {
						embed.setAttribute(UFO.optionalAttrParams[i], FO[UFO.optionalAttrParams[i]]);
					}
				}	
				el.appendChild(embed);
			}
			else {
				var embHTML = "";
				for (var i = 0; i < UFO.optionalAttrEmb.length; i++) {
					if (typeof FO[UFO.optionalAttrEmb[i]] != "undefined") {
						embHTML += ' ' + UFO.optionalAttrEmb[i] + '="' + FO[UFO.optionalAttrEmb[i]] + '"';
					}
				}
				for (var i = 0; i < UFO.optionalAttrParams.length; i++) {
					if (typeof FO[UFO.optionalAttrParams[i]] != "undefined") {
						embHTML += ' ' + UFO.optionalAttrParams[i] + '="' + FO[UFO.optionalAttrParams[i]] + '"';
					}
				}
				el.innerHTML = '<embed type="application/x-shockwave-flash" src="' + FO.movie + '" width="' + FO.width + '" height="' + FO.height + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' + embHTML + '></embed>';
			}
		}
		else {
			var objAttrHTML = "";
			for (var i = 0; i < UFO.optionalAttrObj.length; i++) {
				if (typeof FO[UFO.optionalAttrObj[i]] != "undefined") {
					objAttrHTML += ' ' + UFO.optionalAttrObj[i] + '="' + FO[UFO.optionalAttrObj[i]] + '"';
				}
			}
			var objParamHTML = "";
			for (var i = 0; i < UFO.optionalAttrParams.length; i++) {
				if (typeof FO[UFO.optionalAttrParams[i]] != "undefined") {
					objParamHTML += '<param name="' + UFO.optionalAttrParams[i] + '" value="' + FO[UFO.optionalAttrParams[i]] + '" />';
				}
			}
			//el.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + objAttrHTML + ' width="' + FO.width + '" height="' + FO.height + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + FO.majorversion + ',0,' + FO.build + ',0"><param name="movie" value="' + FO.movie + '" />' + objParamHTML + '</object>'; # Replaced FO.majorversion and FO.build with Detection Kit vars
			el.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + objAttrHTML + ' width="' + FO.width + '" height="' + FO.height + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + requiredMajorVersion + ',0,' + requiredRevision + ',0"><param name="movie" value="' + FO.movie + '" />' + objParamHTML + '</object>';
		}
	},

	createModalDialog: function(FO) {
		UFO.createStyleRule("body", "height:100%;");
		UFO.createStyleRule("#xi-con", "position:absolute; left:0; top:0; z-index:1000; width:100%; height:100%; background-color:#333; filter:alpha(opacity:50); -khtml-opacity:0.5; -moz-opacity:0.5; opacity:0.5; text-align:center;");
		UFO.createStyleRule("#xi-mod", "margin:120px auto 0; width:" + UFO.xiWidth + "px; height:" + UFO.xiHeight + "px;");
		var body = document.getElementsByTagName("body")[0];
		var container = UFO.createElement("div");
		container.setAttribute("id", "xi-con");
		var dialog = UFO.createElement("div");
		dialog.setAttribute("id", "xi-mod");
		container.appendChild(dialog);
		body.appendChild(container);
		var MMredirectURL = window.location; // MM code
		document.title = document.title.slice(0, 47) + " - Flash Player Installation"; // MM code
		var MMdoctitle = document.title; // MM code
		if (UFO.is_iewin) {
			var xiFO = { movie:UFO.xiMovie, width:UFO.xiWidth, height:UFO.xiHeight, majorversion:"6", build:"65", flashvars:"MMredirectURL=" + MMredirectURL + "&MMplayerType=ActiveX&MMdoctitle" + MMdoctitle };
		}
		else {
			var xiFO = { movie:UFO.xiMovie, width:UFO.xiWidth, height:UFO.xiHeight, majorversion:"6", build:"65", flashvars:"MMredirectURL=" + MMredirectURL + "&MMplayerType=PlugIn&MMdoctitle" + MMdoctitle };
		}
		UFO.writeFlashObject(xiFO, "xi-mod");
	},

	expressInstallCallback: function() {
		var body = document.getElementsByTagName("body")[0];
		var dialog = document.getElementById("xi-con");
	    body.removeChild(dialog);
		UFO.createStyleRule("body", "height:auto;");
	},

	createElement: function(el) {
		return (typeof document.createElementNS != "undefined") ?  document.createElementNS("http://www.w3.org/1999/xhtml", el) : document.createElement(el);
	}
	
	//, addLoadEvent: function(fn) ## Removed based on custom wrapper. Contents are displayed immediately upon the call of initUFO
};
// End UFO

// Custom wrapper for unobtrusive UFO implementation
// INPUTS
// divID - ID of the div element that contains the non flash elements and all the UFO attributes
// swfPathID - ID of the image element that contains the flash movies source. This is a hack to work
//         around collage issues.
function initUFO( divID, swfPathID ) {
	var prefix = 'ufo';
	var elm = document.getElementById( divID );
	//alert("NFD: in initUFO");
	if ( typeof( elm ) != 'undefined' ) {

		//Fill out flash object based on params
		var flashObj = [];
		if (getHtml(swfPathID)) // Required Attribute Params
			flashObj.movie = getHtml(swfPathID);
		if (elm.getAttribute(prefix+'width'))
			flashObj.width = elm.getAttribute(prefix+'width');
		if (elm.getAttribute(prefix+'height'))
			flashObj.height = elm.getAttribute(prefix+'height');
		if (elm.getAttribute(prefix+'name')) // Optional Embed params
			flashObj.name = elm.getAttribute(prefix+'name');
		if (elm.getAttribute(prefix+'swliveconnect'))
			flashObj.swliveconnect = elm.getAttribute(prefix+'swliveconnect');
		if (elm.getAttribute(prefix+'align'))
			flashObj.align = elm.getAttribute(prefix+'align');
		if (elm.getAttribute(prefix+'id')) // Optional Object params
			flashObj.id = elm.getAttribute(prefix+'id');
		if (elm.getAttribute(prefix+'align'))
			flashObj.align = elm.getAttribute(prefix+'align');
		if (elm.getAttribute(prefix+'play')) // Optional Attribute Params
			flashObj.play = elm.getAttribute(prefix+'play');
		if (elm.getAttribute(prefix+'loop'))
			flashObj.loop = elm.getAttribute(prefix+'loop');
		else flashObj.loop = 'false';
		if (elm.getAttribute(prefix+'menu'))
			flashObj.menu = elm.getAttribute(prefix+'menu');
		else flashObj.menu = 'false';
		if (elm.getAttribute(prefix+'quality'))
			flashObj.quality = elm.getAttribute(prefix+'quality');
		else flashObj.quality = 'high';
		if (elm.getAttribute(prefix+'scale'))
			flashObj.scale = elm.getAttribute(prefix+'scale');
		else flashObj.scale = 'exactfit';
		if (elm.getAttribute(prefix+'salign'))
			flashObj.salign = elm.getAttribute(prefix+'salign');
		if (elm.getAttribute(prefix+'wmode'))
			flashObj.wmode = elm.getAttribute(prefix+'wmode');
		if (elm.getAttribute(prefix+'bgcolor'))
			flashObj.bgcolor = elm.getAttribute(prefix+'bgcolor');
		if (elm.getAttribute(prefix+'base'))
			flashObj.base = elm.getAttribute(prefix+'base');
		if (elm.getAttribute(prefix+'flashvars'))
			flashObj.flashvars = elm.getAttribute(prefix+'flashvars');
		if (elm.getAttribute(prefix+'devicefont'))
			flashObj.devicefont = elm.getAttribute(prefix+'devicefont');
		if (elm.getAttribute(prefix+'allowscriptaccess'))
			flashObj.allowscriptaccess = elm.getAttribute(prefix+'allowscriptaccess');
		UFO.create(flashObj, divID);
	}
}
