// $Id: flashwriter.js,v 1.5 2003/11/18 05:48:11 rcarver Exp $
/*	
	FlashWriter 2003 squidfingers.com / fivesevensix.com
*/
FlashWriter = function(version, swf, width, height, hideMenu) {
	this.version = version;
	this.swf = swf;
	this.width = width;
	this.height = height;
	this.hideMenu = hideMenu;
	this.vars = {};
	this.props = {};
}
FlashWriter.prototype.addProperty = function(name, value) {
	this.props[name] = value;
}
FlashWriter.prototype.addVar = function(name, value) {
	this.vars[name] = value;
}
FlashWriter.prototype.write = function(altId, altContent) {
	if (!FlashWriter.isRedirecting) document.write(this.getContent(altId, altContent));
}
FlashWriter.prototype.getContent = function(altId, altContent) {
	if (FlashWriter.hasFlashVersion(this.version)) {
		return this.getFlashTags();
	} else {
		var altIdContent = null;
		if (altId != null && document.getElementById && document.getElementById(altId)) {
			altIdContent = document.getElementById(altId).innerHTML.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
		}
		if (altIdContent) {
			return altIdContent;
		} else if (altContent != null) {
			return altContent;
		} else {
			return this.getFlashTags();
		}
	}	
}
FlashWriter.prototype.getFlashTags = function() {
	var flashVars = "";
 	for (var i in this.vars) {
 		flashVars += escape(i) + "=" + escape(this.vars[i]) + "&";
 	}
	var fVars = flashVars.length ? "?"+flashVars : "";
	var tags = '<object';
	tags += ' width="'+this.width+'"';
	tags += ' height="'+this.height+'"';
	tags += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	tags += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+',0,0,0">';
	tags += '<param name="movie" value="'+this.swf+fVars+'">';
	if (flashVars.length) tags += '<param name="FlashVars" value="'+flashVars+'">'
	if (this.hideMenu) tags += '<param name="menu" value="false">';
	for (var i in this.props) {
		tags += '<param name="'+i+'" value="'+this.props[i]+'">';
	}	
	tags += '<embed src="'+this.swf+fVars+'"';
	tags += ' width="'+this.width+'"';
	tags += ' height="'+this.height+'"';
	if (flashVars.length) tags += ' FlashVars="'+flashVars+'"';
	if (this.hideMenu) tags += ' menu="false"';
	for (var i in this.props) {
		tags += ' '+i+'="'+this.props[i]+'"';
	}
	tags += ' type="application/x-shockwave-flash"';
	tags += ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
	tags += '<\/embed>';	
	tags += '<\/object>';
	return tags;
}


// Static Class Methods	------------------------------------------------------

FlashWriter.redirect = function(version, noFlashPage, assumeFlash) {
	// do not redirect if previous page is the noFlashPage
	if (document.referrer.indexOf(noFlashPage) == -1 && !this.hasVersionAssumption(version, assumeFlash)) {
		this.isRedirecting = true;
		window.location.replace(noFlashPage);
	}
}
FlashWriter.hasVersionAssumption = function(version, assumeFlash) {
	var hasVersion = this.hasFlashVersion(version);
	// if the version cannot be determined and assumeFlash is not false, then assume they have it
	return (hasVersion == null && (assumeFlash != false)) ? true : hasVersion;
}
FlashWriter.hasFlashVersion = function(requiredVersion) {
	// hasFlashVersion returns:
	// true  - has the correct Flash version or greater
	// false - does not have the correct Flash version
	// null  - cannot be checked for the Flash plug-in
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var version = 0;
		var plugin = navigator.plugins["Shockwave Flash"];
		if (typeof plugin == "object") {
			var description = plugin.description;
			version = parseInt(description.charAt(description.indexOf(".")-1));
		}
		return (version >= requiredVersion);
	} else if (navigator.appVersion.indexOf("Mac") == -1 && window.execScript) {
		FlashWriter.tmpFlash = false;
		for (var i = requiredVersion; i <= requiredVersion+10 && FlashWriter.tmpFlash != true; i++) {
			execScript('on error resume next: FlashWriter.tmpFlash=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
		}
		var result = FlashWriter.tmpFlash; delete(FlashWriter.tmpFlash);
		return result;
	}
	return null;
}
FlashWriter.isRedirecting = false;
