// Flash Version Detector  v1.2.1
// documentation: http://www.dithered.com/javascript/flash_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
// with VBScript code from Alastair Hamilton (now somewhat modified)
// AJAX taken from http://rajshekhar.net/blog/archives/85-Rasmus-30-second-AJAX-Tutorial.html
// Edited and adjusted for News.com by Bernie McGinn and Andrew Lottmann, 9/19/2005

var requiredVersion = 7;

function createRequestObject() {
   var ro;
   var browser = navigator.appName;
   if (browser == "Microsoft Internet Explorer"){
      ro = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      ro = new XMLHttpRequest();
   }
   return ro;
}
var http = createRequestObject();

function getFlashVersion() {
   var latestFlashVersion = 8;
   var agent = navigator.userAgent.toLowerCase(); 
	
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			for (var i = latestFlashVersion; i >= 3; i--) {
            if (flashPlugin.description.indexOf(i + '.') != -1) {
               flashVersion = i;
               break;
            }
         }
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	   var doc = '<scr' + 'ipt language="VBScript"\> \n';
      doc += 'On Error Resume Next \n';
      doc += 'Dim obFlash \n';
      doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n';
      doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
      doc += '   If IsObject(obFlash) Then \n';
      doc += '      flashVersion = i \n';
      doc += '      Exit For \n';
      doc += '   End If \n';
      doc += 'Next \n';
      doc += '</scr' + 'ipt\> \n';
      document.write(doc);
   }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = -1;
	}
	
	try { flashVersion; }
	catch(e) { flashVersion = 0; }
	
	return flashVersion;
}

function openBigPic(assetID,nodeID,pageType) {
    var url='/component/dynamic/'+pageType+'-'+nodeID+'_3-'+assetID+'.html';
    http.open('get', url);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
   if (http.readyState == 4) {
      document.getElementById("bigPic").innerHTML = http.responseText;
   }
}

function getBigPic(assetID,pageType,nodeID) {
   pageType = (pageType) ? pageType : 2244;
   nodeID = (nodeID) ? nodeID : 12;
   if (neGetCookie("isFlash7")) {
      openBigPic(assetID,nodeID,pageType);
   } else {
      var flashVersion = getFlashVersion();
      if (flashVersion >= requiredVersion) {
         openBigPic(assetID,nodeID,pageType);
         neSetCookie("isFlash7",1);
      } else if (flashVersion == 0) {
         document.getElementById("bigPic").innerHTML = '<div id="upgradeFlash"><h3>Install Flash 7 and get the Big Picture!<\/h3><p>The Big Picture is a new feature which requires Flash 7. The Big Picture displays the relationship between the newsmakers, companies, and topics reported here at News.com. <a href="http:\/\/bigpicture.news.com\/" target="_blank">Learn more about the Big Picture.<\/a><\/p><p><a href="http:\/\/www.macromedia.com\/go\/getflashplayer">Please upgrade to the latest version of the Flash Player. <\/a><\/p><\/div>';
      } else if (flashVersion >= 0) {
         document.getElementById("bigPic").innerHTML = '<div id="upgradeFlash"><h3>Upgrade to Flash 7 and get the Big Picture!<\/h3><p>The Big Picture is a new feature which requires Flash 7. The Big Picture displays the relationship between the newsmakers, companies, and topics reported here at News.com. <a href="http:\/\/bigpicture.news.com\/" target="_blank">Learn more about the Big Picture.<\/a><\/p><p><a href="http:\/\/www.macromedia.com\/go\/getflashplayer">Please upgrade to the latest version of the Flash Player. <\/a><\/p><\/div>';
      } else if (flashVersion < 0 || flashVersion == null) {
         document.getElementById("bigPic").innerHTML = '<div id="upgradeFlash"><p>This browser does not support Javascript-based Flash detection.</p> <h3>Upgrade to Flash 7 and get the Big Picture!<\/h3><p>The Big Picture is a new feature which requires Flash 7. The Big Picture displays the relationship between the newsmakers, companies, and topics reported here at News.com. <a href="http:\/\/bigpicture.news.com\/" target="_blank">Learn more about the Big Picture.<\/a><\/p><p><a href="http:\/\/www.macromedia.com\/go\/getflashplayer">Please upgrade to the latest version of the Flash Player. <\/a><\/p><\/div>';
      }
   }
}

