/** 
* Object which holds all the functions which are detecting plugins 
* 
* usage: 
* <pre>
* var x = new pluginDetect(); 
* 
* if (x.isPlugin("ShockwaveFlash.ShockwaveFlash.7","Shockwave Flash 7.0")) { 
* 	document.write("flash found.. flash developers are happy!\n"); 
* }
*
* if (x.isPlugin("MediaPlayer.MediaPlayer","Windows Media Player")) { 
*	document.write("media player found.. let's watch a movie?\n"); 
* }
* </pre>
* 
*/ 
function pluginDetect() { 
	this.IE =  (navigator.userAgent.toLowerCase().indexOf("msie") != -1) ? true : false; 
}


/** 
* Function which determines the browser client is using 
* and returns true if the plugin is installed (else false) 
* 
* @argument classsID  object name to look for (i.e. ShockwaveFlash.ShockwaveFlash.7) 
* @argument pluginName the name to look for in plugin list 
*
*/ 
pluginDetect.prototype.isPlugin = function(classID,pluginName) { 
	res = false;
	return res = (this.IE) ? this.plugin_detectIE(classID) : this.plugin_detectMo(pluginName); 
}


/**
* Function for Plugin detection in IE 
* The function is trying to create an ActiveX object in VB 
* if the created object exists return true otherwise return false!
* 
* @argument ClassID object name to look for (i.e. ShockwaveFlash.ShockwaveFlash.7) 
*
*/ 
pluginDetect.prototype.plugin_detectIE = function (ClassID) { 
	// status 
	ret = false; 
	document.write('<SCRIPT LANGUAGE=VBScript>\n'
	// resumes if an error is showed 
	+ 'on error resume next\n' 
	// try to create an object with given class name 
	// return true or false if the plugin is found 
	+ 'ret = IsObject(CreateObject("' + ClassID + '"))\n' 
	+ '</SCRIPT>\n');
	return ret;
}

/**
* Function for Plugin detection in Non IE browsers 
* Usualy Non IE browsers have a special object called navigator.plugins which contains 
* all the plugins supported by browser. The function loops through the object and 
* searches for the specific plugin 
*
* @argument pluginName the name to look for in plugin list 
*/ 
pluginDetect.prototype.plugin_detectMo = function (pluginName) {
	// plugin which contains all the objects
	var pluginObj = navigator.plugins; 
	// make a loop through the object
	for (i = 0; i < pluginObj.length;i++)  { 
		// search the plugin 
		if (pluginObj.item(i).name.search(pluginName) >= 0 || pluginObj.item(i).description.search(pluginName) >= 0) 
			return true; 
	}
	
	return false; 
	
}
