//GLOBAL OBJECTS / VARIABLES
//object:objAgent, location:/js/getAgent.js

//global variables and parameters
var pluginRequired = 5;			//required verison 5.0
var pluginName = false;			//name
var pluginDescription = false;	//description
var pluginFileName = false;		//name of file
var pluginVersion = false;		//verion
var pluginInstalled = false;    //installed
var pluginEnabled = false;		//enabled

var bPlugins = (navigator.plugins) ? true : false; //detect plugins Array
var bMimeTypes = (navigator.mimeTypes && navigator.mimeTypes.length) ? true : false; //detect mimetypes Array
var bVB = ((objClient.platform == "win") && (objClient.application == "ie") && (!(objClient.applicationMinor == "op"))) ? true : false; //detect vb script use for MS IE windows and exclude opera

//Create the object
var objFlash = new objFlash();

function objFlash() {
	this.pluginRequired = pluginRequired; //add param to object
	//	loop throgh the plugins array (if supported)
	if ((bPlugins) && (!(bVB))) {
		for (i = 0; i < navigator.plugins.length; i ++) {
			// if the plugin is found then collect the details
			if (navigator.plugins[i].name.indexOf("Shockwave Flash") != -1) {
				pluginName = navigator.plugins[i].name;
				pluginDescription = navigator.plugins[i].description;
				pluginFileName = navigator.plugins[i].filename;
				pluginVersion =	parseInt(pluginDescription.charAt(pluginDescription.indexOf(".") -1));
				if(isNaN(pluginVersion)) { //if the description does not contain the version check the name (mac)
					pluginVersion = parseInt(pluginName.charAt(pluginName.indexOf(".") -1));
				}
				pluginInstalled = true;
				pluginEnabled = true;
				if(pluginVersion >= pluginRequired) {
					break;
				}
			}
		}
	}

	//	loop throgh the mimetypes array (if supported and the above condition fails)
	else if ((!(bPlugins)) && (bMimeTypes) && (!(bVB))) {
		for (i = 0; i < navigator.mimeTypes.length; i ++) {
			// if the plugin is found then collect the details
			if (navigator.mimeTypes['application/x-shockwave-flash'] &&  navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
				pluginName = navigator.mimeTypes[i].name;
				pluginDescription = navigator.mimeTypes[i].description;
				pluginEnabled = (navigator.mimeTypes[i].enabledPlugin) ? true : false;
				pluginInstalled = true;
				break;
			}
		}
	}

	//if neither collection is present and the browser is not win ie we cant detect it
	else if ((!(bPlugins && bMimeTypes)) && (!(bVB))) {
		 pluginVersion = "unknown";
	}

	//use VB for browsers that do not support the plugins object or the mimetypes array
	else {
		checkFlashVB();
	}

	//ok were done lets add what we know to our custom object
	this.pluginName = pluginName;
	this.pluginDescription = pluginDescription;
	this.pluginFileName = pluginFileName;
	this.pluginVersion = pluginVersion;
	this.pluginInstalled = pluginInstalled;
	this.pluginEnabled = pluginEnabled;
}

function checkFlashVB() {
	document.write('<script language="VBScript"> \n');
		document.write('On Error Resume Next \n');
		document.write('Dim intMaxVersion \n');
		document.write('intMaxVersion = 0 \n');
		document.write('For i = 1 to 10 \n');
			document.write('If Not(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & i))) Then \n');	
			document.write('Else \n');
				document.write('intMaxVersion = i \n');			
			document.write('End If \n');		
		document.write('Next \n');
		document.write('pluginVersion = intMaxVersion \n');		
	document.write('</script> \n');
}
