function $(id)
{
	return document.getElementById(id);
}

/*--------------------------------------*/
/* 		FLASH PLAYER MANAGEMENT			*/
/*--------------------------------------*/

var player;
var player_obj;


/*
* initialize flash player
* 
* param url_libs - url to obtain flash player source and config file
* param url_file
*/
function init_mediaplayer(url_libs, url_file, skinName)
{
	player = new SWFObject(url_libs + "mediaplayer.swf","flashplayer","500","430","0");
	player.addParam('allowscriptaccess','always');
	player.addParam('allowfullscreen','true');
	player.addParam('wmode','opaque');
	// player configuration
	player.addVariable('config', url_libs + 'config.xml');
	player.addVariable('skin', url_libs + 'skins/' + skinName + '.swf');
	if( url_file != '' )
	{	
		player.addVariable("file", url_file);
	}
	else
	{
		player.addVariable("file", url_libs + "default.flv");
	}
	player.write("player_container");
	player.launch_next = 0;
}


function playerReady(obj) {
	var id = obj['id'];
	var version = obj['version'];
	var client = obj['client'];
	player_obj = $(id);
	player_obj.addModelListener('STATE', 'checkStateMovie');
	player_obj.addControllerListener('PLAYLIST', 'launchFirst');
};

/*
* change movie file
*/
function change_flv(xml_file, play)
{
	if( player_obj != null )
	{
		player_obj.sendEvent("LOAD",xml_file);
	}
}

/*
* retrieve all state update on the player
*/
function checkStateMovie(obj)
{
	if( obj.newstate == 'COMPLETED' )
	{
		player.launch_next = 1;
	}
}

function launchFirst(obj)
{
	player_obj.sendEvent('ITEM',0);
}


/*--------------------------------------*/
/* 		INTERACTION MANAGEMENT			*/
/*--------------------------------------*/

function change_selected_item( id_item )
{
	// retrieves all the link in the list parent of the current link
	var li_item = $(id_item).parentNode.getElementsByTagName('li');
	
	for( var i = 0; i<li_item.length; i++)
	{
		if( li_item[i].id == id_item )
		{
			Element.addClassName(li_item[i],"selected");
		}
		else
		{
			Element.removeClassName(li_item[i],"selected");
		}
	}
	
	
}
