/**
 * @author Peter Pokojny <pokojny at creeo dot net>
 */ 

/*
function displaydebug(i, text) {
	bla = document.getElementById('debug1');
	//alert(bla);
	//bla.innerHTML = text;
	bla.value = text;
}/**/

function SwfAllUNeed() {
	this.noscriptcontentid = "NoScriptForFlashNo1";
	
	this.requiredMajorVersion = 8;
	this.requiredMinorVersion = 0;
	this.requiredRevision = 0;
		
	this.isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	this.isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	this.isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	
	this.JSGetSwfVer = function(i) {
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			if (navigator.plugins["ShockwaveFlash 2.0"] || navigator.plugins["Shockwave Flash"]) {
				var swVer2 = navigator.plugins["ShockwaveFlash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
				descArray = flashDescription.split(" ");
				tempArrayMajor = descArray[2].split(".");
				versionMajor = tempArrayMajor[0];
				versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" ) {
					tempArrayMinor = descArray[3].split("r");
				} else {
					tempArrayMinor = descArray[4].split("r");
				}
				versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			} else {
				flashVer = -1;
			}
		} else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) {
			flashVer = 4;
		} else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) {
			flashVer = 3;
		} else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) {
			flashVer = 2;
		} else {
			flashVer = -1;
		}
		return flashVer;
	}
	
	this.DetectFlashVer = function(reqMajorVer, reqMinorVer, reqRevision) {
		reqVer = parseFloat(reqMajorVer + "." + reqRevision);
		for (i = 25; i > 0; i--) {
			if (this.isIE && this.isWin && !(this.isOpera)) {
				var versionStr = VBGetSwfVer(i);
			} else {
				var versionStr = this.JSGetSwfVer(i);
				versionStr = ''+versionStr;
			}
			if (versionStr != 0) {
				if (this.isIE && this.isWin && !(this.isOpera)) {
					var tempArray = versionStr.split(" ");
					var tempString = tempArray[1];
					var versionArray = tempString.split(",");
				} else {
					var versionArray = versionStr.split(".");
				}
				versionMajor = versionArray[0];
				versionMinor = versionArray[1];
				versionRevision = versionArray[2];
				
				versionString = versionMajor + "." + versionRevision;
				versionNum = parseFloat(versionString);
				
				if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
					return true;
				} else {
					return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
				}
			}
		}
		return (reqVer ? false : 0.0);
	}
	
	this.hasProductInstall = this.DetectFlashVer(6, 0, 65);
	this.hasRequestedVersion = this.DetectFlashVer(this.requiredMajorVersion, this.requiredMinorVersion, this.requiredRevision);
	this.MMredirectURL = window.location;
	
	this.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	this.width = 0;
	this.height = 0;
	this.params = new Array();
	this.quality = 'high';
	this.swfurl = '';
	this.bgcolor = "#ffffff";
	
	this.hideAlternateContent = function() {
		var alternateContent = document.getElementById(this.noscriptcontentid);
		if (alternateContent)
			alternateContent.style.display = 'none';
	}
	
	this.addParam = function(key, value) {
		this.params.push(new Array(key, value));
	}
	
	this.paramsString = function() {
		var res = '';
		for (i in this.params) {
			res = res + '&amp;' + this.params[i][0] + '=' + this.params[i][1];
		}
		return res;
	}
	
	this.placeFlash = function() {
		if (this.hasProductInstall && !this.hasRequestedVersion) {
			document.title = document.title.slice(0, 47) + " - Flash Player Installation";
			var MMdoctitle = document.title;
			
			var productInstallOETags = '<object classid="'+this.classid+'"'
				+ ' width="'+this.width+'" height="'+this.height+'"'
				+ ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
				+ '<param name="movie" value="'+this.swfurl+'?MMredirectURL='+this.MMredirectURL+'&amp;MMplayerType=ActiveX&amp;MMdoctitle='
				+ MMdoctitle + '&amp;version=false" />'
				+ '<param name="quality" value="'+this.quality+'" /><param name="bgcolor" value="'+this.bgcolor+'" />'
				+ '<embed src="'+this.swfurl+'?MMredirectURL='+this.MMredirectURL+'&amp;MMplayerType=PlugIn&amp;version=false"'
				+ ' quality="'+this.quality+'" bgcolor="'+this.bgcolor+'"'
				+ ' width="'+this.width+'" height="'+this.height+'" name="versiondetection" aligh="middle" play="true" loop="false"'
				+ ' quality="'+this.quality+'"'
				+ ' allowSriptAccess="sameDomain"'
				+ ' type="application/x-shockwave-flash"'
				+ ' pluginspage="http://www.macromedia.com/go/getflashplayer">'
				+ '</embed></object>';
			document.write(productInstallOETags);
			this.hideAlternateContent();
		} else if (this.hasRequestedVersion) {
			var oeTags = '<object classid="'+this.classid+'"'
				+ ' width="'+this.width+'" height="'+this.height+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
				+ '<param name="movie" value="'+this.swfurl+'?version=true' + this.paramsString() + '" />'
				+ '<param name="quality" value="'+this.quality+'" />'
				+ '<param name="bgcolor" value="'+this.bgcolor+'" />'
				+ '<embed src="'+this.swfurl+'?version=true'
				+ this.paramsString() + '"'
				+ ' quality="'+this.quality+'" bgcolor="'+this.bgcolor+'" width="'+this.width+'" height="'+this.height+'"'
				+ ' name="versiondetection" aligh="middle" play="true" loop="false" quality="'+this.quality+'" allowScriptAccess="sameDomain"'
				+ ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
			document.write(oeTags);
			//displaydebug(1, oeTags);
			this.hideAlternateContent();
		} else {
			// alternate content stays visible
		}
	}
}
