var mozProtocol = 'application/x-veohtvplugin';
var ieClassId = 'CLSID:AADAA41D-FFD5-4F38-B35A-8CA640D6C037';
var mozId = 'objNPVeohTVPlugin';	// identify embeds that talk with Web plugin
var ieId = 'objVeohVersion';

var mozName = 'NPVeohVersion plugin'; // Mozilla's name for the plugin the the Navigator.plugins array
var activeXName = 'VeohClientVersion.VeohVersion'; // IE's activeX name for the plugin. Could be an array.

var mozName5 = 'VeohTV Plugin'; // Mozilla's -"- for Web Player
var activeXName5 = 'VeohTV2Version.VeohTV2Version'; // IE's -"- for Web Player

//check for veoh client (pre + post 3.4.2)
function isVeohInstalled()
{
	// Is it installed?
	var installed = false;
	
	// Java is a special case
	if (mozName == 'java') 
	{
		if (navigator.javaEnabled()) 
		{ 
			installed = true; 
		}
	}
	else 
	{		
		// If Netscape/Mozilla style, check for the mozName within the navigator array
		if( navigator.plugins && navigator.plugins.length ) 
		{
			for( var i=0; i < navigator.plugins.length; i++ ) 
			{
				var plugin = navigator.plugins[i];
				var pluginName = plugin.name.toLowerCase();
				
				if( pluginName.indexOf(mozName.toLowerCase()) > -1 ) 
				{ 
					installed = true;	
				}
			}			
		}
		else 
		{
			// Otherwise if we are in IE, try and create an ActiveX object
			var qtObj = false;
			
			try 
			{
				qtObj = new ActiveXObject( activeXName );
				if( qtObj ) 
				{ 
					installed = true; 
				} 
			}
			catch( e ) 
			{ 
				installed = false;
			}
		}
	}
	
	// Return the correct result
	return installed;
}

/*
 *  Veoh Web Player
 */
function isVeohWebPlayerInstalled() {
	// Is it installed?
	var installed = false;
	
	// If Netscape/Mozilla style, check for the mozName5 within the navigator array
	if( navigator.plugins && navigator.plugins.length ) 
	{
		for( var i=0; i < navigator.plugins.length; i++ ) 
		{
			var plugin = navigator.plugins[i];
			var pluginName = plugin.name.toLowerCase();
			
			if( pluginName.indexOf(mozName5.toLowerCase()) > -1 ) 
			{ 
				installed = true;	
			}
		}	
	}
	else 
	{
		// Otherwise if we are in IE, try and create an ActiveX object
		try 
		{
			qtObj = new ActiveXObject( activeXName5 );
			if( qtObj ) { 
				installed = true;
			} 
		}
		catch( e ) 
		{
			installed = false;
		}
	}
	// Return the correct result
	return installed;
}

function getVeohWebPlayerPort() {
	var p2pPort = ''; 
	if ( document.getElementById(mozId) && typeof document.getElementById(mozId) == 'function' 
			&& document.getElementById(mozId).getP2PPort )
	{
		p2pPort = document.getElementById(mozId).getP2PPort();
	}
	else if ( document.getElementById(ieId) && typeof document.getElementById(ieId) == 'object' ) 
	{
		p2pPort = document.getElementById(ieId).P2PPort;
	}
	
	return p2pPort;
}

function getVeohWebPlayerVersion() {
	var version = '';
	
	if ( document.getElementById(mozId) &&typeof document.getElementById(mozId) == 'function' 
			&& document.getElementById(mozId).getVersion)
	{
		version = document.getElementById(mozId).getVersion();
	}
	else if ( document.getElementById(ieId) && typeof document.getElementById(ieId) == 'object' ) 
	{
		version = document.getElementById(ieId).Version;
	}
	
	return version;
}

function getWebPlayerPluginHtml() {
	var html = '<object id="'+ieId + '" classid="' + ieClassId + '">' +
	'<embed id="'+ mozId + '" height="1" width="1" type="'+ mozProtocol + '"/></object>';
	return html;
}