/*
*
*	myFlash = new gfx("src.file", "srcid", "width", "height", flashversion, "backgroundcolor");
*	myFlash.addParam("wmode", "transparent");					// optional
*	myFlash.write();
*
*/

gfx = function(src, w, h, idee, bgcol) {
	this.s = src;
	this.w = w;
	this.h = h;
	this.i = idee;
	this.n = idee;
	this.align = "middle";
	this.b = bgcol;
	this.v = 8;

	this.params = new Object();
	this.htmlsrc = "";
}

gfx.prototype.addParam = function(name, value) {
	this.params[name] = value;
}

gfx.prototype.getParams = function() {
	return this.params;
}

gfx.prototype.getParam = function(name) {
	return this.params[name];
}

gfx.prototype.getParamTags = function() {
	var paramTags = "";
	for (var param in this.getParams()) {
		paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
	}
	if (paramTags == "") {
		paramTags = null;
	}
	return paramTags;
}

gfx.prototype.getHTML = function() {
	if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) {
		this.htmlsrc += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + this.w + '" height="' + this.h + '" id="' + this.i + '"  name="' + this.i + '" align="' + this.align + '">';
		this.htmlsrc += '<param name="movie" value="' + this.s +'?c='+new Date().getTime() + '" />';
		this.htmlsrc += '<param name="bgcolor" value="' + this.b + '" />';
		if (this.getParamTags() != null) {
			this.htmlsrc += this.getParamTags();
		}
		this.htmlsrc += '</object>';
	}
	else {
		this.htmlsrc += '<embed src="' + this.s + '" quality="auto" bgcolor="' + this.b + '" width="' + this.w + '" height="' + this.h + '" name="' + this.i + '" id="' + this.i + '" align="' + this.align + '" allowScriptAccess="sameDomain"';
		for (var param in this.getParams()) {
			this.htmlsrc += ' ' + param + '="' + this.getParam(param) + '"';
		}
		this.htmlsrc += ' type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer"></embed>';
	}
	return this.htmlsrc;
}

function checkUnit(str) {
	if (str.indexOf("%") == "-1") {
		str += "px";
	}
	return str;
}

function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if (x.description) {
				var y = x.description;
//				flashversion = y.charAt(y.indexOf('.')-1);
				flashversion = y.substring((y.indexOf(' ', y.indexOf('Flash')) + 1), y.indexOf('.'));
			}
		}
	}
	else {
		result = false;
		for(var i = 15; i >= 3 && result != true; i--){
			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
			flashversion = i;
		}
	}
	return flashversion;
}


function detectFlash(ver) {
	if (getFlashVersion() >= ver) {
		return true;
	}
	else {
		return false;
	}
}

gfx.prototype.write = function() {
	if(detectFlash(this.v)) {
		document.write(this.getHTML());
	}
	else {
		this.w = checkUnit(this.w);
		this.h = checkUnit(this.h);
		this.htmlsrc += '<a href="https://www.macromedia.com/go/getflashplayer">最新の Shockwave Flash プラグインをインストールしてご覧ください</a>';
		document.write(this.htmlsrc);
	}
}