/////////////////////////////////////////////////////
//
//  BrowserInfo クラス ver 0.2
// 
//	http://www.horori.net 
//  
//  2007/11/22 - netscapeの判定ミスを修正
//  2006/12/13 - 公開
//
/////////////////////////////////////////////////////
/*
使用例）

  var bi = new BrowserInfo();

　//例:MacIEかどうかを判定する
  if( bi.macie )
	alert("MacIEです。");

　//例:firefoxであればバージョンを表示する。
  if( bi.firefox )
	alert("FireFoxのバージョン：" + bi.firefoxVersion );


BrowserInfoクラスのプロパティ一覧
プロパティ	型	説明
ie	Boolean	InternetExplorerである場合はtrue
ieMVersion	Number(整数)	InternetExplorerのメジャーバージョン 4 , 5 , 6 , 7 など
ieVersion	Number	InternetExplorerのバージョン 4 , 5.1 , 5.5 , 6 , 7 など
macie	Boolean	MacIEであれば true
firefox	Boolean	Firefoxであれば true
firefoxMVersion	Number(整数)	Firefoxのメジャーバージョン 0 , 1 , 2 など
firefoxVersion	Number	Firefoxのバージョン 0.9 , 1.5 , 2 など
safari	Boolean	Safariであれば true
safariMVersion	Number(整数)	Safariのメジャーバージョン 85 , 125 , 412 , 417 など
safariVersion	Number	Safariのバージョン 85.8 , 125.9 , 312.6 など
opera	Boolean	Operaであれば true
operaMVersion	Number(整数)	Oparaのメジャーバージョン 3 , 6 , 7 , 8 , 9 など
operaVersion	Number	Operaのバージョン 6.01 , 7.11 , 8.53 , 9 など
netscape	Boolean	Netscapeであれば true
netscapeMVersion	Number(整数)	Netscapeのメジャーバージョン 6 , 7 など
netscapeVersion	Number	Netscapeのバージョン 6.01 , 7.01 など
webkit	Boolean	Webkitエンジンを使用していれば true
webkitVersion	Number	Webkitエンジンのバージョン 312.8 , 418 など
gecko	Boolean	Geckoエンジンを使用していれば true
geckoVersion	Number	Geckoエンジンのバージョン 20030624 など
*/

function BrowserInfo(userAgent) {

	/*****************************************
	 * Geckoエンジンバージョンチェッカー
	 * (返値 int 合致しない場合は-1)
	 *****************************************/
	this.geckoVersionChecker = function(){
		var num = this.ua.match(new RegExp("Gecko/20[0-9]{6}"));
		return ( num == null ) ? -1 : parseInt(String(num).replace("Gecko/",""));
	}

	/*****************************************
	 * WebKitバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.webkitVersionChecker = function(){
		var num = this.ua.match(new RegExp("WebKit/[0-9]{1,4}(\.[0-9]{1,2})?"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Firefox/",""));
	}

	/*****************************************
	 * IEバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.ieVersionChecker = function(){
		var ienum = this.ua.match(new RegExp("MSIE [0-9]{1,2}\.[0-9]{1,3}"));
		return ( ienum == null ) ? -1 : parseFloat(String(ienum).replace("MSIE ",""));
	}
	

	/*****************************************
	 * Chromeバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.chromeVersionChecker = function(){
		var num = this.ua.match(new RegExp("Chrome/[0-9]{1,2}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Chrome/",""));
	}

	/*****************************************
	 * Firefoxバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.firefoxVersionChecker = function(){
		var num = this.ua.match(new RegExp("Firefox/[0-9]{1,2}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Firefox/",""));
	}

	/*****************************************
	 * Operaバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.operaVersionChecker = function(){
		var num = this.ua.match(new RegExp("Opera[/ ][0-9]{1,2}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).substr(6));
	}

	/*****************************************
	 * Safariバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.safariVersionChecker = function(){
		var num = this.ua.match(new RegExp("Safari/[0-9]{1,4}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Safari/",""));
	}

	/*****************************************
	 * Netscapeバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.netscapeVersionChecker = function(){
		var num = this.ua.match(new RegExp("Netscape[0-9]?/[0-9]{1,2}\.[0-9]{1,3}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace(new RegExp("Netscape[0-9]?/"),""));
	}

	/*****************************************
	 * Mozillaバージョンチェッカー
	 * (返値 float 合致しない場合は-1)
	 *****************************************/
	this.mozillaVersionChecker = function(){
		var num = this.ua.match(new RegExp("Mozilla/[0-9]{1,2}\.[0-9]{1,2}"));
		return ( num == null ) ? -1 : parseFloat(String(num).replace("Mozilla/",""));
	}
	// -- コンストラクタ --

	this.ua = (userAgent) ? userAgent : navigator.userAgent;

	this.geckoVersion = this.geckoVersionChecker();
	this.gecko = (this.geckoVersion > 0 );

	this.webkitVersion = this.webkitVersionChecker();
	this.webkit = (this.webkitVersion > 0 );

	this.ieVersion = this.ieVersionChecker();
	this.ieMVersion = Math.floor(this.ieVersion);
	this.ie = ( this.ieVersion >= 3 );
	this.macie = ( this.ua.match("Mac_PowerPC") != null );

	this.chromeVersion = this.chromeVersionChecker();
	this.chromeMVersion = Math.floor(this.chromeVersion);
	this.chrome = (this.chromeVersion > 0 );

	this.firefoxVersion = this.firefoxVersionChecker();
	this.firefoxMVersion = Math.floor(this.firefoxVersion);
	this.firefox = (this.firefoxVersion > 0 );

	this.safariVersion = this.safariVersionChecker();
	this.safariMVersion = Math.floor(this.safariVersion);
	this.safari = (this.safariVersion > 85 );

	this.operaVersion = this.operaVersionChecker();
	this.operaMVersion = Math.floor(this.operaVersion);
	this.opera = (this.operaVersion > 1 );
	
	this.netscapeVersion = this.netscapeVersionChecker();
	this.netscapeMVersion = Math.floor(this.netscapeVersion);
	this.netscape = (this.netscapeVersion > 1 );
	
	this.mozillaVersion = this.mozillaVersionChecker();
	this.mozilla = ( !this.firefox && !this.opera && !this.ie && !this.netscape && this.mozillaVersion > 0 ); 
	
	this.toString = function(){
		return ("[ua:"+this.ua+"  netscapeVersion:"+this.netscapeVersion+"  operaVersion:" + this.operaVersion + "  webkitVersion:"+ this.webkitVersion +"  safariVersion:"+this.safariVersion+"  safariMVersion:"+this.safariMVersion+"  ieVersion:"+ this.ieVersion +"  macie:" + this.macie  + "  geckoVersion:" +this.geckoVersion + " firefoxVersion:" +this.firefoxVersion +"]" );
	}
}
