/**
 * @namespace com.thesis.base.Detect
 * @author 钟军锐 August.R@263.net
 */

/** @id doDetect */
function doDetect(){
	//Detect类的方法
	if(typeof doDetect._initialized=="undefined"){
		doDetect._initialized = true;
		/** @id compareVersions */
		doDetect.prototype.compareVersions = function (sVersion1, sVersion2){
			var aVersion1=sVersion1.split(".");
			var aVersion2=sVersion2.split(".");
			if(aVersion1.length > aVersion2.length ){
				for(var i=0;i<aVersion1.length - aVersion2.length;i++ ) aVersion2.push("0");
			}
			else{
				for(var i=0;i<aVersion2.length - aVersion1.length;i++) aVersion1.push("0");
			}
			for(var i=0;i<aVersion1.length;i++){
				if(aVersion1[i] < aVersion2[i]) return -1;
				else if (aVersion1[i] > aVersion2[i]) return 1;
			}
			return 0;
		};
	}
	//Detect类的属性
	this.sUserAgent = navigator.userAgent;
	this.fAppVersion= parseFloat(navigator.appVersion);
	//匹配Opera浏览器
	this.isOpera=this.sUserAgent.indexOf("Opera")>-1;
	this.isMinOpera4=this.isMinOpera5=this.isMinOpera6=this.isMinOpera7=this.isMinOpera7_5=false;
	if(this.isOpera){
		if(navigator.appName=="Opera")  this.fOperaVersion=fAppVersion;
		else{
			this.reOperaVersion=new RegExp("Opera (\\d+\\.\\d+)");
			this.reOperaVersion.test(this.sUserAgent);
			this.fOperaVersion= parseFloat(RegExp["$1"]);
		}
		this.isMinOpera4=this.fOperaVersion>=4;
		this.isMinOpera5=this.fOperaVersion>=5;
		this.isMinOpera6=this.fOperaVersion>=6;
		this.isMinOpera7=this.fOperaVersion>=7;
		this.isMinOpera7_5=this.fOperaVersion>=7.5;
	}
	//匹配Safari浏览器
	this.isKHTML=this.sUserAgent.indexOf("KHTML")>-1 
					|| this.sUserAgent.indexOf("Konqueror")>-1
					|| this.sUserAgent.indexOf("AppleWebKit")>-1;
	this.isMinSafari1=this.isMinSafari1_2=false;
	this.isMinKonq2_2=this.isMinKonq3=this.isMinKonq3_1=this.isMinKonq3_2=false;
	if(this.isKHTML){
		this.isSafari=this.sUserAgent.indexOf("AppleWebKit")>-1;
		this.isKonq=this.sUserAgent.indexOf("Konqueror")>-1;
		if(this.isSafari){
			this.reAppleWebKit=new RegExp("AppleWebKit\\/(\\d+(?:\\.d*)?)");
			this.reAppleWebKit.test(this.sUserAgent);
			this.fAppleWebKitVersion=parseFloat(RegExp["$1"]);
			this.isMinSafari1=this.fAppleWebKitVersion>=85;
			this.isMinSafari1_2=this.fAppleWebKitVersion>=124;
		}
		else{
			this.reKonq=new RegExp("Konqueror\\/(\\d+(?:\\.\\d+(?:\\.\\d)?)?)");
			this.reKonq.test(this.sUserAgent);
			this.isMinKonq2_2=this.compareVersions(RegExp["$1"],"2.2")>=0;
			this.isMinKonq3=this.compareVersions(RegExp["$1"],"3.0")>=0;
			this.isMinKonq3=this.compareVersions(RegExp["$1"],"3.1")>=0;
			this.isMinKonq3_2=this.compareVersions(RegExp["$1"],"3.2")>=0;
		}
	}
	//匹配IE浏览器
	this.isIE=this.sUserAgent.indexOf("compatible")>-1 
				&& this.sUserAgent.indexOf("MSIE")>-1 
				&& !this.isOpera;
	this.isMinIE4=this.isMinIE5=this.isMinIE5_5=this.isMinIE6=this.isMinIE7=false;
	if(this.isIE){
		this.reIE=new RegExp("MSIE (\\d\\.\\d+);");
		this.reIE.test(this.sUserAgent);
		this.fIEVersion=parseFloat(RegExp["$1"]);
		this.isMinIE4=this.fIEVersion>=4;
		this.isMinIE5=this.fIEVersion>=5;
		this.isMinIE5_5=this.fIEVersion>=5.5;
		this.isMinIE6=this.fIEVersion>=6.0;
		this.isMinIE7=this.fIEVersion>=7.0;
	}
	//匹配Mozilla浏览器
	this.isMoz=this.sUserAgent.indexOf("Gecko")>-1 && !this.isKHTML;
	this.isMinMoz1=this.isMinMoz1_4=this.isMinMoz1_5=this.isMinMoz2=false;
	if(this.isMoz){
		this.reMoz=new RegExp("rv:(\\d+\\.\\d+(?:\\.\\d+)?)");
		this.reMoz.test(this.sUserAgent);
		this.isMinMoz1=this.compareVersions(RegExp["$1"],"1.0")>=0;
		this.isMinMoz1_4=this.compareVersions(RegExp["$1"],"1.4")>=0;
		this.isMinMoz1_5=this.compareVersions(RegExp["$1"],"1.5")>=0;
		this.isMinMoz2=this.compareVersions(RegExp["$1"],"1.8")>=0;
	}
	//匹配NetScape浏览器
	this.isNS4=!this.isIE && !this.isOpera && !this.isMoz && !this.isKHTML
				&& (this.sUserAgent.indexOf("Mozilla")==0) 
				&& (navigator.appName=="Netscape")
				&& (this.fAppVersion>=4.0 && this.fAppVersion<5.0);
	this.isMinNS4=this.isMinNS4_5=this.isMinNS4_7=this.isMinNS4_8=false;
	if(this.isNS4){
		this.isMinNS4=true;
		this.isMinNS4_5=this.fAppVersion>=4.5;
		this.isMinNS4_7=this.fAppVersion>=4.7;
		this.isMinNS4_8=this.fAppVersion>=4.8;
	}
	//匹配操作系统
	this.isWin=(navigator.platform=="Win32") || (navigator.platform=="Windows");
	this.isMac=(navigator.platform=="Mac68K") || (navigator.platform=="MacPPC") || (navigator.platform=="Macintosh");
	this.isUnix=(navigator.platform=="X11") && !this.isWin && !this.isMac;
	this.isWin95=this.isWin98=this.isWinNT4=this.isWin2k=this.isWinME=this.isWinXP=this.isWinVista=false;
	this.isMac68=this.isMacPPC=false;
	this.isSunOS=this.isMinSunOS4=this.isMinSunOS5=this.isMinSunOS5_5=false;
	if(this.isWin){
		this.isWin95=this.sUserAgent.indexOf("Win95")>-1 || this.sUserAgent.indexOf("Windows 95")>-1;
		this.isWin98=this.sUserAgent.indexOf("Win98")>-1 || this.sUserAgent.indexOf("Windows 98")>-1;
		this.isWinME=this.sUserAgent.indexOf("Win 9x 4.90")>-1 || this.sUserAgent.indexOf("Windows ME")>-1;
		this.isWin2k=this.sUserAgent.indexOf("Windows NT 5.0")>-1 || this.sUserAgent.indexOf("Windows 2000")>-1;
		this.isWinXP=this.sUserAgent.indexOf("Windows NT 5.1")>-1 || this.sUserAgent.indexOf("Windows XP")>-1;
		this.isWinVista=this.sUserAgent.indexOf("Windows NT 6.0")>-1 || this.sUserAgent.indexOf("Windwos Vista")>-1;
		this.isWinNT4=this.sUserAgent.indexOf("WinNT")>-1 || this.sUserAgent.indexOf("Windows NT")>-1 || this.sUserAgent.indexOf("WinNT4.0")>-1 
						|| this.sUserAgent.indexOf("Windows NT 4.0")>-1 && (!this.isWinME && !this.isWin2k && !this.isWinXP && !this.isWinVista);
	}
	if(this.isMac){
		this.isMac68=this.sUserAgent.indexOf("Mac_68000")>-1 || this.sUserAgent.indexOf("68K")>-1;
		this.isMacPPC=this.sUserAgent.indexOf("Mac_PowerPC")>-1 || this.sUserAgent.indexOf("PPC")>-1;
	}
	if(this.isUnix){
		this.isSunOS=this.sUserAgent.indexOf("SunOS")>-1;
		if(this.isSunOS){
			this.reSunOS=new RegExp("SunOS (\\d+\\.\\d+(?:\\.\\d+)?)");
			this.reSunOS.test(this.sUserAgent);
			this.isMinSunOS4=this.compareVersions(RegExp["$1"],"4.0")>=0;
			this.isMinSunOS5=this.compareVersions(RegExp["$1"],"5.0")>=0;
			this.isMinSunOS5_5=this.compareVersions(RegExp["$1"],"5.5")>=0;
		}
	}
}
/** @id Detect */
var Detect = new doDetect();
