/************************************************************************/
/* File: browserDetect.js						*/
/* Auth: Anthony Decena							*/
/* Desc: This is a modified version of Erik Krok's Ultimate Browser	*/
/* 	 Sniffer.  This should easily tell us anything that we need to	*/
/*	 know when it comes to the necessary tools needed for viewing	*/
/* 	 anything on NowStream.  I have fitted it with a few extra	*/
/*	 checks including a Flash Player Detection, and I hope to add	*/
/*	 a media player detection soon.					*/
/************************************************************************/

/* Lets get this fuckin party started */
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
/* Proper browsers should have major and minor versions */
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_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5); 
var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6); 


/* IE does some shit with its appVersion that displays a 3 or 4 instead	*/
/* of the actual version.  Supposedly this 3 or 4 is the version of NS	*/
/* that it is compatible with.  Sounds like a bunch of commie bullshit	*/
/* if you ask me.							*/
var is_mac = (agt.indexOf("mac")!=-1);
var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
	if(is_mac) {
          	var 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_konq = false;
var kqPos   = agt.indexOf('konqueror');
if (kqPos !=-1) {                 
     	is_konq  = true;
       	is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
       	is_major = parseInt(is_minor);
    	}                                 

var is_getElementById   = (document.getElementById) ? "true" : "false"; 
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false"; 
var is_documentElement = (document.documentElement) ? "true" : "false"; 

var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var is_khtml  = (is_safari || is_konq);

var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
var is_gver  = 0;
if (is_gecko) is_gver=navigator.productSub;


var is_moz = ((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=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")));

var is_fb = ((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=="Firebird"));

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"));

if ((is_moz)||(is_fb)||(is_fx)) {
    	var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
       	if(!(is_moz_ver)) {
           	is_moz_ver = agt.indexOf('rv:');
           	is_moz_ver = agt.substring(is_moz_ver+3);
           	is_paren   = is_moz_ver.indexOf(')');
           	is_moz_ver = is_moz_ver.substring(0,is_paren);
       		}
       	is_minor = is_moz_ver;
       	is_major = parseInt(is_moz_ver);
    	}
   	
var is_fb_ver = is_moz_ver;
var is_fx_ver = is_moz_ver;

var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
		&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
                && (!is_khtml) && (!(is_moz)) && (!is_fb) && (!is_fx));

if ((navigator.vendor)&& ((navigator.vendor=="Netscape6") || (navigator.vendor=="Netscape")) && (is_nav)) {
     	is_major = parseInt(navigator.vendorSub);
       	is_minor = parseFloat(navigator.vendorSub);
    	}

var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && is_minor >= 4);  
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );

var is_nav6   = (is_nav && is_major==6);    // new 010118 mhp
var is_nav6up = (is_nav && is_minor >= 6); // new 010118 mhp

var is_nav5   = (is_nav && is_major == 5 && !is_nav6); // checked for ns6
var is_nav5up = (is_nav && is_minor >= 5);

var is_nav7   = (is_nav && is_major == 7);
var is_nav7up = (is_nav && is_minor >= 7);

var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
var is_ie3  = (is_ie && (is_major < 4));

var is_ie4   = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5   = (is_ie && is_major == 5);
var is_ie5up = (is_ie && is_minor >= 5);
    
var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
var is_ie5_5up =(is_ie && is_minor >= 5.5);                // 020128 new - abk
	
var is_ie6   = (is_ie && is_major == 6);
var is_ie6up = (is_ie && is_minor >= 6);


/* AOL uses this embedded browser bullshit that I read about.  So if the windows that	*/
/* they are viewing nowstream in was not the first windows opened, we may get a misread */
/* on the AOL browser.  So this isnt 100%, all we can hope is that the embedded browser */
/* that their AOL is using is IE6up							*/
var is_aol   = (agt.indexOf("aol") != -1);
var is_aol3  = (is_aol && is_ie3);
var is_aol4  = (is_aol && is_ie4);
var is_aol5  = (agt.indexOf("aol 5") != -1);
var is_aol6  = (agt.indexOf("aol 6") != -1);
var is_aol7  = ((agt.indexOf("aol 7")!=-1) || (agt.indexOf("aol7")!=-1));
var is_aol8  = ((agt.indexOf("aol 8")!=-1) || (agt.indexOf("aol8")!=-1));

var is_webtv = (agt.indexOf("webtv") != -1);
        
var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
var is_AOLTV = is_TVNavigator;

var is_hotjava = (agt.indexOf("hotjava") != -1);
var is_hotjava3 = (is_hotjava && (is_major == 3));
var is_hotjava3up = (is_hotjava && (is_major >= 3));


/* The reason that a javascript version check is a good idea is because	*/
/* we can know ahead of time which of our checks will work and which 	*/
/* will not.  Also if someone rolls up with a NS browser, we may be 	*/
/* able to fool it into embedding some of the tools we need.(maybe)	*/
var is_js;
if (is_nav2 || is_ie3) is_js = 1.0;
else if (is_nav3) is_js = 1.1;
else if ((is_opera5)||(is_opera6)) is_js = 1.3; 
else if (is_opera7up) is_js = 1.5; 
else if (is_khtml) is_js = 1.5;   
else if (is_opera) is_js = 1.1;
else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
else if (is_nav5 && !(is_nav6)) is_js = 1.4;
else if (is_hotjava3up) is_js = 1.4;
else if (is_nav6up) is_js = 1.5;
else if (is_nav && (is_major > 5)) is_js = 1.4;
else if (is_ie && (is_major > 5)) is_js = 1.3;
else if (is_moz) is_js = 1.5;
else if (is_fb||is_fx) is_js = 1.5;
else is_js = 0.0;
    
if ((agt.indexOf("mac")!=-1) && is_ie5up) is_js = 1.4;
    
if (is_nav6up) {
	is_minor = navigator.vendorSub;
    	}


/* These are just random checks .... this probably shouldnt be used as	*/
/* a utility class library but I'm just going to keep these here for	*/
/* now.  If you want the utility class with all the fun stuff in it go	*/
/* get DianaB.js from the beta box.					*/
var is_anchors = (document.anchors) ? "true":"false";
var is_regexp = (window.RegExp) ? "true":"false";
var is_option = (window.Option) ? "true":"false";
var is_all = (document.all) ? "true":"false";
var is_images = (document.images) ? "true":"false";
var is_layers = (document.layers) ? "true":"false"; // gecko m7 bug?
var is_forms = (document.forms) ? "true" : "false";
var is_links = (document.links) ? "true" : "false";
var is_frames = (window.frames) ? "true" : "false";
var is_screen = (window.screen) ? "true" : "false";
var is_java = (navigator.javaEnabled());


/* Its always good to know if someones got a flash player .. Actually	*/
/* the only reason this is here is becuase I made the photo album in 	*/
/* flash and may need to check for it .. :P				*/
var is_Flash        = false;
var is_FlashVersion = 0;

if ((is_nav||is_opera||is_moz||is_fb||is_fx)||(is_mac&&is_ie5up)) {
  	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));
      		}
   	}

/* Im taking this out for now because I removed all the platformer stuff from this script. I'll	*/
/* put it back in soon.  Still needs to be tested some.						*/
/*if (is_win&&is_ie4up) {
	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>');
   		}*/


