 /*

 initial concept by by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 i've updated it to be more reliant upon css, and have added some cross-movie functions

 added support for major and minor flash version requirements
 removed bypass text in lieu of just altTxt
 modifed constructor to include the bare necessities
 id property automatically created from the swf url string
 fixed the ie pc object tag to include the codebase tag
 creates div's on the fly if the div does not exist

 */

FlashObject = function(swf, id, major, minor, width, height, doDetect) {
	this.swf = swf;
	this.id = id ? id : swf.substring(swf.lastIndexOf("/")+1, swf.indexOf("."));
	this.width = width ? width : "100%";
	this.height = height ? height : "100%";
	this.version = major ? major : 6;
	this.minorVersion = minor ? minor : 79;
	this.redirect = "";
	this.params = new Object();
	this.variables = new Object();
	this.doDetect = doDetect ? doDetect : (getQueryParamValue('detectflash') ? getQueryParamValue('detectflash') : true);
	this.uniqueName = "flash_object_instance_" + (++FlashObject._uniqueid_);
	this.addVariable("document_location_href", document.location.href);
	this.addVariable("flash_object_name", this.uniqueName);
	FlashObject[this.uniqueName] = this;
}
FlashObject._uniqueid_ = -1;
FlashObject.prototype.setRedirect = function(url) {
	this.redirect = url;
}
FlashObject.prototype.setElementId = function(elementId) {
	this.eid = elementId
}
FlashObject.prototype.addParam = function(name, value) {
	this.params[name] = value;
}
FlashObject.prototype.getParams = function() {
	return this.params;
}
FlashObject.prototype.getParam = function(name) {
	return this.params[name];
}
FlashObject.prototype.addVariable = function(name, value) {
	this.variables[name] = value;
}
FlashObject.prototype.getVariable = function(name) {
	return this.variables[name];
}
FlashObject.prototype.getVariables = function() {
	return this.variables;
}
FlashObject.prototype.getVariablePairs = function() {
	var variablePairs = new Array();
	for (var name in this.getVariables()) variablePairs.push(name + "=" + escape(this.getVariable(name)));
	if (variablePairs.length > 0) return variablePairs.join("&");
	else return null;
}
FlashObject.prototype.getParamTags = function() {
	var paramTags = "";
	for(param in this.getParams()) {
		paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
	}
	return paramTags;
}
FlashObject.prototype.getParamString = function() {
	var paramString = "";
	for(param in this.getParams()) {
		paramString += param + '="' + this.getParam(param) + '" ';
	}
	return paramString;
}
FlashObject.prototype.getHTML = function() {
	var flashVersionArray = getFlashVersionArray();
	var flashHTML = "";
	if (flashVersionArray[0]==this.version&&flashVersionArray[2]<this.minorVersion) {
		flashHTML += '<div class="minorversion"><a href="http://macromedia.com/go/getflashplayer" target="_blank">You do not have the most recent flash player installed.  You may experience a loss of functionality.  Click here to upgrade!</a></div>';
	}
	if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
		flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.version + ',0,' + this.minorVersion + ',0" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '">';
		flashHTML += '<param name="movie" value="' + this.swf + '" />';
		flashHTML += this.getParamTags();
		if (this.getVariablePairs() != null) flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
		flashHTML += '</object>';
	}
	else { // Everyone else
		flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" ';
		flashHTML += this.getParamString();
		if (this.getVariablePairs() != null) flashHTML += 'flashVars="' + this.getVariablePairs() + '"';
		flashHTML += '></embed>';
	}
	flashHTML += "";
	return flashHTML;
}
FlashObject.prototype.write = function(elementId) {
	var flashVersionArray = getFlashVersionArray();
	if (elementId) {
		if (document.getElementById(elementId)==null) document.write('<div id="' + elementId + '"></div>');
		this.setElementId(elementId);
	}
	if(flashVersionArray[0]>=this.version || this.doDetect=='false') document.getElementById(elementId).innerHTML = this.getHTML();
	else if (this.redirect != "") document.location.replace(this.redirect);
}
FlashObject.prototype.setSize = function(width, height) {
	var layer = document.getElementById(this.eid);
	if (width) layer.style.width = width;
	if (height) layer.style.height = height;
}
FlashObject.prototype.resizeWithOption = function(option, width, height, widthparam, heightparam) {

if (height>3000) return;

	/*
	(0 or undefied or null) "exact" - passes the width and height directly to the setSize method
	(1) "limited" - passes the width and height enabling maximums
	(2) "fit to page" - maintains the size of the browser's page dimensions
	(3) "fit to content and page" - expands to fit the maximum height of the full content or the page, whichever is greater
	(4) "center vertical" - centers the div vertically
	*/
	if (option=="1") {
		if (widthparam) width = Math.min(width, widthparam);
		if (heightparam) height = Math.min(height, heightparam);
		this.setSize(width, height);
	} else if (option=="2") {
		var dimensions = getBrowserDimensions();
		if (widthparam) width = dimensions[0];
		if (heightparam) height = dimensions[1];
		this.setSize(width, height);
	} else if (option=="3") {
		var dimensions = getBrowserDimensions();
		//if (widthparam) width = Math.max(width, dimensions[0]);
		if (heightparam) height = Math.max(height, dimensions[1]);
		this.setSize(width, height);
	} else if (option=="4") {
		var layer = document.getElementById(this.eid);
		var dimensions = getBrowserDimensions();
		if (height<dimensions[1]) {
			layer.style.top = "50%";
			layer.style.marginTop = Math.round(height/2)*-1;
		} else {
			layer.style.top = "auto";
			layer.style.marginTop = "auto";
		}
		this.setSize(width, height);
		var layer = document.getElementById("shadow");
		var dimensions = getBrowserDimensions();
		if ((parseInt(height, 10)+50)<dimensions[1]) {
			layer.style.top = "50%";
			layer.style.marginTop = Math.round((parseInt(height, 10)+50)/2)*-1;
			layer.style.height = parseInt(height, 10)+50;
		} else {
			layer.style.top = "auto";
			layer.style.marginTop = "auto";
			layer.style.height = height;
		}
	} else {
		this.setSize(width, height);
	}
}

/* ---- get an array of the browser dimensions ---- */
function getBrowserDimensions () {
	var x,y;
	// all except Explorer
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
	// Explorer 6 Strict Mode
	} else if (document.documentElement &&document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	// other Explorers
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return ([x, y]);
}

/* ---- return an array of the flash version ---- */
function getFlashVersionArray() {
	var fva = new Array(0, 0, 0, 0);
	if (navigator.plugins && navigator.mimeTypes.length) {
		var nfp = navigator.plugins["Shockwave Flash"];
		if (nfp && nfp.description) {
			var va = nfp.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
			for (var i=0; i<va.length; ++i) if (parseInt(va[i])) fva[i] = parseInt(va[i]);
		}
	} else if (window.ActiveXObject) {
		try {
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			var va = axo.GetVariable("$version").split(" ")[1].split(",");
			for (var i=0; i<va.length; ++i) if (parseInt(va[i])) fva[i] = parseInt(va[i]);
		} catch (e) {}
	}
	return fva;
}

/* ---- get value of query string param ---- */
function getQueryParamValue(param) {
	var q = document.location.search || document.location.hash;
	if(q){
		var startIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
		if (q.length > 1 && startIndex > -1) {
			return q.substring(q.indexOf("=", startIndex)+1, endIndex);
		}
	}
	return "";
}

/* ---- add the array.push protoype for i.e.5 ---- */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}