// ---------------------------------------------------------------------------
// Usage
/*

# Example 1

if (FlashRedirect.hasVersion (8, 'noflash.html', 'nosniff=true')) {
	var tag = new FlashTag (8, 'main.swf', '400', '300');
	tag.addProperty ('bgcolor', '#ffffff');
	tag.writeHtml();
}

# Example 2

if (Flash.hasVersion (8)) {
	var tag = new FlashTag (8, 'main.swf', '400', '300');
	tag.writeHtml();
} else {
	document.write ('Flash 8 is not installed.');
}

# Example 3

if (Flash.hasVersion(8)) new FlashTag(8,'main.swf','400','300').p('bgcolor','#ffffff').w();

*/
// ---------------------------------------------------------------------------
// Flash Object

var Flash = new Object();
Flash.hasVersion = function (versionRequired) {// Returns Boolean
	if (navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'] && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
		var description = navigator.plugins['Shockwave Flash'].description;
		var version = parseInt (description.charAt (description.indexOf ('.') - 1));
		return version >= versionRequired;
	}
	if (navigator.appVersion.indexOf ('Windows') != -1 && window.execScript) {
		this.hasVersionResult = null;
		execScript ('on error resume next: Flash.hasVersionResult=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + versionRequired + '"))','VBScript');
		return this.hasVersionResult;
	}
	return false;
}

// ---------------------------------------------------------------------------
// FlashRedirect Object

var FlashRedirect = new Object();
FlashRedirect.hasVersion = function (versionRequired, redirectLocation, bypassQuery) {// Returns Boolean
	if (Flash.hasVersion (versionRequired)) {
		return true;
	} else if (bypassQuery != null && window.location.search.indexOf (bypassQuery) != -1) {
		return true;
	} else {
		window.location.href = redirectLocation;
		return false;
	}
}

// ---------------------------------------------------------------------------
// FlashTag Class

FlashTag = function (version, movie, width, height) {// Constructor
	this.version = version;
	this.movie = movie;
	this.width = width;
	this.height = height;
	this.props = new Array();
	this.vars = new Array();
}
FlashTag.prototype.addProperty = function (name, value) {// Returns Void
	this.props[name] = value;
}
FlashTag.prototype.addProperties = function (obj) {// Returns Void
	for (var i in obj) {
		this.addProperty (i, obj[i]);
	}
}
FlashTag.prototype.addVariable = function (name, value) {// Returns Void
	this.vars[name] = value;
}
FlashTag.prototype.addVariables = function (obj) {// Returns Void
	for (var i in obj) {
		this.addVariable (i, obj[i]);
	}
}
FlashTag.prototype.getHtml = function(){// Returns String
	var fvars = '';
	for (var i in this.vars) {
		fvars += i + '=' + escape (this.vars[i]) + '&';
	}
	this.addProperty ('FlashVars', fvars);
	var tag = '<object';
	tag += ' width="' + this.width + '"';
	tag += ' height="' + this.height + '"';
	tag += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	tag += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.version + ',0,0,0">';
	tag += '<param name="movie" value="' + this.movie + "?" + fvars + '" />';
	for (var i in this.props) {
		tag += '<param name="' + i + '" value="' + this.props[i] + '" />';
	}
	tag += '<embed src="' + this.movie + "?" + fvars + '"';
	tag += ' type="application/x-shockwave-flash"';
	tag += ' pluginspage="http://www.macromedia.com/go/getflashplayer"';
	tag += ' width="' + this.width + '"';
	tag += ' height="' + this.height + '"';
	for (var i in this.props) {
		tag += ' ' + i + '="' + this.props[i] + '"';
	}
	tag += '><\/embed>';
	tag += '<\/object>';
	return tag;
}
FlashTag.prototype.writeHtml = function(){// Returns Void
	document.write (this.getHtml());
}

// chainable wrappers

FlashTag.prototype.p = function (name, value) {// Returns FlashTag
	this.addProperty (name, value);
	return this;
}
FlashTag.prototype.v = function (name, value) {// Returns FlashTag
	this.addVariable (name, value);
	return this;
}
FlashTag.prototype.w = function(){// Returns FlashTag
	this.writeHtml();
	return this;
}

// ---------------------------------------------------------------------------

