//  CLIENT_SIDE SNIFFER CODE

// convert all characters to lowercase to simplify testing

var cssDir = "/wgbh/nova/elegant/css/";
var stylePrefix = "";

var winNSCSS = "winns.css";
var winIECSS = "winie.css";
var macNAVCSS = "macns.css";
var macIECSS = "macie.css";
var macIE5CSS = "macie5.css";
var unixCSS = "macie.css";

var agt=navigator.userAgent.toLowerCase(); 

// *** BROWSER VERSION *** 
// Note: On IE5, these return 4, so use is_ie5up to detect IE5. 
var is_major = parseInt(navigator.appVersion); 
var is_minor = parseFloat(navigator.appVersion); 

// *** BROWSER TYPE *** 
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
            && (agt.indexOf('webtv')==-1));
var is_nav4up = (is_nav && (is_major >= 4));  
var is_ie   = (agt.indexOf("msie") != -1); 
var is_ie3  = (is_ie && (is_major < 4)); 
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up  = (is_ie  && (is_major >= 4));
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );  
var is_ie5up  = (is_ie5  && !is_ie3 && !is_ie4);  

// *** PLATFORM ***
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);
var is_sun   = (agt.indexOf("sunos")!=-1);
var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
var is_hpux  = (agt.indexOf("hp-ux")!=-1);
var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
var is_linux = (agt.indexOf("inux")!=-1);
var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
var is_unixware = (agt.indexOf("unix_system_v")!=-1); 
var is_mpras    = (agt.indexOf("ncr")!=-1); 
var is_reliant  = (agt.indexOf("reliantunix")!=-1);
var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
       (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || 
       (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
var is_sinix = (agt.indexOf("sinix")!=-1);
var is_freebsd = (agt.indexOf("freebsd")!=-1);
var is_bsd = (agt.indexOf("bsd")!=-1);
var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || 
             is_sco ||is_unixware || is_mpras || is_reliant || 
             is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

//  Select the appropriate stylesheet
if ((is_nav4up || is_ie4up || is_ie5) || (!is_nav && !is_ie)) {
  ChooseStyleSheet();
}
			 
// video tracking functions

function version() {
	var versionNum;
	var indexVer;
	// accounting for MSIE masquerading as Navigator
	indexVer = navigator.appVersion.indexOf("MSIE")
	if (indexVer < 0) {
		indexVer = 0;
	} else {
		indexVer = indexVer + 5;
	}		
	versionNum = parseFloat(navigator.appVersion.substring(indexVer,indexVer + 4));
	return versionNum;
}


function bring2top() {
	if ( (navigator.appName == "Microsoft Internet Explorer") && (version() < 4) ) {
		// nothing
	} else if ( (navigator.appName == "Netscape") && (version() < 3) ) {
		// nothing
	} else {
		focus()
	}
}


// Function to choose the style sheet for use based on the platform
// and browser version
function ChooseStyleSheet() {
			 
  var fileHead = cssDir + stylePrefix;
  var styles;
  if (is_win) {
	if (is_nav) {
      styles = fileHead + winNSCSS;
	} else {
	  // Windows Netscape fonts need to be larger than those for IE
	  styles = fileHead + winIECSS;
	}
  } else if (is_mac) {
      if (is_ie) {
        styles = fileHead + macIECSS;
	  } else if  (is_ie5){
	    styles = fileHead + macIE5CSS;
		} else if  (is_nav){
	    styles = fileHead + macNAVCSS;
		}
  } else if (is_unix) {
    styles = fileHead + unixCSS;
  } else {
    // Default style = macCSS
	// Macintosh stylesheets have the largest font sizes, which
	// will ensure readability
	styles = fileHead + macIECSS;
  }

  document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + styles + "\">");
  return true;
}







//Force Tables in  Netscape to go all the way to the right margin
//Pass 'IE' as the second argument to the function if you want to make
//sure IE doesn't put anything in(especially  &nbsp; where a table cell
//is supposed to be only 1px high

		function makeIt (num,exception) {
 	 		var browser = navigator.appName;
			 var version = parseInt(navigator.appVersion);
			 var width;
			 if (browser == "Netscape" && version >= '4') {
			 	width = window.innerWidth;
			 	if (num == 'total') {
			 		//make sure path to spacer.gif is correct
		 			space = "<img src='/wgbh/nova/images02/spacer.gif' width='" + width +"' height='1'  border='0'  alt='  ' />"; 
		 			return space;
		 		} else if (width <= num) {  
		 			space = '&nbsp;';
		 		} else {
		 			
		 			width = width - num; 
		 			//make sure path to spacer.gif is correct
		 			space = "<img src='/wgbh/nova/images02/spacer.gif' width='" + width +"' height='1'  border='0'  alt='  ' />"; 
		 		}
			 } else if (browser != "Netscape" && num == 'total') {
		 		space = '';
			 } else if (browser != "Netscape" && exception == "IE") {
				space = '';		 	
			 } else {
			 	space = '&nbsp;';
			 }
			 return space;
		}
		
		
//Force NN to reload on re-size
 		function fixNN () {
 			var ua = navigator.appName;
			var uanum = parseFloat(navigator.appVersion);
			if (ua == "Netscape" && uanum >= '4.08') {
				location.reload();
			} else {
				return;
			}
		}
		
// rollover functions
function roll_off(imgName) {
	if(document.images)
	document[imgName].src = eval(imgName + '1.src');
}

function roll_on(imgName) {
	if(document.images)
	document[imgName].src = eval(imgName + '2.src');
}

function cfl_window(which_window, image_width, image_height) {
  var window_width = image_width + 46;
  var window_height = image_height + 175;
  newwin = window.open(which_window, "cfl_window", 
'toolbar=0,location=0,directories=0,scrollbars=1,status=0,menubar=0,resizable=1,width=' + window_width + ',height=' + window_height);
window.self.name = "cfl_parent";
//  movingwindow.focus();
}


if(document.images) {
	
	var nav_ctw1 = new Image();
	var nav_ctw2 = new Image();
	
	nav_ctw1.src = "/wgbh/nova/images03/nav_ctw.gif";
	nav_ctw2.src = "/wgbh/nova/images03/nav_ctw_on.gif";
}

  function pluginDesc(aMimeType) {
    if (navigator.mimeTypes) {
      if (navigator.mimeTypes[aMimeType]) {
        if (navigator.mimeTypes[aMimeType].enabledPlugin) {
          if (aMimeType == 'video/quicktime') {	// special case for QuickTime -- version is in name, not description

            return navigator.mimeTypes[aMimeType].enabledPlugin.name;
          } else {
          	return navigator.mimeTypes[aMimeType].enabledPlugin.description;
          }
        }
      }
    }
  }

function  plugin_ret() {
  // given a mime type, returns the plug-in's description, if there is one.
  var q = '?';
  q += 'screen.height=' + screen.height + '&';
  q += 'screen.width=' + screen.width + '&';
  if (document.body) {
    q += 'window.height=' + document.body.clientHeight + '&';
    q += 'window.width=' + document.body.clientWidth + '&';
  } else if (window.innerHeight) {
    q += 'window.height=' + window.innerHeight + '&';
    q += 'window.width=' + window.innerWidth + '&';
  }
  if (pluginDesc('application/x-director')) { q+= 'shockwave=' + escape(pluginDesc('application/x-director')) + '&'; }
  if (pluginDesc('application/x-shockwave-flash')) { q+= 'flash=' + escape(pluginDesc('application/x-shockwave-flash')) + '&'; }
  if (pluginDesc('video/quicktime')) { q+= 'quicktime=' + escape(pluginDesc('video/quicktime')) + '&'; }
  q += 'javaEnabled=' + navigator.javaEnabled() + '&';
  if (document.images) {
    var detect = new Image();
    detect.src = 'http://intapp.wgbh.org/intapp/track/single.gif' + q;
    document.write('<img src="' + detect.src + '" height="1" width="1" alt="">');
  }
}