		
	// some variables to save
	var currentPosition = 0; 
	var currentRemaining;
	var currentVolume;
	var currentItem;
	var currentState;
	var previousState;
	var currentLoad;
	var currentXsize;
	var currentYsize;
	var current_id;
	var current_duree = '';
	var current_update_id = 0;
	
	var next_id = '';
	var next_url = '';
	
	var player;
    function playerReady(obj) {
	  player = document.getElementById(obj['id']);
	  addListeners();
	  //printPlaylistData();
    };
	
	
	
	function addListeners() {
	  if (player) { 
		//player.addModelListener("TIME", "positionListener");
		player.addModelListener("STATE", "stateListener");
		//player.addModelListener('ERROR', 'jwErrorMonitor');
	  } else {
		setTimeout("addListeners()",100);
	  }
    }
	
	function jwErrorMonitor(obj) {
      alert(obj.message);
    };
	
	function positionListener(obj) { 
	  currentPosition = obj.position;
	  
	  if (current_update_id != current_id && currentPosition > 5) {
	    if(O('duree_' + current_id).innerHTML) current_duree = '';
		else current_duree = obj.duration;
		Media_Update_Video(current_id, current_duree);
		current_update_id = current_id;
	  }	
    }
	 
    function itemMonitor(obj) {
       currentItem = obj['index'];
    };
	 
	 function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	    currentState = obj.newstate; 
	    previousState = obj.oldstate;
		currentPosition = obj.position;  
		
        if (currentState == "COMPLETED" && O('next_play_' + current_id)) {
		  eval(O('next_play_' + current_id).innerHTML); 
		  currentState = 'NONE';
		  //O('code_html').value = currentState + '/' + O('next_play_' + current_id).innerHTML;
	    }
     }

	 var url = "";
	 var newFile = null;

	function loadPlaylist(url)
	 {
	   //newFile = {file:url};
	   player.sendEvent('STOP');
	   player.sendEvent('LOAD', url); 
	 }
	 
	 /*function loadPlaylist(url){
	  newFile = {file:url};
	  player.sendEvent('STOP');
	  setTimeout("player.sendEvent('LOAD', newFile)", 100);
	 }*/
	 
	 function addPlaylist(newItem)
      {
        newItem.duration = '';
        newItem.type     = '';
        var oldList = player.getPlaylist();
        var newList = oldList.concat(newItem);
        player.sendEvent("LOAD", newList);

      };
	  
	  function printPlaylistData() {
					var plst = null;
					plst = player.getPlaylist();
					if (plst) {
						var txt = '';
						for(var itm in plst) { 
							txt += '<li>'+itm+':</li>';
							txt += '<ul>';
							txt += '<li>'+plst[itm].title+'</li>';
							txt += '<li>'+plst[itm].author+'</li>';
							txt += '<li>'+plst[itm].file+'</li>';
							txt += '</ul><br>';
						}
						var tmp = document.getElementById("plstDat");
						if (tmp) { tmp.innerHTML = txt; }
					} else {
						setTimeout("printPlaylistData()",100);
					}	
				}
	  
	 function gid(name)
      {
        return document.getElementById(name);
      }; 
	
	// this function is caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { thisMovie("player_webtv").sendEvent(typ,prm); };
	
	// These functions are caught by the feeder object of the player.
	function loadFile(swf,obj) { thisMovie(swf).loadFile(obj); };
	
	function addItem(obj,idx) { thisMovie("player_webtv").addItem(obj,idx); };
	
	function removeItem(idx) { thisMovie("player_webtv").removeItem(idx); };
	
	function getLength(swf) { return(thisMovie(swf).getLength()); };
	
	
	// This is a javascript handler for the player and is always needed.
	/*function thisMovie(movieName) {
		if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};*/
	
	
	function Charger_Video(url, id) {
	  //url ="fichiers/xml/12portes1.xml";
	  
	  current_id = id;
	  current_update_id = 0;
	  O('titre_video_en_cours').innerHTML = O('titre_' + id).innerHTML;
	  O('bg_description_video').innerHTML = O('description_' + id).innerHTML;
	  loadPlaylist(url);
	  Now_Playing(current_id);
	  Media_Update_Infos_Media(id);
	}
	
	
	// This creates the player after the page has finished loading (onload).
	function createPlayer(id_lecteur, file, id, image) {
		// <![CDATA[
	// width of video:320, height of the video+20(for controlbar):260,
	// 9 for Flash Player 9 (for ON2 Codec and FullScreen)
	
	var s1 = new SWFObject("media_player.swf","player_webtv","370","278","9", "#000000");
	
	s1.addVariable("autostart","true");
	s1.addVariable("showdigits","true"); 
	s1.addVariable("file", file);
	s1.addVariable("thumbsinplaylist","false");
	s1.addVariable("shuffle","false");
	s1.addParam('allowscriptaccess','always');
	 // the PHP script
	//s1.addVariable("streamscript","flvprovider.php");
	s1.addVariable("streamscript","streamer.php");
	s1.addVariable("bufferlength","1.2");
	 // the width and the height of the video
	s1.addVariable("displaywidth","370");
	s1.addVariable("displayheight","278");
	s1.addVariable("displayheigion","true");
	s1.addVariable("repeat","false");  
	 // for fullscreen
	s1.addParam("allowfullscreen","false");
	s1.addVariable("showfsbutton","false");
    s1.addVariable("enablejs","true");
    s1.addVariable("javascriptid","player_webtv");
	//s1.addVariable("image","images/no_img_mp3.jpg");
	//image=http://media.salemwebnetwork.com/
	//s1.addVariable("skin","LightSource_Skin_v1.swf");
	current_id = id;
	Now_Playing(current_id);
	s1.write(id_lecteur);
    var mmw = new SWFMacMouseWheel(s1);
	// ]]>
	};
	
	
	function createPlayer2(id_lecteur, file, id, image){
	    var s1 = new SWFObject("media_player.swf","player_webtv","370","278","9","#000000");
		//s1.useExpressInstall("playerProductInstall.swf");
	    //s1.setAttribute("xiRedirectUrl", window.location.href);
		s1.addParam("allowfullscreen","true");
		s1.addParam("allownetworking","all");
		s1.addParam("allowscriptaccess","always");
		s1.addVariable("autostart","always");
	    s1.addVariable("showdigits","true"); 
	    s1.addParam("allowfullscreen","false");
	    s1.addVariable("showfsbutton","false");
        s1.addVariable("enablejs","true");
        s1.addVariable("javascriptid","player_webtv");
		s1.addVariable("displaywidth","370");
	    s1.addVariable("displayheight","278");
	
		s1.addParam("flashvars","file="+file+"&image="+image);
		//alert("file="+file+"&image="+image);
		s1.write(id_lecteur);
	}
	
	
	function Now_Playing(id) {
	  var tab = new Array();
	  
	  tab = getElementsByClassName('content_current', '');
	  for(var i=0;i<tab.length;i++) tab[i].className = 'content';  
	  document.getElementById('content_' + id).className = 'content_current';
	}
	
	//Get all the elements of the given classname of the given tag.
	function getElementsByClassName(classname,tag) {
	 if(!tag) tag = "*";
	 var anchs =  document.getElementsByTagName(tag);
	 var total_anchs = anchs.length;
	 var regexp = new RegExp('\\b' + classname + '\\b');
	 var class_items = new Array()
	 
	 for(var i=0;i<total_anchs;i++) { //Go thru all the links seaching for the class name
	  var this_item = anchs[i];
	  if(regexp.test(this_item.className)) {
	   class_items.push(this_item);
	  }
	 }
	 return class_items;
	}
