/**
 * Class Detection
 * 
 * Detects the video and audio plugins installed by a client and
 * sets, acording to this, the availability and version membervariables
 * of the media inside the mediacollection.
 * 
 * The underscore is used to declare classes, attributes and methods 
 * as private by naming convention.
 * 
 * Created:		2009_09-24	
 * Modified:	2009_09-24
 *
 * @version 0.1
 * @author Jan Völker
 * @copyright ARD.de
 */

/** 
 * Class constructor
 * @access public
 * @param void
 * @return Detection
 */
var PluginDetection = function(mediaCollection) {
	this._pluginFound = false;
	this._detectClientPlugins(mediaCollection);
};

PluginDetection.prototype = {
	/** 
	 * Detect installed plugins and enable media in the mediacollection
	 * @access private
	 * @param object MediaCollection
	 * @return void
	 */
	_detectClientPlugins: function(mediaCollection) {
		var pluginArray = new Array(
			this._detectFlashPlugin(), 
			this._detectSilverlightPlugin(), 
			this._detectWmPlugin()
		);
		for (var i in pluginArray) {
			if (pluginArray[i] != false && mediaCollection.getMediaArray()[i] != false) 
			{
				mediaCollection.enablePlugin(i, pluginArray[i]);
				this._pluginFound = true;
			}
		}
	},
	
	/** 
	 * Detect Flash plugin and version. 
	 * Version 9.0.115.0 is the minimum needed for H.264 playback
	 * @access private
	 * @param void
	 * @return string/boolean Versionnumber/false
	 */
	_detectFlashPlugin : function() {
		// has Flash version 9.0.115.0 or higher
		if (swfobject.hasFlashPlayerVersion("9.0.115.0")) {
			var playerVersionObject = swfobject.getFlashPlayerVersion();
			var playerVersion = playerVersionObject.major + "." + 
				playerVersionObject.minor + "." + 
				playerVersionObject.release;
			return playerVersion;
		}
		// no Flash
		else {
			return false;
		}
	},	
	/** 
	 * Detect Silverlight plugin and version. 
	 * @access private
	 * @param void
	 * @return string/boolean Versionnumber/false
	 */
	_detectSilverlightPlugin : function() {
		if(Silverlight.isInstalled("3")) {
			return "3";
		}
		else {
			return false;
		}
	},
	/** 
	 * Detect WindowsMedia plugin and version. 
	 * @access private
	 * @param void
	 * @return string/boolean Versionnumber/false
	 */
	_detectWmPlugin : function() {
		if(isWMPInstalled()){
			return "version n/a";
		}
		else {
			return false;
		}
	},	
	/** 
	 * Check if a usable Plugin is found 
	 * @access public
	 * @param void
	 * @return boolean 
	 */
	pluginFound : function() {
		return this._pluginFound;
	}
};
