/*
This library handles video player detection for Plugins and ActiveX controls.

For activeX detection the axdetect.vbs script should also be included in the page.
*/
function detection_all()
{
	var player = {
		real: detection_realPlayerVersion(),
		windowsmedia: detection_windowsMediaVersion(),
		quicktime: detection_quickTimeVersion(),
		shockwave: detection_shockwaveVersion(),
		flash: detection_flashVersion()
	};
	return player;
}

function detection_realPlayerVersion()
{
	return parseFloat(RealPlayer_detection());
}

function detection_windowsMediaVersion()
{
	return parseFloat(((browser_ie() && !browser_mac())||browser_axcomp()) ? WMPlayer_detection() : detection_windowsMediaNsVersion());
}

function detection_quickTimeVersion()
{
	return parseFloat((browser_ie() && !browser_mac()) ? detection_quickTimeAxVersion() : detection_quickTimeNsVersion());
}

function detection_shockwaveVersion()
{
	return parseFloat((browser_ie() && !browser_mac()) ? detection_shockwaveAxVersion() : detection_shockwaveNsVersion());
}

function detection_flashVersion()
{
	return parseFloat((browser_ie() && !browser_mac()) ? detection_flashAxVersion() : detection_flashNsVersion());
}

//***************************
// Netscape detection,
// returns the version of wm plugin found or 0.0

function detection_windowsMediaNsVersion() {
	// this function returns a floating point value which should be the version of the Windows
	// Media plugin or 0.0
	// this function only returns useful information if called from Netscape or IE Mac 5.0+

	// Set these local variables to avoid the Netscape 4 crashing bug.
	var thearray = navigator.plugins
	var arraylen = thearray.length

	// Step through each plugin in the array.
	for (var i=0; i < arraylen; i++) {
		// Set these local variables to avoid the Netscape 4 crashing bug.
		var theplugin = thearray[i]
		var thename	 = theplugin.name
		var thedesc	 = theplugin.description
		//txt = txt + theplugin.name +' : '+ theplugin.description + ' <br>';
		
		if (thename.indexOf("Windows Media") != -1 &&
			(thename.indexOf("Player") != -1 || thename.indexOf("Plugin") != -1)) {
			return 1.0;
		}
	}
	return 0.0;
}

//***************************
// Netscape detection,
// returns the version of qt plugin found or 0.0

function detection_quickTimeNsVersion() {
	// this function returns a floating point value which should be the version of the Shockwave plugin or 0.0
	// this function only returns useful information if called from Netscape or IE Mac 5.0+

	// Set these local variables to avoid the Netscape 4 crashing bug.
	var thearray = navigator.plugins
	var arraylen = thearray.length

	// Step through each plugin in the array.
	for (var i=0; i < arraylen; i++) {
		// Set these local variables to avoid the Netscape 4 crashing bug.
		var theplugin = thearray[i]
		var thename	 = theplugin.name
		var thedesc	 = theplugin.description
		// QuickTime Plug-in 4.1.2

		// If the plugin is Shockwave...
		if (thename.indexOf("QuickTime") != -1) {
			var versionString = thename.substring(thename.indexOf("Plug-in ") + 8);
			if (versionString.indexOf(".") > 0) {
				var versionMajor = versionString.substring(0,versionString.indexOf("."));
				var versionMinor = versionString.substring(versionString.indexOf(".") + 1);
				if (versionMinor.indexOf(".") > 0) versionMinor = versionMinor.substring(0,versionString.indexOf(".")) + versionMinor.substring(versionMinor.indexOf(".") + 1)
				return parseFloat(versionMajor + "." + versionMinor);
			}
			//else return parseFloat(versionString);
		}
	}
	return 0.0;
}

//*********************************
function detection_shockwaveNsVersion()
{
  // this function returns a floating point value which should 
  // be the version of the Shockwave plugin or 0.0 this function 
  // only returns useful information if called from Netscape or 
  // IE Mac 5.0+

  // Set these local variables to avoid the Netscape 4 crashing bug.
  var thearray = navigator.plugins
  var arraylen = thearray.length

  // Step through each plugin in the array.
  for (var i=0; i < arraylen; i++)
  {
    // Set these local variables to avoid the Netscape 4 crashing bug.
    var theplugin = thearray[i]
    var thename   = theplugin.name
    var thedesc   = theplugin.description
    
    // If the plugin is Shockwave...
    if (thename.indexOf("Shockwave") != -1 && thename.indexOf("Director") != -1)
    {
      var versionString = thedesc.substring(thedesc.indexOf("version ") + 8);
      
      if (versionString.indexOf(".") > 0)
      {
        var versionMajor = versionString.substring(0,versionString.indexOf("."));
        var versionMinor = versionString.substring(versionString.indexOf(".") + 1);
        
        if (versionMinor.indexOf(".") > 0)
        {
        	versionMinor = versionMinor.substring(0,versionString.indexOf(".")) 
        		+ versionMinor.substring(versionMinor.indexOf(".") + 1)
        }
        
        return parseFloat(versionMajor + "." + versionMinor);
      }
      
      else return parseFloat(versionString);
    }
  }
  
  return 0.0;
}

//***************************
// Netscape detection,
// returns the version of flash plugin found or 0.0

function detection_flashNsVersion()
{
  // this function returns a floating point value which should be the version of the Shockwave plugin or 0.0
  // this function only returns useful information if called from Netscape or IE Mac 5.0+

  // Set these local variables to avoid the Netscape 4 crashing bug.
  var thearray = navigator.plugins
  var arraylen = thearray.length

  // Step through each plugin in the array.
  for (var i=0; i < arraylen; i++) {
    // Set these local variables to avoid the Netscape 4 crashing bug.
    theplugin = thearray[i]
    thename   = theplugin.name
    thedesc   = theplugin.description

    // If the plugin is Flash...
    if (thename.indexOf("Shockwave") != -1 && thename.indexOf("Flash") != -1)
    {
		var versionString = thedesc.substring(thedesc.indexOf("Flash ") + 6);
		
		// Look for an " r".  Whatever's after the "r" is the minor version. For
		// example, "Flash 4.0 r12" is minor release 12 of Flash 4.
		var versionLoc = versionString.indexOf(" r");
		
		if (versionLoc != -1)
		{
			// If there is an "r", then everything before the " r" is the major version...
			var versionMajor = versionString.substring(0,versionLoc);
			
			// ...and everything after is the minor version.
			var versionMinor = parseInt(versionString.substring(versionLoc + 2));
			
			// pad with zeroes
			if (versionMinor < 10) versionMajor += "0";
			
			// Format the final version string as x.xyy where x.x is the major version
			// and yy is the minor release version.
			
			return parseFloat(versionMajor + versionMinor);
		}
		else return parseFloat(versionString);
    }
  }
  
  return 0.0;
}

//***************************
// For detecting the ActiveX of players for ie win.
// Requires a vbscript function be included on the page
// to do the actual checking returns version found or 0.0

function detection_quickTimeAxVersion() {
	// this function returns a floating point value which should be the version of the Shockwave control or 0.0
	// this function should only be called from Internet Explorer for Windows
	// loop backwards through the versions until we get a bite
	for (var i=3;i>0;i--) {
		var versionNum = VBGetQuicktimeVersion(i);
		if (versionNum != 0) {
			return 1.0;
		}
	}
	return 0.0;
}

function detection_shockwaveAxVersion()
{
	// This function returns a floating point value which should be the version 
	// of the Shockwave control or 0.0 this function should only be called from
	// Internet Explorer for Windows loop backwards through the versions until
	// we get a bite
	for (var i=8;i>0;i--) {
		var versionString = VBGetShockwaveVersion(i);
		// if we get 1.0 we assume it is actually 6.0 or less
		if (versionString != "0.0") return (versionString == "1.0" ? 6.0 : parseFloat(versionString));
	}
	return 0.0;
}

function detection_flashAxVersion()
{
	// This function returns a floating point value which should 
	// be the version of the Shockwave control or 0.0.
	// This function should only be called from Internet Explorer
	// for Windows.

    // loop backwards through the versions until we get a bite
	for (var i=8;i>0;i--)
	{
		var versionNum = VBGetFlashVersion(i);
		if (versionNum != 0)
		{
			var versionMajor = Math.floor(versionNum / 65536);
			var versionMinor = versionNum % 65536;
			var versionMiddle = ".";
			for (var i=100;i>5;i/=10) if (versionMinor < i) versionMiddle += "0";
			return parseFloat(versionMajor + versionMiddle + versionMinor);
		}
	}
	return 0.0;
}