<?xml version="1.0" encoding="utf-8" ?>
<Module>
	<ModulePrefs title="Nimbb" height="240">
		<Require feature="wave" />
	</ModulePrefs>
	<Content type="html">
		<![CDATA[ 

<table>
<tr>
<td>
<div id="nimbb"></div>
</td>
<td>
<div id="state"></div>
</td>
</tr>
</table>

<script type="text/javascript">

//-----------------------------------------------------------------------------
// Global variables.
//-----------------------------------------------------------------------------
var _Nimbb;

//-----------------------------------------------------------------------------
// Nimbb Events.
//-----------------------------------------------------------------------------
function Nimbb_initCompleted(idPlayer)
{
	// Get a reference to the player.
	_Nimbb = document[idPlayer];
}

function Nimbb_videoSaved(idPlayer)
{
	// Get the saved video GUID.
	var guid = _Nimbb.getGuid();
	   
	// Store it to the wave.
	if( guid != null )
	{
		wave.getState().submitDelta({'guid': guid});
	}
}

//-----------------------------------------------------------------------------
// init() : get the wave ready.
//-----------------------------------------------------------------------------
function init() {
	wave.log("Nimbb gadget init...");
	
	// Make sure wave is ready.
	if (wave && wave.isInWaveContainer())
	{
		wave.log("wave container ready.");
		wave.setStateCallback(stateUpdated);
	}
}

//-----------------------------------------------------------------------------
// stateUpdated() : state of the wave changed.
//-----------------------------------------------------------------------------
function stateUpdated() {
	
	var host = wave.getHost();
	var viewer = wave.getViewer();
	var guid = wave.getState().get('guid', null);
	var div_nimbb = document.getElementById('nimbb');
	var div_state = document.getElementById('state');
	
	// First, check if the video has been recorded.
	if( guid == null )
	{
		// No video yet, check if this is the host.
		if( host.getId() == viewer.getId() )
		{
			// Only the host is allowed to record a video.
			div_nimbb.innerHTML = '<object id="nimbb" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="320" height="240" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="movie" value="http://player.nimbb.com/nimbb.swf?mode=record" /><param name="allowScriptAccess" value="always" /><embed name="nimbb" src="http://player.nimbb.com/nimbb.swf?mode=record" width="320" height="240" allowScriptAccess="always" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object>';  
			div_state.innerHTML = 'Record your video and click Save to share the video.';
		}
		else
		{
			div_nimbb.innerHTML = '';
			div_state.innerHTML = '<img src="' + host.getThumbnailUrl() + '"> ' + host.getDisplayName() + ' is recording a Nimbb video.';
		}
	}
	else
	{
		div_nimbb.innerHTML = '<object id="nimbb" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="320" height="240" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="movie" value="http://player.nimbb.com/Nimbb.swf?guid=' + guid + '" /><param name="allowScriptAccess" value="always" /><embed name="nimbb" src="http://player.nimbb.com/Nimbb.swf?guid=' + guid + '" width="320" height="240" allowScriptAccess="always" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object>';
		div_state.innerHTML = '<a href="http://nimbb.com/v/' + guid + '" target="_blank">http://nimbb.com/v/' + guid + '</a>';
	}
}

//-----------------------------------------------------------------------------
// Register handlers.
//-----------------------------------------------------------------------------
gadgets.util.registerOnLoadHandler(init);

</script>
		]]>
</Content>
</Module>
