﻿ //****************************************************************************
// Author Scile
// Site www.scile.cn
// Version 1.2.0
// Fri May 26 15:55:45 2006
//****************************************************************************
function Flash (width, height){
	this.width = width;
	this.height = height;
	this.params = new Array ();
	
	this.requiredDisplayVision = [8, 0, 0];
	this.requiredInstallVision = [6, 0, 0];
	this.upgradeSWF = "/flashes/upgrade.swf"
	
	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){
		// NS/Opera version >= 3 check for Flash plugin in plugin array
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
				var swVer2 = navigator.plugins["Shockwave Flash 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;
			}
		}
		// MSN/WebTV 2.6 supports Flash 4
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
		// WebTV 2.5 supports Flash 3
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
		// older WebTV supports Flash 2
		else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
		// Can't detect in all other cases
		else {

			flashVer = -1;
		}
		return flashVer;
	}
	
	this.VBGetSwfVer = function (i){
		try{
			var axo = new ActiveXObject ("ShockwaveFlash.ShockwaveFlash");
			return axo.GetVariable ("$version").split (" ")[1]
		}catch (e){
			return - 1
		}
	}
	
	this.detectFlashVer = function (reqMajorVer, reqMinorVer, reqRevision){
		var reqVer = reqMajorVer * 10000 + reqMinorVer * 100 + reqRevision
		var versionStr = new String()
		if (this.isIE && this.isWin && !this.isOpera) {
			versionStr = this.VBGetSwfVer();
		} else {
			versionStr = this.JSGetSwfVer();		
		}
		
		if (versionStr == - 1 ){
			return false;
		} else if (versionStr != 0){
			var versionArray = versionStr.split (",");
			var versionMajor = Number (versionArray [0]);
			var versionMinor = Number (versionArray [1]);
			var versionRevision = Number (versionArray [2]);
			var versionNum = versionMajor * 10000 + versionMinor * 100 + versionRevision
			if (versionNum >= reqVer){
				return true;
			} else {
				return false ;
			}
		}
	}
	
	this.addParam = function (param, value){
		var obj = new Object ();
		obj.paramName = param;
		obj.paramValue = value;
		this.params[this.params.length] = obj;
	}
	
	this.writeDocument = function (path, width, height){
		var s = new String ();
		s += '<object ';
		s += 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		s += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0" ';
		s += 'width="' + width + '" height="' + height + '" > <param name="movie" value="' + path + '" />';
		for (var i in this.params){
			s += '<param name="' + this.params [i].paramName + '" value="' + this.params [i].paramValue + '" /> ';
		}
		s += '<embed ';
		s += 'pluginspage="http://www.macromedia.com/go/getflashplayer" ';
		s += 'type="application/x-shockwave-flash" ';
		s += 'width="' + width + '" height="' + height + '" src="' + path + '" ';
		for (var i in this.params){
			s += this.params [i].paramName + '="' + this.params [i].paramValue + '" ';
		}
		s += '></embed></object>'
		document.write (s);
	}
	
	this.loadSWF = function (path){
		
		var hasInstallVision = this.detectFlashVer (this.requiredInstallVision [0] , this.requiredInstallVision [1] , this.requiredInstallVision [2]);
		var hasDisplayVision = this.detectFlashVer (this.requiredDisplayVision [0] , this.requiredDisplayVision [1] , this.requiredDisplayVision [2]);

		if (hasInstallVision){
			if (hasDisplayVision){
				this.writeDocument (path , this.width , this.height)
				//  var code = '你的flash player版本已经是最新的了，这里可以加载你的最新的flash 8 程序展示给大家看';
				//	document.write(code);
				
			}else{
				this.writeDocument (this.upgradeSWF , this.width , this.height)
				//var code = '你的版本不够，必须升级，这里可以调用专门的升级程序';
				//document.write(code);
				
			}
		} else {
			var code = '你没有安装flash player，点这里可以安装最新的flash player，<a href=http://www.macromedia.com/go/getflash/>Get Flash</a>';
			document.write (code);
		}
	}
}

