/* =========================================================================
NAMES: FlashSniffer & FlashObject

Last Updated  : 1/14/2006
COMMENT: Checks for Flash player and vers.no. Places Flash objects onto pages.

VERSION: 1.0.0.19
============================================================================ */
// create instance at the beginning of html pages.
FlashSniffer = function () {
	this._init();	
}
// private
FlashSniffer.prototype._init = function () {
	this._aMovies = [];
	//this._bInstalled = false;
	this._nVersion = 0;
	this._nMinor = 0;
	this._nBuild = 0;
	this._bEmbedded = (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) ? true : false; // checks NS plugin architecture
	this._bIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; // true if we're on IE
	this._bWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; // true if we're on windows
	
	if (this._bEmbedded) {
		var player = navigator.plugins["Shockwave Flash"];
		if(player && player.description) {
			this._setVersion(player.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}
	else if(window.ActiveXObject) {
		try {
			this._setVersion(new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").split(" ")[1].split(","));
		} catch (e) {}
	}
}

// private method. called from _init
FlashSniffer.prototype._setVersion = function (aVers) {
	this._nVersion = parseInt(aVers[0]) || 0;
	this._nMinor = parseInt(aVers[1]) || 0;
	this._nBuild = parseInt(aVers[2]) || 0;
}

FlashSniffer.prototype.movies = function () {
	return this._aMovies;	
}

FlashSniffer.prototype.hasFlash = function (nVer) {
	return (this._nVersion >= nVer);
}

// place Flash Objects using this class.
FlashObject = function (sSrc,nW,nH,fs,nPlyrVer) {
	this._init(sSrc,nW,nH,fs,nPlyrVer);
}

/**
	sSrc - Path to Flash src file
	nW - Width property
	nH - Height property
	fs - Instance of FlashSniffer
	nPlyrVer - Min player vers. req. to play the movie.
*/
FlashObject.prototype._init = function (sSrc,nW,nH,fs,nPlyrVer) {
	flashCheck.movies[flashCheck.movies.length] = this;
	this._nPos = flashCheck.movies.length;
	this._id = "fo_"+this._nPos;
	this._sSrc = sSrc;
	this._nW = nW;
	this._nH = nH;
	this._nPlyrVer = nPlyrVer;
	this._wmode = "transparent";
	this._aParams = [];
	this._fs = flashCheck;
	// set base parameters specific to site.
	this.addParam("loop","false");
	this.addParam("menu","flash");
	this.addParam("quality","high");
	this.addParam("base",".");
	this.addParam("allowScriptAccess","sameDomain");
}

FlashObject.prototype.placeFlash = function () {
	this.addParam("wmode",this._wmode);
	var sHTML = '<div id="flashdiv_'+this._nPos+'" class="flashobject" style="width:'+this._nW + ((this._nW.toString().indexOf("%") != -1) ? "" : "px") + ';height:'+this._nH+((this._nH.toString().indexOf("%") != -1) ? "" : "px")+';">';
	if (this._fs._bEmbedded) {
        sHTML += '<embed type="application/x-shockwave-flash" pluginspace="'+location.protocol+'//www.macromedia.com/go/getflashplayer" src="'+ this._sSrc +'" width="'+ ((this._nW.toString().indexOf("%") > -1) ? "100%" : this._nW) +'" height="'+ ((this._nH.toString().indexOf("%") > -1) ? "100%" : this._nH) +'" id="'+ this._id + '" name="'+ this._id +'"';
        for(var i=0; i < this._aParams.length; i++) {
			sHTML += ' ' + this._aParams[i].prop + '="' + this._aParams[i].val + '"';
		}
        sHTML += '></embed>';
	} else {
		sHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+location.protocol+'//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ ((this._nW.toString().indexOf("%") > -1) ? "100%" : this._nW) +'" height="'+ ((this._nH.toString().indexOf("%") > -1) ? "100%" : this._nH) +'" id="'+ this._id +'">';
		sHTML += '<param name="movie" value="' + this._sSrc + '" />';
		for(var i=0; i < this._aParams.length; i++) {
			sHTML += '<param name="' + this._aParams[i].prop + '" value="' + this._aParams[i].val + '" />'
		}
		sHTML += '</object>';
	}
	sHTML += "</div>";
	return sHTML;
}

/**
	sAlt - alternate html to write into the page.
*/
FlashObject.prototype.insertInto = function (id,sAlt) {
	document.getElementById(id).innerHTML = (this._fs.hasFlash(this._nPlyrVer)) ? this.placeFlash() : sAlt;
}

FlashObject.prototype.setOpaque = function (b) {
	this._wmode = (b) ? true : false;
}

FlashObject.prototype.addParam = function(name,value) {
	this._aParams[this._aParams.length] = {prop:name,val:value};
}