/******************************************************************************
 Flash Detection API

 Author: Dan G. Switzer, II
 Date:   May 19, 2005
 Build:  1.1.001

 To contribute money to further the development of the qForms API, see:
 http://www.pengoworks.com/qForms/donations/

 GNU License
 ---------------------------------------------------------------------------
 This library provides common methods for interacting with HTML forms
 Copyright (C) 2001  Dan G. Switzer, II

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for mser details.
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
******************************************************************************/
var _x;

function _fpApi(){
	this.htmlTag = null;
	this.version = null;
	this.installed = false;
	this.detected = false;
	this.swLiveConnect = false;
	this.scale = "noscale";
	this.quality = "high";
	this.errorMsg = "This page requires Macromedia Flash v%VER% of higher.";
	this.requiredVersion = (!!window._fp_requiredVersion) ? _fp_requiredVersion : "6,0,0,0";
}
var flashPlugin = new _fpApi();

_fpApi.prototype.loadMovie = function (sSrc, sId, sWidth, sHeight, sBgColor, sAlign, sSAlign){
	if( this.isFlashAvailable() ){
		var aSource = [];
		switch( this.htmlTag ){
			case "embed":
				aSource[aSource.length] = "<embed";
				aSource[aSource.length] = " src=\"" + sSrc + "\"";
				aSource[aSource.length] = " name=\"" + sId + "\"";
				aSource[aSource.length] = " id=\"" + sId + "\"";
				aSource[aSource.length] = " width=\"" + sWidth + "\"";
				aSource[aSource.length] = " height=\"" + sHeight + "\"";
				aSource[aSource.length] = " quality=\"" + this.quality + "\"";
				if( typeof sBgColor == "string" ) aSource[aSource.length] = " bgcolor=\"" + sBgColor + "\"";
				if( typeof sSAlign == "string" ) aSource[aSource.length] = " salign=\"" + sSAlign + "\"";
				if( typeof sAlign == "string" ) aSource[aSource.length] = " align=\"" + sAlign + "\"";
				aSource[aSource.length] = " swLiveConnect=\"" + this.swLiveConnect + "\"";
				if( this.scale.length > 0 ) aSource[aSource.length] = " scale=\"" + this.scale + "\"";
				aSource[aSource.length] = " type=\"application/x-shockwave-flash\"";
				aSource[aSource.length] = " pluginspace=\"http://www.macromedia.com/go/getflashplayer\"";
				aSource[aSource.length] = "></embed>";
			break;

			case "object":
				aSource[aSource.length] = "<object";
				aSource[aSource.length] = " classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
				aSource[aSource.length] = " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + this.requiredVersion + "\"";
				aSource[aSource.length] = " width=\"" + sWidth + "\"";
				aSource[aSource.length] = " height=\"" + sHeight + "\"";
				aSource[aSource.length] = " name=\"" + sId + "\"";
				aSource[aSource.length] = " id=\"" + sId + "\"";
				if( typeof sAlign == "string" ) aSource[aSource.length] = " align=\"" + sAlign + "\"";
				aSource[aSource.length] = ">";
				aSource[aSource.length] = "<param name=\"movie\" value=\"" + sSrc + "\">";
				aSource[aSource.length] = "<param name=\"quality\" value=\"" + this.quality + "\">";
				aSource[aSource.length] = "<param name=\"swLiveConnect\" value=\"" + this.swLiveConnect + "\">";
				if( this.scale.length > 0 ) aSource[aSource.length] = "<param name=\"scale\" value=\"" + this.scale + "\">";

				if( typeof sBgColor == "string" ) aSource[aSource.length] = "<param name=\"bgcolor\" value=\"" + sBgColor + "\">";
				if( typeof sSAlign == "string" ) aSource[aSource.length] = "<param name=\"salign\" value=\"" + sSAlign + "\">";
				aSource[aSource.length] = "</object>";
			break;
		}

		// write the HTML to the page
		document.write(aSource.join(""));
		return true;
	} else {
		return false;
	}
}

_fpApi.prototype.throwError = function (){
	document.write("<p class=\"flashError\">" + this.errorMsg.replace(/%VER%/g, this.requiredVersion.substring(0,1)) + "</p>");
	return true;
}

_fpApi.prototype.showImage = function (sSrc, sWidth, sHeight, oArguments){
	var aSource = [];
	aSource[aSource.length] = "<img src=\"" + sSrc + "\"";
	aSource[aSource.length] = " width=\"" + sWidth + "\"";
	aSource[aSource.length] = " height=\"" + sHeight + "\"";
	aSource[aSource.length] = " alt=\"" + ((typeof sAlt == "string") ? sAlt : "") + "\"";
	if( typeof oArguments == "object" ){
		for( var k in oArguments ){
			aSource[aSource.length] = " " + k + "=\"" + oArguments[k] + "\"";
		}
	}
	aSource[aSource.length] = " />";
	
	// write the HTML to the page
	document.write(aSource.join(""));
	return true;
}

_fpApi.prototype.isFlashAvailable = function (){
	return (this.installed && (this.version >= parseInt(this.requiredVersion) ));
}

// if the browser is a non-IE browser
if( navigator.plugins && navigator.plugins.length ){
	flashPlugin.htmlTag = "embed";
	
	// check for newer version of Flash
	_x = navigator.plugins["Shockwave Flash"];
	if( _x ){
		flashPlugin.installed = true;
		flashPlugin.detected = true;
		if( !!_x.description ) flashPlugin.version = parseFloat(_x.description.replace(/^[^0-9]*/, ""), 10);
	// flash was detected, but doesn't appear correctly installed
	} else {
		flashPlugin.detected = true;
		flashPlugin.installed = false;
	}

	// if the version of Flash is v2
	if( navigator.plugins["Shockwave Flash 2.0"] ){
		flashPlugin.htmlTag = "embed";
		flashPlugin.detected = true;
		flashPlugin.installed = true;
		flashPlugin.version = 2;
	}
// almost useless code to see if Flash is installed
} else if( navigator.mimeTypes && navigator.mimeTypes.length ){
	_x = navigator.mimeTypes['application/x-shockwave-flash'];
	flashPlugin.installed = (!!_x && !!_x.enabledPlugin);
	flashPlugin.htmlTag = "embed";
// if using MSIE, check to see what version of Flash is installed
} else {
	document.write("<scr" + "ipt language=\"VBScript\">\n");
	document.write("on error resume next\n");
	document.write("For i = 2 to 10\n");
	document.write("If Not(IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" & i))) Then\n");
	document.write("Else\n");
	document.write("flashPlugin.detected = True\n");
	document.write("flashPlugin.installed = True\n");
	document.write("flashPlugin.version = i\n");
	document.write("flashPlugin.htmlTag = \"object\"\n");
	document.write("End If\n");
	document.write("Next\n");
	document.write("</script>\n");
}
