/**
 * playlist.js
 *
 * This belongs to the flowplay2 plugin for dokuwiki. It is somewhat based on the 
 * embeding example on flowplayer.org.
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @version    0.3
 * @author     bSpot <blind@bspot.de>
 */

// Flowplayer configuration 
var playerConfig = 
{ 
	controlBarBackgroundColor: '0x99cddc'
} 

var embedConfig =
{
	bgcolor:'#6F7485',
	width: 320,
	height: 240
}

// variable that holds the player API. it is initially null 
var flowplayerobject = null;


// runs url in flowplayer
function runFlowPlayer(url)
{
	// set URL
	playerConfig.videoFile = url; 
	
	// if flowplayer is not loaded. load it now. 
	if (flowplayerobject == null) 
	{ 
		// create Flowplayer instance into DIV element whose id="player" 
		// Flash API is automatically returned (flashembed.js ver. 0.27) 
		flowplayerobject = flashembed
		(
			"flowplayer",
			embedConfig,
			{config: playerConfig} 
		);
		
	} 
	// flowplayer is already loaded - now we simply call setConfig() 
	else 
	{
		flowplayerobject.setConfig(playerConfig);  
	} 
}


window.onload = function() 
{ 
	var links = document.getElementsByTagName("a");  
	for (var i = 0; i < links.length; i++) 
	{
		if (links[i].className == "flowplayitem") 
		{
			links[i].onclick = function() 
			{  
				playerConfig.autoPlay = true;
				runFlowPlayer(this.getAttribute("href"));
				
				// disable link's default behaviour 
				return false;  
			}
		}
	} 
	
	// start player if url is given
	if (playerConfig["videoFile"])
		runFlowPlayer(playerConfig["videoFile"]);
	
	// when user presses splash image it triggers our first playlist entry 
	if (document.getElementById("splash"))
		document.getElementById("splash").onclick = function()  
		{ 
			links[0].onclick(); 
		} 
}

