// JavaScript Document
// Copyright 2009 Spencer Website Design All rights reserved.
// www.spencerwebsitedesign.com
//
// JavaScript Browser Sniffer
// Based on the work of Eric Krok, Andy King, Michel Plungjan
// see http://www.webreference.com/ for more information

var browserdecl = 0; // old
var flashdecl = false; // no flash player installed

// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();


// *** BROWSER VERSION ***

var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);

var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);
var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);
var is_opera8 = (agt.indexOf("opera 8") != -1 || agt.indexOf("opera/8") != -1);
var is_opera9 = (agt.indexOf("opera 9") != -1 || agt.indexOf("opera/9") != -1);

var is_opera8up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6 && !is_opera7);

var is_mac = (agt.indexOf("mac")!=-1);
var iePos  = appVer.indexOf('msie');
if (iePos !=-1)
{
	 if(is_mac)
	 {
		 iePos = agt.indexOf('msie');
		 is_minor = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));
	 }
	 else
	 {
		 is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
	 }
	 is_major = parseInt(is_minor);
}

var is_safari = (agt.indexOf('safari')!=-1)?true:false;

var is_gecko = ((!is_safari)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;

var is_fx = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
						 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
						 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
						 (is_gecko) && ((navigator.vendor=="Firefox")||(agt.indexOf('firefox')!=-1)));

if (is_fx)
{
	 var is_fx_ver = (navigator.vendorSub)?navigator.vendorSub:0;
	 if(is_fx&&!is_fx_ver)
	 {
			 is_fx_ver = agt.indexOf('firefox/');
			 is_fx_ver = agt.substring(is_fx_ver+8);
			 is_fx_ver = parseFloat(is_fx_ver);
	 }
	 if(!(is_fx_ver))
	 {
			 is_fx_ver = agt.indexOf('rv:');
			 is_fx_ver = agt.substring(is_fx_ver+3);
			 is_paren   = is_fx_ver.indexOf(')');
			 is_fx_ver = is_fx_ver.substring(0,is_paren);
	 }
	 is_minor = is_fx_ver;
	 is_major = parseInt(is_fx_ver);
}

var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_safari));
var is_ie7up = (is_ie && is_minor >= 7);


// *** PLATFORM ***
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
is_mac    = (agt.indexOf("mac")!=-1);
if (is_mac) { is_win = !is_mac; }


// *** FLASH DETECTION ***
// see http://webref.com/js/column84/2.html

var is_Flash        = false;
var is_FlashVersion = 0;

if ((is_opera||is_fx||is_safari)||
	 (is_mac&&is_ie7up))
{
	var plugin = (navigator.mimeTypes &&
								navigator.mimeTypes["application/x-shockwave-flash"] &&
								navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) ?
								navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if (plugin&&plugin.description)
	{
		 is_Flash = true;
		 is_FlashVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1));
	}
}

if (is_win&&is_ie7up)
{
	document.write(
		 '<scr' + 'ipt language=VBScript>' + '\n' +
		 'Dim hasPlayer, playerversion' + '\n' +
		 'hasPlayer = false' + '\n' +
		 'playerversion = 10' + '\n' +
		 'Do While playerversion > 0' + '\n' +
				'On Error Resume Next' + '\n' +
				'hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & playerversion)))' + '\n' +
				'If hasPlayer = true Then Exit Do' + '\n' +
				'playerversion = playerversion - 1' + '\n' +
		 'Loop' + '\n' +
		 'is_FlashVersion = playerversion' + '\n' +
		 'is_Flash = hasPlayer' + '\n' +
		 '<\/sc' + 'ript>');
}

if(((is_fx)&&(is_fx_ver>=2))||(is_ie7up)||(is_opera8up)||(is_safari))
{
	browserdecl = 1; // New enough
}

// This is old and doesn't seem to work anymore. 
//if(is_FlashVersion >= 8)
//{
//	flashdecl = true;
//}