//
// flash script satay.js
// inspired by swfobject (http://blog.com/swfobject)
// basics rewritten by Chris Ovenden from scratch 
// with 2 new features:
// uses flash satay method for flash embedding
// (http://www.alistapart.com/articles/flashsatay/);
// alt content remains inside object tag when it loads
//
function satay(url, id, width, height, version, bgColour) {
	this.query = "?";
	this.swf = url;
	this.reqVersion = new PlayerVersion(version.toString().split("."));
	this.html1 = '<object type="application/x-shockwave-flash" data="'; this.html2 = '" id="' + id + '" width="' + width + '" height="' + height + '">';
	this.addParam('bgcolor=', bgColour);
	
}	

satay.prototype.addParam = function(param, value) {
	this.html2 += '<param name="' + param + '" value="' + value + '" />';
}

satay.prototype.addQueryParam = function(param, value) {
	this.query += param + "=" + value + "&amp;";
}

satay.prototype.write = function(target) {
	var t = document.getElementById(target);
	if (!t) return false; 
	var browserVersion = getPlayerVersion();
	//alert(browserVersion.versionIsValid(this.reqVersion));
	if (!browserVersion.versionIsValid(this.reqVersion)) return false;
	
	this.addParam('movie', this.swf+this.query);
	//alert(this.html1 + this.swf + this.query + this.html2);
	t.innerHTML = this.html1 + this.swf + this.query + this.html2 + t.innerHTML + "</object>";
	return true;
}

//shamelessly lifted from SWFobject source code:
function PlayerVersion (arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
getPlayerVersion = function(){
	var pv = new PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			pv = new PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				pv = new PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // throws if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (pv.major == 6) {
					return pv;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			pv = new PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return pv;
}