
function ClientType (habitat) {
	this.habitat = habitat;
	this.uA = navigator.userAgent;
	this.aV = parseFloat( navigator.appVersion );
	this.nP = navigator.platform;
	this.nA = navigator.appName;
	this.b_type = "unknown";
	this.b_ver = "unknown";
	this.os_type = "unknown";
	this.os_ver = "unknown";

	if( this.uA.indexOf( "Opera" ) > -1 ) {
		this.b_type = "opera";
		this._opera();
	}

	if( this.uA.indexOf( "KHTML" ) > -1 || this.uA.indexOf( "Konqueror" ) > -1 || this.uA.indexOf( "AppleWebKit" ) > -1 ) {
		this.b_type = "khtml";
		this._khtml();
	}

	if( this.uA.indexOf( "compatible" ) > -1 && this.uA.indexOf( "MSIE" ) > -1 && this.b_type != "opera" ) {
		this.b_type = "ie";
		this._ie();
	}

	if( this.uA.indexOf( "Gecko" ) > -1 && this.b_type != "khtml" ) {
		this.b_type = "mozilla";
		this._mozilla();
	}

	if( this.b_type != "ie" && this.b_type != "opera" && this.b_type != "mozilla" && this.b_type != "khtml" &&
	( this.uA.indexOf( "Mozilla" ) == 0 ) && ( this.nA == "Netscape" ) && ( this.aV >= 4.0 && this.aV < 5.0 ) ) {
		this.b_type = "ns4";
		this.b_ver = this.aV;
	}

	if( ( this.nP == "Win32" ) || ( this.nP == "Windows" ) ) {
		this.os_type = "win";
		this._win();
	}
	if( ( this.nP == "Mac68k" ) || ( this.nP == "MacPPC" ) || ( this.nP == "Macintosh" ) ) {
		this.os_type = "mac";
		this._mac();
	}
	if( ( this.nP == "X11" ) && this.os_type != "win" && this.os_type != "mac" ) {
		this.os_type = "unix";
		this._unix();
	}
	return this;
}

ClientType.prototype._ie = function () {
	var match = this.uA.match(new RegExp( "MSIE (\\d+\\.\\d+);" ));
	if( match ) {
		this.b_ver = parseFloat( match[1] );
	}
};

ClientType.prototype._khtml = function () {
	this.safari = this.uA.indexOf( "AppleWebKit" ) > -1;
	this.konq = this.uA.indexOf( "Konqueror" ) > -1;
	if( this.safari ) {
		var match = this.uA.match(new RegExp( "AppleWebKit\\/(\\d+(?:\\.\\d*)?)" ));
		if( match ) {
			var ver = parseFloat( match[1] );
			if( ver >= 85 ) {
				this.b_ver = 1;
			} else if ( ver >=124 ) {
				this.b_ver = 1.2;
			}
		}
	} else if( this.konq ) {
		var match = this.uA.match(new RegExp( "Konqueror\\/(\\d+(?:\\.\\d+(?:\\.\\d)?)?)" ));
		if( match ) {
			this.b_ver = match[1];
		}
	}
};

ClientType.prototype._mac = function () {
	var match = this.uA.match(new RegExp( "(Mac_(68000|PowerPC)|68K|PPC)" ));
	if( match ) {
		if( match[1] == "68K" || match[2] == "68000" ) {
			this.os_ver = "mac68k";
		} else if( match[1] == "PPC" || match[2] == "PowerPC" ) {
			this.os_ver = "macPPC";
		}
	}
};

ClientType.prototype._mozilla = function () {
	var match = this.uA.match(new RegExp( "rv:(\\d+\\.\\d+(?:\.\\d+)?)" ));
	if( match ) {
		this.b_ver = match[ 1 ];
	}
};

ClientType.prototype._opera = function () {
	if( this.nA == "Opera" ) {
		this.b_ver = this.aV;
	} else {
		var match = this.uA.match(new RegExp( "Opera (\\d+\\.\\d+)" ));
		if( match ) {
			this.b_ver = parseFloat( match[ 1 ] );
		}
	}
};

ClientType.prototype._unix = function () {
	if( this.uA.indexOf( "SunOS" ) > -1 ) {
		this.os_type = "sunos";
		var match = this.uA.match(new RegExp( "SunOS (\\d+\\.\\d+(?:\\.\\d+)?)" ));
		if( match ) {
			if( this.vType( match[1], "4.0" ) ) {
				this.os_ver = "4";
			} else if( this.vType( match[1], "5.0" ) ) {
				this.os_ver = "5";
			} else if( this.vType( match[1], "5.5" ) ) {
				this.os_ver = "5.5";
			}
		}
	}
};

ClientType.prototype._win = function () {
	if( this.uA.indexOf( "Win95" ) > -1 || this.uA.indexOf( "Windows 95" ) > -1 ) {
		this.os_ver = "win95";
	} else if( this.uA.indexOf( "Win98" ) > -1 || this.uA.indexOf( "Windows 98" ) > -1 ) {
		this.os_ver = "win98";
	} else if( this.uA.indexOf( "Win 9x 4.90" ) > -1 || this.uA.indexOf( "Windows ME" ) > -1 ) {
		this.os_ver = "winME";
	} else if( this.uA.indexOf( "Windows NT 5.0" ) > -1 || this.uA.indexOf( "Windows 2000" ) > -1 ) {
		this.os_ver = "win2K";
	} else if( this.uA.indexOf( "Windows NT 5.1" ) > -1 || this.uA.indexOf( "Windows XP" ) > -1 ) {
		this.os_ver = "winXP";
	} else if( this.uA.indexOf( "WinNT" ) > -1 || this.uA.indexOf( "Windows NT" ) > -1 || this.uA.indexOf( "WinNT4.0" ) > -1 || this.uA.indexOf( "Windows NT 4.0" ) > -1 && ( this.os_ver != "winME" && this.os_ver != "win2K" && this.os_ver != "winXP" ) ) {
		this.os_ver = "winNT4";
	}
};

ClientType.prototype.vType = function ( v1, v2 ) {
	v1 = v1.split( "." );
	v2 = v2.split( "." );
	var len1 = v1.length;
	var len2 = v2.length;
	if( len1 > len2 ) {
		for( var i = 0; i < len1 - len2; i++ ) {
			v2.push( "0" );
		}
	} else if( len2 > len1 ) {
		for( var i = 0; i < len2 - len1; i++ ) {
			v1.push( "0" );
		}
	}
	for( var i = 0; i < len1; i++ ) {
		if( v1[ i ] < v2[ i ] ) {
			return -1;
		} else if( v1[ i ] > v2[ i ] ) {
			return 1;
		}
	}
	return 0;
};

