//this script will test up to the following version.
flash_versions = 20;

//initialize variables and arrays
var flash_sniffer = new Object();
flash_sniffer.installed = false;
flash_sniffer.version='0.0';

//iterate through Netscape-compatible plug-ins first.
if(navigator.plugins && navigator.plugins.length){
	for (x=0; x<navigator.plugins.length; x++){
		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1){
			flash_sniffer.version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
			flash_sniffer.installed = true;
			break;
		}
	}
}

//iterate through ActiveX-style plug-ins afterwords
else if(window.ActiveXObject){
	for(x=2; x<=flash_versions; x++){
		try{
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash){
				flash_sniffer.installed = true;
				flash_sniffer.version = x + '.0';
			}
		}
		catch(e){}
	}
}

//create sniffing variables in the following style: flash.installed_version[x]
flash_sniffer.installed_version = Array();

for(i = 4; i <= flash_versions; i++){
	eval("flash_sniffer.installed_version[" + i + "] = (flash_sniffer.installed && parseInt(flash_sniffer.version) >= " + i + ") ? true : false;");
}

function flash_object(){
	this.height;
	this.width;
	this.container;
	this.flash_version;
	this.flash_src;
	this.flash_paramaters;
	this.alternative_image;
	this.alternative_url;
	this.alternative_target;
	this.alternative_alt_text;
	this.render_flash = render_flash;
}

function debug_me(debug_string){
	alert('Debug:\n--------\n' + debug_string);
}

function render_flash(){
	var content = 'this.height: ' + this.height + '\n';
	content += 'this.width: ' + this.width + '\n';
	content += 'this.container: ' + this.container + '\n';
	content += 'this.flash_required_version: ' + this.flash_required_version + '\n';
	content += 'this.flash_src: ' + this.flash_src + '\n';
	content += 'this.flash_paramaters: ' + this.flash_paramaters + '\n';
	content += 'this.alternative_image: ' + this.alternative_image + '\n';
	content += 'this.alternative_url: ' + this.alternative_url + '\n';
	content += 'this.alternative_target: ' + this.alternative_target + '\n';
	content += 'this.alternative_alt_text: ' + this.alternative_alt_text + '\n';

	if(flash_js_debug){debug_me(content);}
	
	var embed_string = '';
	var url_supplied = (this.alternative_url.length > 0) ? true : false;
	var target_supplied = (this.alternative_target.length > 0) ? true : false;
					
	if((flash_sniffer.installed_version[this.flash_required_version]) && ((typeof(this.flash_src) != 'undefined') && (this.flash_src != null) && (this.flash_src != 'null') && (this.flash_src != ''))){
		embed_string += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.flash_required_version + ',0,0,0" width="' + this.width + '%" height="' + this.height + '%" id="" align="middle" viewastext>';
		embed_string += '	<param name="allowScriptAccess" value="sameDomain" />';
		embed_string += '	<param name="movie" value="' + this.flash_src + '?' + this.flash_paramaters + '" />';
		embed_string += '	<param name="quality" value="high" />';
		//embed_string += '	<param name="scale" value="noscale" />';
		embed_string += '	<param name="salign" value="t" />';
		embed_string += '		<embed src="' + this.flash_src + '?' + this.flash_paramaters + '" scale="noscale" salign="t" quality="high" width="' + this.width + '%" height="' + this.height + '%" name="" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		embed_string += '</object>';
	}
	else{
		if((typeof(this.alternative_image) != 'undefined') && (this.alternative_image != null) && (this.alternative_image != 'null') && (this.alternative_image != '')){
			//check for alternative image href
			if((typeof(this.alternative_url) != 'undefined') && (this.alternative_url != null) && (this.alternative_url != 'null') && (this.alternative_url != '')){
				embed_string += '<a href="' + this.alternative_url + '"';
				
				//check for alternative image target
				if((typeof(this.alternative_target) != 'undefined') && (this.alternative_target != null) && (this.alternative_target != 'null') && (this.alternative_target != '')){
					embed_string += ' target="' + this.alternative_target + '"';
				}
				
				//check for alternative image alt text
				if((typeof(this.alternative_alt_text) != 'undefined') && (this.alternative_alt_text != null) && (this.alternative_alt_text != 'null') && (this.alternative_alt_text != '')){
					embed_string += ' title="' + this.alternative_alt_text + '"';
				}				
				
				embed_string += '>';			
			}
			
			embed_string += '<img src="' + this.alternative_image + '" height="' + this.height + '" width="' + this.width + '"';
			
			if(url_supplied || target_supplied){
				embed_string += ' border="0"></a>';
			}
			else{
				embed_string += '>';
			}
		}
		else{
			//if no alternative image has been supplied, display the following message within the flash container div
			embed_string += '<div>Flash is required in order to view this content</div>'
		}
	}
	//write out content, whichever scenaio the sniffer script has identified	
	document.getElementById(this.container).innerHTML = embed_string;
	
	if(flash_js_debug){debug_me(embed_string);}
}