
/*--------------------------------------*/
/* 		FLASH PLAYER MANAGEMENT			*/
/*--------------------------------------*/

var player;

/*
* initialize fllash player
*/
function init_mediaplayer(url_libs,urlVideo)
{
	player = new SWFObject(url_libs + "mediaplayer.swf","flashplayer","500","430","0");
	player.addParam("allowscriptaccess","true");
	player.addParam("allowfullscreen","true");
	player.addParam("wmode","opaque");
	if(urlVideo!='')
	{
		player.addVariable("file", urlVideo );
	}else 
	{
		player.addVariable("file", url_libs + "default_image.jpg");
	}
	// player configuration
	player.addVariable("config", url_libs + "config.xml");
	player.write("player_container");
	player.old_state = 0 ;
	player.new_state = 0 ;
}

/*
* change movie file
*/
function change_flv(xml_file, play)
{
	if( $("flashplayer") )
	{	
		obj={file:xml_file};
		thisMovie("flashplayer").loadFile(obj);
		if(play)
		{
			setTimeout('movie_play()',3000);
		}
	}
	else
	{
		player.addVariable("file", xml_file);
		player.write("player_container");
	}
}

/*
 * launch movie
 */
function movie_play()
{
	if( player.play_state == null || player.play_state == 0)
	{
		launch_action('playitem', 0);
		setTimeout('movie_play',500);
	}
}

/*
* allow interaction with the player
*/
function launch_action(action, param)
{
	thisMovie("flashplayer").sendEvent(action, param);
}

function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
}
/*
* retrieve all update on the player
*/
function getUpdate(typ,pr1,pr2,swf) { 
  if(typ == 'state') 
  {  
  	
  	
  	if( pr1 == 1 || pr1 == 2 )
  	{
  		player.new_state = 0;
  		player.old_state = 0;
  	}
  	//$('playerState').value = pr1;
  }
  // fin de vidéo. renvoie dans la id playerState de la partie playlist la valeur true
  if( typ == "time" && pr1 != 0 && pr2 == 0 )
  {
  	//player.play_state = pr1;
  	//$('playerState').value = 1;
  	
  	player.new_state = 1;
  }
}

/*--------------------------------------*/
/* 		INTERACTION MANAGEMENT			*/
/*--------------------------------------*/

function change_selected_item( id_item )
{
	// retrieves all the link in the list parent of the current link
	var a_link = $(id_item).parentNode.parentNode.getElementsByTagName('a');
	
	for( var i = 0 ; i < a_link.length ; i++ )
	{
		if( a_link[i].getAttribute('selectable_item') === 'true' )
		{
			if( a_link[i].id == id_item )
			{
				a_link[i].className = "selected";
			}
			else
			{
				a_link[i].className = "";
			}
		}
	}
	
}
