
//////////////////////////////////
// @author:      Dave Smith
// @description: Javascript embed for flash
//               Based on the Chris Mook code but
//               with an improved interface and
//               support for express install
//////////////////////////////////

var requiredVersion = 8;
var maxVersion = 9;
var actualVersion = 8;
var hasRightVersion = false;
var jsVersion = 1.0;
var sAltContentId="";
	
function fnDetectFlash() {
	if (navigator.plugins) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			var flashVersion = parseInt(flashDescription.substring(16));
			actualVersion=flashVersion;
		}
	}
	if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 4;
	if (actualVersion >= requiredVersion) {
		hasRightVersion = true;                
	}
}

////////////////////////////////
//Flash Variables

var version_value=9;
var allowScriptAccess_value="crossDomain";
var movie_value="menu";
var quality_value="high";
var bgcolor_value="#000000";
var width_value="752";
var height_value="215";
var quality_value="high";
var moviepath_value="/";

////////////////////////////////

var tagEmbed='<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
var tagObject='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=';
var tagParams='';
var tagParamsEmbedTag='';
var tagFlashVars='';

function fnFlashEmbedNewParam(sName,sValue){
	tagParams+='<param name="'+sName+'" value="'+sValue+'" />';
	tagParamsEmbedTag+=sName+'="'+sValue+'" ';
}

function fnFlashEmbedFlashVar(sName,sValue){
	if(tagFlashVars==''){
		tagFlashVars=sName+'='+sValue;
	}else{
		tagFlashVars+='&'+sName+'='+sValue;
	}
}

function fnFlashEmbedWrite(){
	if(hasRightVersion) {
		//Object open
		tagObject+=version_value+',0,0,0" ';
		tagObject+='width="'+width_value+'" ';
		tagObject+='height="'+height_value+'" ';
		tagObject+='id="'+movie_value+'"';
		tagObject+='>';
		var oeTags=tagObject;
		
		//param tags
		oeTags+='<param name="allowScriptAccess" value="'+allowScriptAccess_value+'" />'
		oeTags+='<param name="movie" value="'+moviepath_value+'" />'
		oeTags+='<param name="quality" value="'+quality_value+'" />'
		oeTags+='<param name="bgcolor" value="'+bgcolor_value+'" />'
		if(tagParams!=''){
			oeTags+=tagParams;
		}
		if(tagFlashVars!=''){
			oeTags+='<param name="FlashVars" value="'+tagFlashVars+'" />';
		}
		
		//Embed tag
		tagEmbed+='src="'+moviepath_value+'" ';
		tagEmbed+='quality="'+quality_value+'" ';
		tagEmbed+='bgcolor="'+bgcolor_value+'" ';
		tagEmbed+='width="'+width_value+'" ';
		tagEmbed+='height="'+height_value+'" ';
		tagEmbed+='id="'+movie_value+'" ';
		tagEmbed+='name="'+movie_value+'" ';
		tagEmbed+='allowScriptAccess="'+allowScriptAccess_value+'" ';
		if(tagFlashVars!=''){
			tagEmbed+='FlashVars="'+tagFlashVars+'" ';
		}
		if(tagParamsEmbedTag!=''){
			tagEmbed+=tagParamsEmbedTag;
		}
		tagEmbed+='/>';
		oeTags+=tagEmbed;
		//Object close
		oeTags+='</object>';
		document.write(oeTags);
	}else{
		//var oeTags=document.getElementById(sAltContentId).innerHTML;
		var oeTags=sAltContentId;
		document.write(oeTags);
	}
}

function fnFlashEmbed(sName,sPath,nVersion,sBgColor,sWidth,sHeight,sAltContent)
{
	///Basic vars
	movie_value=sName;
	version_value=nVersion;
	bgcolor_value=sBgColor;
	width_value=sWidth;
	height_value=sHeight;
	moviepath_value=sPath;
	
	sAltContentId=sAltContent;
	
	//detection
	requiredVersion = version_value;
	maxVersion = version_value;
	
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;  
	var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; 
	jsVersion = 1.1;
	if(isIE && isWin){
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		for(i=2;i<=version_value;i++){
			document.write('oX=false \n');
			document.write('oX=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'")) \n');
			document.write('if oX<>false then actualVersion='+i+' \n');
		}
		document.write('<\/SCR' + 'IPT\> \n');
	}
	
	fnDetectFlash();
	
	
	//express install
	
	
}

fnFlashEmbed.prototype.addParam=fnFlashEmbedNewParam;
fnFlashEmbed.prototype.addFlashVar=fnFlashEmbedFlashVar;
fnFlashEmbed.prototype.embed=fnFlashEmbedWrite;


