//browser and os detection

function infoDetection()
{
	this.os = 'other';
	this.browser = 'other';
	this.version = '0';

	this.css = '';
	
	/**************************************************
		Sets the os, browser, version and css file.
	**************************************************/
	this.detect = function()
	{
		var nVer = navigator.appVersion;
		var nAgt = navigator.userAgent;

		//OS
		if (nVer.indexOf("Win")!=-1) this.os="win";
		if (nVer.indexOf("Mac")!=-1) this.os="mac";
		if (nVer.indexOf("X11")!=-1) this.os="unix";
		if (nVer.indexOf("Linux")!=-1) this.os="linux";

		//BROWSER and VERSION

		//IE
		if ((verOffset=nAgt.indexOf("MSIE"))!=-1)
		{
			this.browser = 'ie';
			var fullVersion  = parseFloat(nAgt.substring(verOffset+5));
			this.version = parseInt(''+fullVersion);
			
			if( this.version < 7 )
			{
				this.css = 'ie6';
			}
			else
			{
				this.css = 'ie';
			}
		}
		//opera
		else if ((verOffset=nAgt.indexOf("Opera"))!=-1) 
		{
			this.browser = 'opera';
			var fullVersion  = parseFloat(nAgt.substring(verOffset+6));
			this.version = parseInt(''+fullVersion);

		}
		//firefox
		else if ( ((verOffset=nAgt.indexOf("Firefox"))!=-1) && ( nAgt.indexOf("Gecko") !=-1 ) ) 
		{
			this.browser = 'firefox';
			var fullVersion  = parseFloat(nAgt.substring(verOffset+8));
			if (!isNaN(fullVersion)) this.version = parseInt(''+fullVersion);
			else {this.version = 0;}

			if( this.os == 'mac' )
			{
				this.css = 'mac_firefox';
			}
		}
		//safari
		else if ( ((verOffset=nAgt.indexOf("Safari"))!=-1) ) 
		{
			this.browser = 'safari';
			var fullVersion  = parseFloat(nAgt.substring(nAgt.indexOf("Version/")+8,nAgt.indexOf("Version/")+12));					
			if (!isNaN(fullVersion)) this.version = parseInt(''+fullVersion);
			else {this.version = 0;}

			if( this.version == 0 )
			{
				var fullVersion  = parseFloat(nAgt.substring(nAgt.indexOf("Safari/")+7));					
				if (!isNaN(fullVersion)) this.version = parseInt(''+fullVersion);
				else {this.version = 0;}
			}

			this.css = 'safari';
		}

		//this.echo();
	}

	/**************************************************
		Writes the style sheet needed to html
	**************************************************/
	this.load_css = function()
	{
		if( this.css != '' )
		{
			document.write('<link rel="stylesheet" href="styles/'+this.css+'.css" />')
		}
	}

	/**************************************************
		Displays captured info
	**************************************************/
	this.echo = function()
	{
		alert(this.os + '::' + this.browser + '::' + this.version);
	}
}

oInfo = new infoDetection();
oInfo.detect();
oInfo.load_css();