// ----------------------------------------------------------------------------
// 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) || window.location.search.indexOf (bypassQuery) != -1) {
		return true;
	} else {
		window.location.href = redirectLocation;
		return false;
	}
}
	
// ----------------------------------------------------------------------------
// FlashTag Class

FlashTag = function (version, movie, width, height) {// Contructor
	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.addVariable = function (name, value) {// Returns Void
	this.vars[name] = value;
}
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());
}

// ----------------------------------------------------------------------------
// Usage
/*

if (FlashRedirect.hasVersion (7, 'noflash.html', 'nosniff=true')) {
	var tag = new FlashTag (7, 'main.swf', '400', '300');
	tag.writeHTML();
}

*/
// ----------------------------------------------------------------------------
