var flash4Installed = false;

// CLASSES
function Flash(writeVBCheck) {
	//public: (properties)
	this.movie = "";			//required
	this.redirectTo = "";
	this.altImage = "";
	this.altImageSize = true;
	this.width = "";			//required
	this.height = "";			//required
	this.param = new Parameters();
	
	//public: (methods)
	this.load = __Flash__load;

	//private: (properties)
	this.debug = false;
	
	//private: (methods)
	this.writeObject = __Flash__writeObject;
	this.writeImage = __Flash__writeImage;
	this.isFlashInstalled = __Flash__isFlashInstalled;
	this.writeVB = __Flash__writeVB;
	
	//Contructor {
		//if ie, write flash
		var vbScript = true;
		if (writeVBCheck != null) vbScript = writeVBCheck;
		else vbScript = true;
		if (document.all && vbScript)
			this.writeVB();
	//} //end constructor
}

function Parameters() {
	//public: (methods)
	this.add = __Parameters__add;
	this.getName = __Parameters__getName;
	this.getValue = __Parameters__getValue;
	this.getCount = __Parameters__getCount;
	
	//private: (properties)
	this.seperator = "|";
	this.arr = new Array();
}

// CLASS DEFINITIONS
//Flash
function __Flash__load() {
	//check if everything is complete
	if (this.movie!="" && this.width!="" && this.height!="")
		this.writeObject();
	else {
		if (this.debug)
			window.alert("Cannot load movie, properties 'movie' (" + this.movie + "), 'width' (" + this.width + "), and 'height' (" + this.height + ") must be set.");
	}
}
function __Flash__writeObject() {
	if (this.debug) {
		window.alert("Writing flash object...");
	}
	
	if (this.isFlashInstalled()) {
		var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			+ ' WIDTH="' + this.width + '" HEIGHT="' + this.height + '"'
			+ ' CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
			+ ' <PARAM NAME="MOVIE" VALUE="' + this.movie + '">';
	
		//add other parameters
		for (var i=0;i<this.param.getCount();i++) {
			oeTags += ' <param name="' + this.param.getName(i) + '" value="' + this.param.getValue(i) + '">';
		}
	
		oeTags += ' <EMBED SRC="' + this.movie + '"'
		+ ' WIDTH="' + this.width + '" HEIGHT="' + this.height + '"';

		//add other parameters
		for (var i=0;i<this.param.getCount();i++) {
			oeTags += ' ' + this.param.getName(i) + '="' + this.param.getValue(i) + '"';
		}

		oeTags += ' TYPE="application/x-shockwave-flash"'
			+ ' PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
			+ '</EMBED>';

		oeTags += '</OBJECT>';
	
		document.write(oeTags); 	// embed the flash movie
	
		if (this.debug) {
			window.prompt("Wrote flash object: ", oeTags);
		}
	} else {
		if (this.redirectTo != "") {
			window.location = this.redirectTo;
			if (this.debug) {
				window.alert("Flash not installed, redirecting.");
			}
			return;
		} else if (this.altImage!="") {
			this.writeImage();
			if (this.debug) {
				window.alert("Flash not installed, wrote image instead.");
			}
		} else if (this.debug) {
			window.alert("Flash not installed, redirect or alternate image not set.");
		}
	}
}
function __Flash__writeImage() {
	var oImg = '<img src="' + this.altImage + '"';
	if (this.altImageSize) {
		oImg += ' width=' + this.width + ' height=' + this.height;
	}
	oImg += ' border=0 alt="">';
	document.write(oImg);
}
function __Flash__isFlashInstalled() {
	//if ie, check the variable written using VBScript
	if (document.all) return (flash4Installed==null)?false:flash4Installed;
	
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if ( plugin && parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) >= 4 )
		return true;
	else
		return false;
}

function __Flash__writeVB() {
	// check the browser...we're looking for ie/win
	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;		// true if we're on ie
	
	// write vbscript detection if we're not on mac.
	if(isIE){ // don't write vbscript tags on anything but ie win
		if (this.debug)
			window.alert("Writing VB script for IE flash version check");
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');	
		document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
	} else {
		if (this.DEBUG) {
			window.alert("Flash.writeVB(): IE, but not on windows (" + navigator.appVersion + "), VBScript not written.");
		}
	}
}

//Parameters
function __Parameters__add(name, val) {
	this.arr[this.arr.length] = name + this.seperator + val;
}
function __Parameters__getName(idx) {
	if (idx>=0 && idx<this.arr.length) {
		return this.arr[idx].substring(0,this.arr[idx].indexOf(this.seperator));
	}
	return "";
}
function __Parameters__getValue(idx) {
	if (idx>=0 && idx<this.arr.length) {
		return this.arr[idx].substring(this.arr[idx].indexOf(this.seperator)+1, this.arr[idx].length);
	}
	return "";
}
function __Parameters__getCount() {
	return this.arr.length;
}