/*
	detect object

	called by function, like this: detect.flash.installed();

*/

var detect = {};
function detectionObject(type)
{
	this.type = type;
	this.isPlugin = false;
	this.requireVersion;
	this.getPlugin = new Function("return get" + this.type + "Plugin(this.requireVersion)");
	this.installed = new Function("return get" + this.type + "Installed()");
	this.version = new Function("return get" + this.type + "Version()");
}

/* Browser and Platform stuff */
detect.browser = {};
detect.platform = {};
detect.browser.getWidth = function()
{
	if (document.all)
	{
		if (document.body)
		{
			return document.body.clientWidth;
		}
		else
		{
			return -1;
		}
	}
	else
	{
		return window.innerWidth;
	}
}
detect.browser.width = detect.browser.getWidth();
detect.browser.getHeight = function()
{
	if (document.all)
	{
		if (document.body)
		{
			return document.body.clientHeight;
		}
		else
		{
			return -1;
		}
	}
	else
	{
		return window.innerHeight;
	}
}
detect.browser.height = detect.browser.getHeight();

detect.browser.ie = false;
if (document.all)
{
	detect.browser.ie = true;
}

detect.platform.pc = navigator.platform=="Win32";
detect.platform.mac = navigator.platform.indexOf("Mac")>-1;

var pcie = false;

if (detect.browser.ie) {
    if (detect.platform.pc) {
        detect.browserOs = 'ieWin';
        pcie = true;
    }
    else
        detect.browserOs = 'ieMac';
}
else {
    if (detect.platform.pc)
        detect.browserOs = 'netWin';
    else
        detect.browserOs = 'netMac';
}

if (navigator.userAgent)
{
	if (navigator.userAgent.indexOf('NT 5.0')>-1)
	{
		detect.platform.os = 'Win2000';
	}
}

detect.platform.winVersion = getWinVersion();
detect.browser.ieVersion = getIEVersion();

function getWinVersion()
{
	var rv = -1; // Return value assumes failure
	if (navigator.userAgent.indexOf("Windows") != -1) 
	{
    var ua = navigator.userAgent;
    var re  = new RegExp("Windows NT ([5-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function getIEVersion()
{
  var rv = -1; // Return value assumes failure
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

detect.showPlugins = new Function("getShowPlugins()");
detect.showAll = new Function("getShowAll()");
function getShowPlugins()
{
	for (a in detect)
	{
			if (detect[a].isPlugin)
			{
				document.write("<b>" + detect[a].type + '</b><br>');
				document.write("Installed: <b>" + detect[a].installed() + "</b>");
				document.write("Version: <b>" + detect[a].version() + "</b><P>");
			}
	}
}
function getShowAll()
{
	detect.showPlugins();
	document.write("detect.browser.ie " + detect.browser.ie + "<br>");
	document.write("detect.platform.pc " + detect.platform.pc + "<br>" );
	document.write("pcie " + pcie + "<br>");
}

// VBscript functions
if (pcie)
{
	document.write('<SCRIPT LANGUAGE="VBScript" src="/dynamo/droplets/detect/detectvbs.js"></script>');
}

//
// Flash
//
detect.flash =  new detectionObject('flash');
detect.flash.isPlugin = true;
//some defaults. these are meant to be overridden
function getflashPlugin(version){}
detect.flash.minVersion = 3;
detect.flash.maxVersion = 10;

// functions
function getflashInstalled(obj)
{
	out = false;
	if (getflashVersion()>0)
	{
		out = true;
	}
	return out;
}
function getflashVersion()
{
	var min = detect.flash.minVersion;
	var max = detect.flash.maxVersion;
	var version = null;
	if (pcie)
	{
		// Call VBscript for PC IE
		version = vbGetFlashVersion(min,max);
	}
	else
	{
		if(navigator.plugins.length)
		{
			var i;
			//loop through all the plugins installed
			for (i=0; i < navigator.plugins.length; i++)
			{
				//put the plugin string in a variable
				var pluginIdent = navigator.plugins[i].description.split(" ");
				//The Flash Player identification string is ([] = the array index) [0]Shockwave [1]Flash [2]6.0 [3]r21
				
				if(pluginIdent[0] == "Shockwave" && pluginIdent[1] == "Flash")
				{
					//an array of the Flash version number (major.minor)
					var versionArray = pluginIdent[2].split(".");
					version = versionArray[0]; // get major version
					break; //need to break this loop as some browsers may have two versions installed
				}
			}
		}
	}
	
	return version;
}


//
// Virtools
// author: Dhimiter Bozo
// Date: 11/10/2005
//
detect.virtools =  new detectionObject('virtools');
detect.virtools.isPlugin = true;
//some defaults. these are meant to be overridden
//version numbers are not needed since the plugin updates itself
function getvirtoolsPlugin(version){}
function getvirtoolsVersion() {} // this is not yet implemented, but needs to be here
detect.virtools.minVersion = 1;
detect.virtools.maxVersion = 1000;

// functions
function getvirtoolsInstalled(obj)
{
	var installed = null;
	
	if (pcie)
	{
		// Call VBscript for PC IE
		
		installed = vbGetVirtoolsVersion();
	}
	else
	{
		if(navigator.plugins.length)
		{
			var i;
			//loop through all the plugins installed
			for (i=0; i < navigator.plugins.length; i++)
			{
				//put the plugin string in a variable
				var pluginIdent = navigator.plugins[i].description.split(" ");
								
				if(pluginIdent[0] == "Virtools")
				{
					installed = true
					break; //need to break this loop as some browsers may have two versions installed
				}
			}
		}
	}
	
	return installed;
}

/*
	Shockwave
	Version numbers aren't accurate
*/
detect.shockwave =  new detectionObject('shockwave');
detect.shockwave.isPlugin = true;

//some defaults. these are meant to be overridden
function getshockwavePlugin(){}
detect.shockwave.minVersion = 3;
detect.shockwave.maxVersion = 100;

// functions
function getshockwaveInstalled(obj)
{
	out = false;
	//alert("shockwave version: " + getshockwaveVersion());
	if (getshockwaveVersion()>0)
	{
		out = true;
	}
	return out;
}
function getshockwaveVersion()
{
	var min = detect.shockwave.minVersion;
	var max = detect.shockwave.maxVersion;
	var version = null;
	if (pcie)
	{
		// Call VBscript for PC IE
		version = parseInt(vbGetShockwaveVersion(min,max));
	}
	else
	{
		if (navigator.plugins)
		{
			for ( var i = 0 ; i< navigator.plugins.length ; i++)
			{ 
				if ((navigator.plugins[i].name.indexOf('Shockwave') > -1 )&&(navigator.plugins[i].name.indexOf('Flash') == -1))
				{
					for (var a=min ; a<=max ; a++)
					{
						if ( navigator.plugins[i].description.indexOf(a) > -1 ){version = a }
					}
				}
			}
		}
	}	
	return version;
}

/*
	Real
	G2 version = 3
*/
detect.real =  new detectionObject('real');
detect.real.isPlugin = true;

//some defaults. these are meant to be overridden
function getrealPlugin(){}
detect.real.minVersion = 1;
detect.real.maxVersion = 10;

// functions
function getrealInstalled(obj)
{
	out = false;
	if (getrealVersion()>0)
	{
		out = true;
	}
	return out;
}
function getrealVersion()
{
	var min = detect.real.minVersion;
	var max = detect.real.maxVersion;
	var version = null;
	if (pcie)
	{
		// Call VBscript for PC IE
		version = vbGetRealVersion(min,max);
	}
	else
	{
		if (navigator.plugins)
		{
			for ( var i = 0 ; i< navigator.plugins.length ; i++)
			{ 
				if (navigator.plugins[i].name.indexOf('RealPlayer') > -1 )
				{
					for (var a=min ; a<=max ; a++)
					{
						if ( navigator.plugins[i].name.indexOf(a) > -1 ){version = a }
					}
				}
			}
		}
	}
	return version;
}

/*
	All PCIE versions = 4
	Most NS versions = 3
*/
detect.quicktime =  new detectionObject('quicktime');
detect.quicktime.isPlugin = true;

//some defaults. these are meant to be overridden
function getquicktimePlugin(){}
detect.quicktime.minVersion = 1;
detect.quicktime.maxVersion = 10;

// functions
function getquicktimeInstalled(obj)
{
	out = false;
	if (getquicktimeVersion()>0)
	{
		out = true;
	}
	return out;
}
function getquicktimeVersion()
{
	var min = detect.quicktime.minVersion;
	var max = detect.quicktime.maxVersion;
	var version = null;
	if (pcie)
	{
		// Call VBscript for PC IE
		version = vbGetQuicktimeVersion(min,max);
	}
	else
	{
		if (navigator.plugins)
		{
			var isQuickTime = navigator.mimeTypes &&
			navigator.mimeTypes["video/quicktime"] &&
			navigator.mimeTypes["video/quicktime"].enabledPlugin;
			if ( isQuickTime )
			{
				for (var a=min ; a<=max ; a++)
				{
					if ( isQuickTime.name.indexOf(a) > -1 ){version = a }
				}
				if ( isQuickTime.name.indexOf('4.1') > -1 ) version = 4.1 ;
			}
			if (version == null)
			{
				for ( var i = 0 ; i< navigator.plugins.length ; i++)
				{ 
					if (navigator.plugins[i].name.indexOf('QuickTime') > -1 )
					{
						for (var a=min ; a<=max ; a++)
						{
							if ( navigator.plugins[i].description.indexOf(a) > -1 ){version = a }
						}
					}
				}
			}
		}
	}
	return version;
}

/*
	Windows Media Player
	All versions = 6
*/
detect.wmp =  new detectionObject('wmp');
detect.wmp.isPlugin = true;

//some defaults. these are meant to be overridden
function getwmpPlugin(){}
detect.wmp.minVersion = 1;
detect.wmp.maxVersion = 10;

// functions
function getwmpInstalled(obj)
{
	out = false;
	if (getwmpVersion()>0)
	{
		out = true;
	}
	return out;
}
function getwmpVersion()
{
	var min = detect.wmp.minVersion;
	var max = detect.wmp.maxVersion;
	var version = null;
	if (pcie)
	{
		// Instantiate a wmp object
		document.write('<object WIDTH="1" HEIGHT="1" classid="CLSID:760C4B83-E211-11D2-BF3E-00805FBE84A6" id="DrmStore"></object>');
		document.write('<object ID="WMPlay" WIDTH="1" HEIGHT="1" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE="#Version=6,2,5,410"></object>');
		// Call VBscript for PC IE
		version = vbGetWmpVersion(min,max);
	}
	else
	{
		if (navigator.plugins)
		{
			v = false;
			if(navigator.mimeTypes && navigator.mimeTypes["application/x-drm"] &&  navigator.mimeTypes["application/x-drm"].enabledPlugin){v=true}
			if(navigator.mimeTypes && navigator.mimeTypes["video/x-ms-wm"] &&  navigator.mimeTypes["video/x-ms-wm"].enabledPlugin){v=true}
			if(navigator.mimeTypes && navigator.mimeTypes["video/x-ms-asf-plugin"] && navigator.mimeTypes["video/x-ms-asf-plugin"].enabledPlugin){v=true}
			if (v)
			{
				version = 6;
			}
		}
	}
	return version;
}
