/**
 * Scripts du Player d extraits et Player video
 * Le player d'extrait est un objet. Seulle une seule instance est supportee
 * et doit etre instancie comme ci-dessous
 * Le player video n'a pas bouge pour l'instant
 */
var audioPlayer=new skPlayer();

/**
 * Fonctions appelees par le player flash lors de ses differents evenements
 */
 		
		/**
		 * Evenement StopRelease (bouton stop relache).
		 */
		function player_mp3_onTickerUpdate(infos) {
			if(typeof audioPlayer.updateHandler=="function" && audioPlayer.lst_extraits.length)
				audioPlayer.updateHandler(infos);
			if (typeof audioPlayer.scrollTitleHandler=="function" && audioPlayer.lst_extraits.length){
				audioPlayer.scrollTitleHandler(2);
				}
		}
		
		/**
		 * Evenement StopRelease (bouton stop relache).
		 */
		function player_mp3_onStopRelease() {
			clearTimeout(audioPlayer.timeoutActif);
			if(typeof audioPlayer.updateHandler=="function" && audioPlayer.lst_extraits.length)
				audioPlayer.stopHandler(audioPlayer.callBackRef,audioPlayer.lst_extraits[audioPlayer.ptr_extraits-2],audioPlayer.lst_extraits[audioPlayer.ptr_extraits-1]);
			if (typeof audioPlayer.scrollTitleHandler=="function" && audioPlayer.lst_extraits.length){
				audioPlayer.scrollTitleHandler(0);
			}
		}
		
		/**
		 * Evenement PauseRelease (bouton pause relache).
		 */
		function player_mp3_onPauseRelease() {
			clearTimeout(audioPlayer.timeoutActif);
			if(typeof audioPlayer.updateHandler=="function" && audioPlayer.lst_extraits.length)
				audioPlayer.pauseHandler(audioPlayer.callBackRef,audioPlayer.lst_extraits[audioPlayer.ptr_extraits-2]);
			if (typeof audioPlayer.scrollTitleHandler=="function" && audioPlayer.lst_extraits.length){
				audioPlayer.scrollTitleHandler(0);
			}
		}
		
		/**
		 * Evenement PlayRelease (bouton play relache).
		 * restant est la duree de lecture restante en secondes
		 */
		function player_mp3_onPlayRelease(restant) {
			clearTimeout(audioPlayer.timeoutActif);
				audioPlayer.timeoutActif = setTimeout("audioPlayer.Chain()",restant);
			if(typeof audioPlayer.updateHandler=="function" && audioPlayer.lst_extraits.length)
					audioPlayer.startHandler(audioPlayer.callBackRef,audioPlayer.lst_extraits[audioPlayer.ptr_extraits-2]);
			if (typeof audioPlayer.scrollTitleHandler=="function" && audioPlayer.lst_extraits.length){
					audioPlayer.scrollTitleHandler(1);
			}
		}

/****************************************************
 * La classe skPlayer
 *******************************************
 * Qui gere maintenant la lecture des extraits audio
 *********************************************/
 
function skPlayer() {
	this.startHandler;
	this.stopHandler;
	this.updateHandler;
	this.scrollTitleHandler;
	this.lst_extraits = new Array;
	this.ptr_extraits;
	this.nbr_extraits;
	this.timeoutActif = null;
	this.temp_pos;
	this.currentID=0;
	this.callBackRef="";
	this.urlbase="http://www.starzik.com";

 	/**
 	 * Methods Definition
 	 */
	if ( typeof skPlayer.initialized == "undefined" ) {

 		/**
 		 * Initialise le lecteur. Dessine l'objet Flash. doit être appele dans le DOM
 		 *
 		 * Parameters: none
 		 * Return: none
 		 */
		skPlayer.prototype.Init = function() {
			var domElement;
			eval('domElement=' + window.divplayer); 		
			domElement.innerHTML=window.PlayerHTML.replace('#MP3#', '');
		}
 
 		/**
 		 * Retourne la position courante de lecture de l extrait en pourcentage de la duree totale.
 		 *
 		 * Parameters: none
 		 * Return: Integer between 0 and 99
 		 */
		skPlayer.prototype.GetPosition = function() {
			return this.getFlashAudioObject().GetVariable("player:jsGetPosition")
		}
 
 		/**
 		 * Retourne la duree en millisecondes de l extrait en cours.
 		 *
 		 * Parameters: none
 		 * Return: Integer 
 		 */
		skPlayer.prototype.GetDuration = function() {
			return this.getFlashAudioObject().GetVariable("player:jsGetDuration")
		}
 
 		/**
 		 * Demande au lecteur de passer a l extrait precedent s il en existe un.
 		 *
 		 * Parameters: none
 		 * Return: void
 		 */
		skPlayer.prototype.Previous = function() {
			// Si on a encore au moins deux arguments avant soi dans la liste on lance l ecoute
			if(this.ptr_extraits>=4) {
				if(this.currentID>0 && typeof this.stopHandler=="function")
					this.stopHandler(this.callBackRef,this.currentID);
				if (this.currentID>0 && typeof this.scrollTitleHandler=="function"){
					this.scrollTitleHandler(0);
				}
				this.ptr_extraits-=4;
				this.Sample(this.lst_extraits[this.ptr_extraits++],this.lst_extraits[this.ptr_extraits++]);
			}
		}
 
 		/**
 		 * Demande au lecteur de passer a l extrait suivant s il en existe un.
 		 *
 		 * Parameters: none
 		 * Return: void
 		 */
		skPlayer.prototype.Next = function() {
			if(this.ptr_extraits<=(this.nbr_extraits-2)) {
				if(this.currentID>0 && typeof this.stopHandler=="function")
					this.stopHandler(this.callBackRef,this.currentID);
				if (this.currentID>0 && typeof this.scrollTitleHandler=="function"){
					this.scrollTitleHandler(0);
				}
				// Si on a encore au moins deux arguments dans la liste on lance l ecoute
				this.Sample(this.lst_extraits[this.ptr_extraits++],this.lst_extraits[this.ptr_extraits++]);
			}
		}
		
		/**
 		 * Demande au lecteur de passer au streaming suivant s il en existe un.
 		 *
 		 * Parameters: none
 		 * Return: void
 		 */
		skPlayer.prototype.NextStream = function() {
			if(this.ptr_extraits<=(this.nbr_extraits-2)) {
				if(this.currentID>0 && typeof this.stopHandler=="function")
					this.stopHandler(this.callBackRef,this.currentID);
				if (this.currentID>0 && typeof this.scrollTitleHandler=="function"){
					this.scrollTitleHandler(0);
				}
				// Si on a encore au moins deux arguments dans la liste on lance l ecoute
				this.SampleStream(this.lst_extraits[this.ptr_extraits++],this.lst_extraits[this.ptr_extraits++]);
			}
		}
 
 		/**
 		 * Dpassage automatique a l extrait suivant s il en existe un.
 		 *
 		 * Parameters: none
 		 * Return: void
 		 */
		skPlayer.prototype.Chain = function() {
			if(this.currentID>0 && typeof this.stopHandler=="function")
				this.stopHandler(this.callBackRef,this.currentID);
			if (this.currentID>0 && typeof this.scrollTitleHandler=="function"){
				this.scrollTitleHandler(0);
			}
			// Si on a encore au moins deux arguments dans la liste on lance l ecoute
			if(this.ptr_extraits<=(this.nbr_extraits-2)) {
				this.Sample(this.lst_extraits[this.ptr_extraits++],this.lst_extraits[this.ptr_extraits++]);
			}
		}
 
 		/**
 		 * Demande au lecteur de reprendre la lecture au point ou il en etait apres une pause.
 		 *
 		 * Parameters: none
 		 * Return: void
 		 */
		skPlayer.prototype.Resume = function() {
			this.getFlashAudioObject().SetVariable("player:jsPlay", "")
		}
 
 		/**
 		 *
 		 */
		skPlayer.prototype.getFlashAudioObject = function() {
 			return document.getElementById('flash_audio_player');
 		}
 			
 		/**
 		 * Stoppe la lecture de l extrait et rembobine au debut.
 		 *
 		 * Parameters: none
 		 * Return: void
 		 */
		skPlayer.prototype.Stop = function() {
			this.getFlashAudioObject().SetVariable("player:jsStop", "")
		}
 
 		/**
 		 * Demande au lecteur de suspendre la lecture sans rembobiner.
 		 *
 		 * Parameters: none
 		 * Return: void
 		 */
		skPlayer.prototype.Pause = function() {
			this.getFlashAudioObject().SetVariable("player:jsPause", "")
		}

 		/**
 		 * Fonction Javascript qui lance l ecoute d'un extrait
 		 *
 		 * Parameters:  
 		 *		ID : [integer5] Song ID
 		 *		Code : [string] Key code to allow playback
		 * 
 		 * Return: void
 		 */
		skPlayer.prototype.Sample = function(ID, Code) {
			var url_extrait;
			this.currentID=ID;

			url_extrait = this.urlbase + "/extrait" + ID + "-" + Code + ".mp3";
			//url_extrait="http://" + window.ServerName + "/extrait" + ID + "-" + Code + ".mp3";
			this.SetUrl(url_extrait);
			this.getFlashAudioObject().SetVariable("player:jsStop", "")
			this.getFlashAudioObject().SetVariable("player:jsPlay", "")
		}
		
		/**
 		 * Fonction Javascript qui lance l ecoute d'un streaming
 		 *
 		 * Parameters:  
 		 *		ID : [integer5] Song ID
 		 *		URL : [string] URL of the stream
		 * 
 		 * Return: void
 		 */
		skPlayer.prototype.SampleStream = function(ID, URL) {
			var url_extrait;
			this.currentID=ID;
			url_extrait=URL;
			this.SetUrl(url_extrait);
			this.getFlashAudioObject().SetVariable("player:jsStop", "")
			this.getFlashAudioObject().SetVariable("player:jsPlay", "")
		}
		
		
		/**
 		 * Lance la lecture d un ou d une serie de streamings.
 		 *
 		 * Parameters:  
 		 *		ID : [integer5] Song ID
 		 *		URL : [string] URL of the stream
 		 * 		ID : ...
 		 *		URL : ...
 		 *		...
 		 * Return: void
 		 */
		skPlayer.prototype.PlayURL = function(callBackRef) {
			this.callBackRef=callBackRef;
			this.ptr_extraits=0;
  			this.nbr_extraits = arguments.length-1;
  			this.lst_extraits.length=0;
  			for (var i = 0; i < this.nbr_extraits; i++)
      		{
    			this.lst_extraits[i] = arguments[i+1];
      		}
      		this.NextStream();	
		}		
		
 
 		/**
 		 * Lance la lecture d un ou d une serie d extraits.
 		 *
 		 * Parameters:  
 		 *		ID : [integer5] Song ID
 		 *		Code : [string] Key code to allow playback
 		 * 		ID : ...
 		 *		Code : ...
 		 *		...
 		 * Return: void
 		 */
		skPlayer.prototype.Play = function(callBackRef) {
			this.callBackRef=callBackRef;
			this.ptr_extraits=0;
  			this.nbr_extraits = arguments.length-1;
  			this.lst_extraits.length=0;
  			for (var i = 0; i < this.nbr_extraits; i++)
      		{
    			this.lst_extraits[i] = arguments[i+1];
      		}
      		this.Next();	
		}
 
 		/**
 		 * Permet de definir une fonction js a appeler apres chaque (re)demarrage d extrait. 
 		 * Si elle est specifiee, cette fonction sera appelee avec l ID de la piste en argument.
 		 *
 		 * Parameters:  
 		 *		Handler : [function] function handling the start (resume) of a song, this function 
 		 *			will be called each time a song starts or resume playing whith the id of the song.
		 *
 		 * Return: void
 		 */
		skPlayer.prototype.SetStartHandler = function(Handler) {
			this.startHandler=Handler;
		}
		
 		/**
 		 * Permet de definir une fonction js a appeler apres chaque fin d extrait. 
 		 * Si elle est specifiee, cette fonction sera appelee avec l ID de la piste en argument.
 		 *
 		 * Parameters:  
 		 *		Handler : [function] function handling the stop of a song, this function 
 		 *			will be called each time a song stops playing whith the id of the song.
		 *
 		 * Return: void
 		 */
		skPlayer.prototype.SetEndHandler = function(Handler) {
			this.stopHandler=Handler;
		}
		
 		/**
 		 * Permet de definir une fonction js a appeler apres chaque pause d extrait. 
 		 * Si elle est specifiee, cette fonction sera appelee avec l ID de la piste en argument.
 		 *
 		 * Parameters:  
 		 *		Handler : [function] function handling the pause of a song, this function 
 		 *			will be called each time a song pause playing whith the id of the song.
		 *
 		 * Return: void
 		 */
		skPlayer.prototype.SetPauseHandler = function(Handler) {
			this.pauseHandler=Handler;
		}
		
 		/**
 		 * Permet de definir une fonction js a appeler pour mettre a jour les infos. 
 		 * Si elle est specifiee, cette fonction sera appelee avec un objet infos en argument.
 		 *
 		 * Parameters:  
 		 *		Handler : [function] function handling the update of player informations, 
 		 *			this function will be called at ticker frequency (default 1s) during 
 		 *			playing of a song with all the infos in parameters.
		 * Infos object:
 		 * 	size:179148
		 * 	loaded:179148
		 * 	percentloading:100
		 * 	position:10397
		 * 	duration:29858
		 * 	percentplaying:34.8214883783241
		 * 	volume:100
		 * 	state:false
		 * 	url:http://pre-release.v3.starzik.com/extrait4855983-8b69d9113624458.mp3
		 * 	id3:[object Object]
		 *
 		 * Return: void
 		 */
		skPlayer.prototype.SetUpdateHandler = function(Handler) {
			this.updateHandler=Handler;
		}
		
 		/**
 		 * Permet de definir une fonction js a appeler pour demarer / arreter le défilement du titre. 
 		 * Si elle est specifiee, cette fonction sera appelee avec 1 ou 0 pour demarer ou arreter le defilement.
 		 *
 		 * Parameters:  
 		 *		Handler : [function] function handling the start / stop of the title scrolling 
 		 *			will be called each time a song start / stops playing whith 1 / 0 as parameter.
 		 *			and at each ticker update with 2
		 *
 		 * Return: void
 		 */
		skPlayer.prototype.SetScrollTitleHandler = function(Handler) {
			this.scrollTitleHandler=Handler;
		}
		
 		/**
 		 * Fixe le volume d ecoute du lecteur. Un volume a 0 correspond a un Mute.
 		 *
 		 * Parameters: 
		 *		Volume : [Integer between 0 and 99] The new volume level in %.
 		 * Return: void
 		 */
		skPlayer.prototype.SetVolume = function(Volume) {
			this.getFlashAudioObject().SetVariable("player:jsVolume", Volume);
		}
		
 		/**
 		 * Fixe l url de la track a lire. 
 		 *
 		 * Parameters: 
		 *		Url : [string] The song url.
 		 * Return: void
 		 */
		skPlayer.prototype.SetUrl = function(Url) {
			this.getFlashAudioObject().SetVariable("player:jsUrl", Url);
		}
		
		skPlayer.initialized = true;
	}
}

/**************************************************************************
 * Gestion des Trailers VIDEO
 *********
 * Toujours a l'ancienne mode
 ******************************************/


		var lst_trailers = new Array;
		var ptr_trailers,nbr_trailers;
		var VtimeoutActif = null;
		var img_url="";
		var fmt_trailers="flash";
		var trailers_target="_blank";
		var trailer_urlbase = "http://www.starzik.com";
		
		function trailers() {
			ptr_trailers=0;
  			nbr_trailers = arguments.length-3;
  			lst_trailers.length=0;
  			img_url=arguments[nbr_trailers];
  			fmt_trailers=arguments[nbr_trailers+1];
  			trailers_target=arguments[nbr_trailers+2];
  			
  			for (var i = 0; i < nbr_trailers; i++)
      		{
    			lst_trailers[i] = arguments[i];
      		}
      		trailer_suivant();	
		}
		
		function trailer_suivant() {
			// Si il nous reste encore une paire id / key on lance le trailer
			if(ptr_trailers<=(nbr_trailers-2)) {
				trailer(lst_trailers[ptr_trailers++],lst_trailers[ptr_trailers++]);
			}
			// Si il y a encore des arguments on relance le timer
			if(ptr_trailers<nbr_trailers) {
				clearTimeout(VtimeoutActif);
				VtimeoutActif = setTimeout("trailer_suivant()",60000);
			}
		}
		
		function DelPopupTrailer(){
			var theDiv;
			theDiv=document.getElementById('trailer_popup'); 
			if(theDiv){
				//thePlayer=document.getElementById('trailer_flash_object');
				//if(!thePlayer)
				//	thePlayer=document.getElementById('trailer_flash_ctrl');
				//if(thePlayer)
				//	thePlayer.SetVariable("player:jsStop", ""); // Pour faire STOP
				theDiv.parentNode.removeChild(theDiv);
			}
		}
		
		function ClosePopupTrailer(){
			thePlayer=document.getElementById('trailer_flash_object');
			if(!thePlayer)
				thePlayer=document.getElementById('trailer_flash_ctrl');
			thePlayer.SetVariable("player:jsStop", ""); // Pour faire STOP
			theDiv=document.getElementById('trailer_popup'); 
			theDiv.parentNode.removeChild(theDiv);
			return false;
		}
		
		function trailer(id,key) {
			// Fonction Javascript qui lance le trailer
			var url_trailer;
			var divtrailer,divcourant;
  			if(trailers_target!="_blank") {
  				divtrailer = document.getElementById(trailers_target);
  			} else {
  				if(!(divtrailer = document.getElementById("trailer_popup_body"))) {
  					popuptraildiv=document.createElement('div');
  					popuptraildiv.id="trailer_popup";
  					popuptrailhead=document.createElement('div');
  					popuptrailhead.id="trailer_popup_head";
  					popuptrailbody=document.createElement('div');
  					popuptrailbody.id="trailer_popup_body";
  					popuptrailclosebox=document.createElement('div');
  					popuptrailclosebox.id="trailer_popup_close_box";
  					popuptrailcloseanc=document.createElement('a');
  					popuptrailcloseanc.id="trailer_popup_close_anc";
  					popuptrailcloseanc.innerHTML="X";
  					popuptrailcloseanc.onclick=ClosePopupTrailer;
  					popuptrailcloseanc.href="#";
  					popuptrailclosebox.appendChild(popuptrailcloseanc);
 					popuptrailhead.appendChild(popuptrailclosebox);
  					popuptraildiv.appendChild(popuptrailhead);
  					popuptraildiv.appendChild(popuptrailbody);
  					document.body.appendChild(popuptraildiv);
  					//new Draggable('trailer_popup');
  					divtrailer=document.getElementById("trailer_popup_body");
  				}
  			}
			url_trailer = trailer_urlbase + "/trailer" + id + "-" + key + ".flv";

			if(fmt_trailers=="flash") {
				divtrailer.innerHTML=TrailerHTML.replace('#FLV#', url_trailer).replace('#JPG#', img_url).replace('#FLV#', url_trailer).replace('#JPG#', img_url); // 2 fois car pour object et embed
			} else {
				divtrailer.innerHTML="<object classid='CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6' id='MediaPlayer' name='MediaPlayer' type='application/x-oleobject' viewastext='' standby='Loading Microsoft Windows Media Player components...' height='200' width='250'><param name='url' value='" + url_trailer + ".wmv'><param name='enabled' value='true' /><param name='defaultframe' /><param name='enablecontextmenu' value='true' /><param name='stretchtofit' value='true' /><param name='windowlessvideo' value='true' /><param name='autostart' value='true' /><param name='ShowPositionControls' value='False' /><param name='uimode' value='mini' /><param name='volume' value='30' /><embed src='" + url_trailer + ".wmv' type='application/x-oleobject' height='200' width='250' ShowPositionControls='0' ></object>";
			}
		}
		
		/**
		 * Fonction appelee par le player flash lors de son evenement 
		 * 'StopRelease' (bouton stop relache).
		 */
		function trailer_flv_onStopRelease() {
			clearTimeout(VtimeoutActif);
		}


