var id;
var timestamp;
var loadSwf;
var task;

var to_define = false;
if(typeof loadSwf == 'undefined') {
	if(DetectFlashVer(9, 0, 0)) {
		to_define = true;
	} else {
		loadSwf = function() {
			document.write('Please install Flash Player 9.0 or later.');
		}
	}
}

if(to_define) {
	id = 0;
	timestamp = (new Date()).getTime();
	task = { };
	
	String.prototype.htmlspecialchars = function () {
		var ch = this.replace(/&/g,"&amp;");
		ch = ch.replace(/"/g,"&quot;");
		ch = ch.replace(/'/g,"&#039;");
		ch = ch.replace(/</g,"&lt;");
		ch = ch.replace(/>/g,"&gt;");
		return ch;
	}
	
	showMessage = function(str, mode) {
	//	document.getElementById('console').innerHTML += str.htmlspecialchars() + "<br/>\n";
	//	document.getElementById('console').innerHTML = str.htmlspecialchars() + "<br/>\n";
	};
	
	loadSwf = function(swf, dat, style, width, height) {;
		id++;
		if(!style) {
			style = "style.xml";
		}
		if(!width) {
			width = 300;
		}
		if(!height) {
			height = 300;
		}
		var conf_tmp = [
			"src", swf + "?" + timestamp,
			"name", "Grapher",
			"id", "Grapher" + id,
			"width", width + "px",
			"height", height + "px",
			"align", "middle",
			"quality", "high",
			"wmode", "transparent",
		//	"bgcolor", "green",		... not effected.
		//	"allowScriptAccess","sameDomain",
			"allowScriptAccess","always",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
		];
		conf_tmp.push("flashVars");
		conf_tmp.push("data="+escape(dat)+"&style="+escape(style)+"&hash="+timestamp);
		return getFlashTag.apply(null, conf_tmp);
	}
	
	var saved = window.onload;
	window.onload = function () {
		for(var i = 2 ; i <= id ; i++) {
			document.getElementById('grapher_area_'+i).innerHTML = task[i];
		}
		saved && saved();
	}
}

{
	var ss = document.getElementsByTagName('script');
	var src = ss[ss.length-1].src;
	var param = src.substring(src.indexOf('#') + 1);
	var tag = loadSwf.apply(null, param.split(","));
	if(id == 1) {
		document.write(tag);
	} else {
		document.write('<span id="grapher_area_'+id+'">&nbsp;</span>');
		task[id] = tag;
	}
}
