
function BrowserInfo()
{
	this.name = "Unknown";
	this.version = 0.0;
	this.os = "-";
	
	this.init = BrowserInfoInit;
	this.isIE = BrowserInfoIsIE;
	this.isNN = BrowserInfoIsNN;
	this.getVersion = BrowserInfoGetVersion;
	this.getName = BrowserInfoGetName;
	this.getOS = BrowserInfoGetOS;
}

function BrowserInfoInit()
{
	var userAgent =	navigator.userAgent.toLowerCase();
	var appName = navigator.appName.toLowerCase();
	
	//
	// get environment
	//
	if (userAgent.indexOf("win") != -1)
	{
		this.os = "Windows";
	}
	else if (userAgent.indexOf("mac") != -1)
	{
		this.os = "Macintosh";
	}
	else if (userAgent.indexOf("x11") != -1)
	{
		this.os = "X11";
	}
	else
	{
		this.os = "Unknown";
	}
	
	//
	// fetch Browser name
	//
	if (userAgent.indexOf("opera") == -1)
	{
		if (appName.indexOf("netscape") != -1)
		{
			this.name = "Netscape";
		}
		else if (appName.indexOf("microsoft") != -1)
		{
			this.name = "Internet Explorer";
		}
		else if (appName.indexOf("icab") != -1)
		{
			this.name = "iCab";
		}
		else if (appName.indexOf("mozilla") != -1)
		{
			this.name = "Mozilla";
		}
		else if (appName.indexOf("safari") != -1)
		{
			this.name = "Safari";
		}
		else
		{
			this.name = "Unknown";
		}
		
		if (this.name == "Internet Explorer")
		{
			var versionArray = userAgent.split(";");
			this.version = parseFloat(versionArray[1].substr(5, versionArray[1].length));
		}
		else if (this.name == "iCab")
		{
			this.version = parseFloat(userAgent.substr(userAgent.indexOf("/") + 1, userAgent.indexOf(" ") - userAgent.indexOf("/")));
		}
		else
		{
			this.version = parseFloat(navigator.appVersion);
		}
	}
	else
	{
		this.name = "Opera";
	}
}

function BrowserInfoIsIE()
{
	return this.name == "Internet Explorer";
}

function BrowserInfoIsNN()
{
	return this.name == "Netscape";
}

function BrowserInfoGetVersion()
{
	return this.version;
}

function BrowserInfoGetName()
{
	return this.name;
}

function BrowserInfoGetOS()
{
	return this.os;
}

var browser = new BrowserInfo();
browser.init();