
	// ------------------------------------------------
	// loader
	var mediaPluginObject1 = '<object id="CommuniGateAV" classid="clsid:FA1F9352-0B8B-431D-BB18-7A3457F696F4" codebase=';
	var mediaPluginObject2 = ' ></object>';
	var mediaPluginURL = 'www.communigate.com/MediaPlugin/1.0/CGateAVX.cab';
	var isHttps = false;
	var checkTimer;
	
	function setHttps( https )
	{
		isHttps = https;
	}
	
	function loadMediaPlugin( version )
	{
		clearInterval(checkTimer);
		checkTimer = setInterval("checkLoaded();", 200);
		var httpStr = isHttps ? "https://" : "http://";
		var obj = mediaPluginObject1+'"'+httpStr+mediaPluginURL+'"'+mediaPluginObject2;
		document.getElementById("MediaPlugin").innerHTML = obj;
		
		return obj;
	}

	// checks if plugin is loaded
	function checkLoaded()
	{
		switch(typeof CommuniGateAV)
		{
			case 'undefined':
				break;
			case 'object':
				if(typeof CommuniGateAV.GetVersion != 'undefined' )
				{
					clearInterval(checkTimer);
					pronto.mediaPluginInitialized();
				}
				break;
		}
	}




	// ------------------------------------------------
	// methods

	function traceResult( operationResult )
	{
		if( operationResult == "" )
		{
			return "OK";
		}
		else
		{
			return operationResult;
		}
	}
	

	// legs methods	

	function createLeg( leg )
	{
		return traceResult( CommuniGateAV.CreateLeg(leg,"","") );
	}
	function activateLeg( leg )
	{
		return traceResult( CommuniGateAV.Activate(leg) );
	}

	function destroyLeg( leg )
	{
		return traceResult( CommuniGateAV.DestroyLeg(leg) );
	}
	function deactivateLeg( leg )
	{
		return traceResult( CommuniGateAV.Deactivate(leg) );
	}
	
	function setHold( leg, flag )
	{
		return traceResult( CommuniGateAV.SetHold(leg, flag) );
	}

	// sfp methods	

	function getLocalSDP( leg )
	{
		return traceResult( CommuniGateAV.GetLocalSDP(leg,"xml") );
	}
	
	function setRemoteSDP( leg, sdp )
	{
		return traceResult( CommuniGateAV.SetRemoteSDP(leg, sdp, "xml") );
	}
	
	
	function sendDTMF(leg, symbol )
	{
		return traceResult( CommuniGateAV.SendDTMF(leg, symbol) );
	}
	
	// play, volume methods	

	function playToLocal(leg, data, loop)
	{
		return traceResult( CommuniGateAV.PlayToLocal(leg, data, loop) );
	}
	function playToRemote(leg, data, loop)
	{
		return traceResult( CommuniGateAV.PlayToRemote(leg, data, loop) );
	}
	
	function setInputVolume(leg, level)
	{
		return traceResult( CommuniGateAV.SetInputVolume(leg, level) );
	}
	function setOutputVolume(leg, level)
	{
		return traceResult( CommuniGateAV.SetOutputVolume(leg, level) );
	}
	
	// connection  properties	

	function setLocalIP(ip)
	{
		return traceResult( CommuniGateAV.SetLocalIP(ip) );
	}
	function setLocalPorts(ip)
	{
		return traceResult( CommuniGateAV.SetLocalPorts(from, till, true) );
	}
	
	
	function getVersion()
	{
		return CommuniGateAV.GetVersion();
	}
	

	// advanced methods	
	
	function listDevices()
	{
		return CommuniGateAV.ListDevices("audioInput")+"; "+CommuniGateAV.ListDevices("audioOutput");
	}
	
	function setLogLevel( logLevel )
	{
		return traceResult( CommuniGateAV.SetLogLevel(logLevel) );
	}
	
