var absoluteURL = "";
var no_flash = absoluteURL+"badFlash/noFlashPlayer.php";
var low_ver = absoluteURL+"badFlash/getFlashPlayer.php";
 
FlashObject = function(elementId, swf, id, w, h, ver, c, quality, isRequired, redirectURL, altImage, skipURL, dontShowTip, altContent){
	this.element = document.getElementById(elementId);
	this.removeBackgroundImage();
	//if(!dontShowTip) this.changeContent("<span class='"+elementId+"'>In order to see this content you will have to install <a href='http://www.macromedia.com/shockwave/download/triggerpages_mmcom/flash.html' target='_blank'>Flash Player "+ver+"</a>.</span>");
	
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	
	if(swf) this.setAttribute('swf', swf);
	if(id) this.setAttribute('id', id);
	if(w) this.setAttribute('width', w);
	if(h) this.setAttribute('height', h);
	if(ver) this.setAttribute('version', new PlayerVersion(ver.toString().split(".")));
	if(c) this.addParam('bgcolor', c);
	this.addParam('quality', quality ? quality : 'high');
	//this.addParam('menu', 'false');
	if(altImage) this.altImage = altImage;
	this.altContent = altContent
	if(!redirectURL) redirectURL = "";
	var MMplayerType = navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length ? "PlugIn" : "ActiveX";
	var MMdoctitle = document.title;
	
	installedVer = FlashObjectUtil.getPlayerVersion();
	expressInstallReqVer = new PlayerVersion([6,0,65]);
	this.isValidVersion = installedVer.versionIsValid(this.getAttribute('version'));
	this.canExpressInstall = installedVer.versionIsValid(expressInstallReqVer);
 	
	if(isRequired && !this.isValidVersion){
		if(this.canExpressInstall || installedVer.major > 0){
			window.location = low_ver+"?c="+(installedVer.major+'.'+installedVer.minor+'.'+installedVer.rev)+"&n="+ver+(this.canExpressInstall ? "&url="+redirectURL+"&pt="+MMplayerType+"&dt="+MMdoctitle : "");
		} else {
			window.location = no_flash;
		}
	} else if(!this.isValidVersion && skipURL){
		window.location = skipURL
	}
}
FlashObject.prototype.setAttribute = function(name, value){
	this.attributes[name] = value;
}
FlashObject.prototype.getAttribute = function(name){
	return this.attributes[name];
}
FlashObject.prototype.getAttributes = function(){
	return this.attributes;
}
FlashObject.prototype.addParam = function(name, value){
	this.params[name] = value;
}
FlashObject.prototype.getParams = function(){
	return this.params;
}
FlashObject.prototype.getParam = function(name){
	return this.params[name];
}
FlashObject.prototype.addVariable = function(name, value){
	this.variables[name] = value;
}
FlashObject.prototype.getVariable = function(name){
	return this.variables[name];
}
FlashObject.prototype.getVariables = function(){
	return this.variables;
}
FlashObject.prototype.getParamTags = function(){
   var paramTags = ""; var key; var params = this.getParams();
   for(key in params) paramTags += '<param name="'+key+'" value="'+params[key]+'" />';
   return paramTags;
}
FlashObject.prototype.getVariablePairs = function(){
	var variablePairs = new Array();
	var key;
	var variables = this.getVariables();
	for(key in variables){
		variablePairs.push(key+"="+variables[key]);
	}
	return variablePairs;
}
FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if(navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length){ // netscape plugin architecture
        flashHTML += '<embed type="application/x-shockwave-flash" src="'+this.getAttribute('swf')+'" width="'+this.getAttribute('width') +'" height="'+this.getAttribute('height')+'" id="'+this.getAttribute('id')+'" name="'+this.getAttribute('id')+'"';
		var params = this.getParams();
        for(var key in params) flashHTML += ' '+key+'="'+params[key]+'"';
		pairs = this.getVariablePairs().join("&");
        if (pairs.length > 0){ flashHTML += ' flashvars="'+pairs+'"'; }
        flashHTML += '></embed>';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" data="'+this.getAttribute('swf')+'"width="'+this.getAttribute('width')+'" height="'+this.getAttribute('height')+'" id="'+this.getAttribute('id')+'">';
        flashHTML += '<param name="movie" value="'+this.getAttribute('swf')+'" />';
		var tags = this.getParamTags();
        if(tags.length > 0) flashHTML += tags;
		var pairs = this.getVariablePairs().join("&");
        if(pairs.length > 0) flashHTML += '<param name="flashvars" value="'+pairs+'" />';
        flashHTML += '</object>';
    }
    return flashHTML;
}
/*FlashObject.prototype.getAltImage = function(){
	return '<div style="background:url('+this.altImage+') no-repeat;width:100%;height:100%;" ></div>';
}*/
FlashObject.prototype.removeBackgroundImage = function(){
	this.setBackgroundImage("");
}
FlashObject.prototype.setBackgroundImage = function(link, repeat, color){
	if(link != null) this.element.style.backgroundImage = link;
	if(repeat != null) this.element.style.backgroundRepeat = repeat;
	if(color != null) this.element.style.backgroundColor = color;
}
FlashObject.prototype.write = function(){
	if(document.getElementById){
		if(this.isValidVersion){
			this.changeContent(this.getHTML());
		} else if(this.altImage){
			this.changeContent('');
			this.setBackgroundImage(this.altImage);
			//this.element.innerHTML = this.getAltImage();
		} else if(this.altContent){
			this.setBackgroundImage();
			this.changeContent(this.altContent);
		}
	}
}
FlashObject.prototype.changeContent = function(str){
	//alert('changeContent str='+str);
	this.element.innerHTML = str;
}

// FlashObjectUtil
FlashObjectUtil = new Object();
FlashObjectUtil.getPlayerVersion = function(){
	var version = new PlayerVersion(0,0,0);
	if(navigator.plugins && navigator.mimeTypes.length){
		var plugin = navigator.plugins["Shockwave Flash"];
		if(plugin && plugin.description) {
			version = new PlayerVersion(plugin.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	} else if (window.ActiveXObject){
		try {
			var ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = new PlayerVersion(ax.GetVariable("$version").split(" ")[1].split(","));
	   } catch (e) {}
	}
	return version;
}
// PlayerVersion
PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) || 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major){
		return false
	} else if(this.major == fv.major){
		if(this.minor < fv.minor){
			return false
		} else if(this.minor == fv.minor){
			if(this.rev < fv.rev){
				return false
			}
		}
	}	
	return true;
}

// add Array.push if needed (ie5)
if (Array.prototype.push == null){
	Array.prototype.push = function(item){
		this[this.length] = item;
		return this.length;
	}
}
