
/* --------- afficher single player video dans lightbox ----------- */
function displayLightboxSinglePlayer(pidLightbox, pclasse, ptitle, pnum_video, pdescription, pcopyright, pmore_videos_link) {

	arrangeDataSinglePlayer(pclasse, ptitle, pnum_video, pdescription, pcopyright, pmore_videos_link);
	montreLightboxSinglePlayer(pidLightbox, pclasse);

}


/* -------------- prepare le data du single player pour monter le contenu ------------ */
function arrangeDataSinglePlayer(pclasse, ptitle, pnum_video, pdescription, pcopyright, pmore_videos_link) {

	var vtitle = replaceForRealCharacters(trim(ptitle));
	var vcopyright = replaceForRealCharacters(trim(pcopyright));
	var vnum_video = pnum_video * 1; // au cas où que nous l'avons sous forme string
	var vdescription = replaceForRealCharacters(trim(pdescription));
		var vmore_videos_link = replaceForRealCharacters(trim(pmore_videos_link));

	var vstring = "<p class='title'>" + vtitle + "</p>" +
								"<div id='video_player_container'>Vidéo ici</div>";
			vstring += (vdescription != null && vdescription != '' ? "<p class='video_description'>" + vdescription + "</p>" : "");
			vstring += (vcopyright != null && vcopyright != '' ? "<div class='copyright'>&copy;&nbsp;Copyright " + vcopyright + "</div>" : "");
			vstring += (vmore_videos_link != null && vmore_videos_link != '' ? "<a href='" + vmore_videos_link + "' class='more_videos'><span>Plus de vidéos</span></a>" : "");

   $("#content_video_single_player").html("");	
	 $("#content_video_single_player").append(vstring);		

	// mettre le video dans son container
		player.setVideo(pnum_video);
		player.append('video_player_container');
}

function montreLightboxSinglePlayer(pidLightbox, pclasse) {
	
	// le met invisible au debut car on peut le changer de place par la suite ...
	$('#TB_window').css('visibility','hidden');
	tb_show('', '#TB_inline?height=660&width=656&inlineId=' + pidLightbox + '&modal=true', false);
	if (pclasse != "") {
			$('#TB_window').addClass(pclasse);
	}

	reajusteLightBoxSelonScreenHeight();

	$('#TB_window').css('visibility','visible');

}

/* ----- vérifier si le contenu du lightbox entre dans le height disponible. 
				Si non, on va faire afficher une scrollbar et le faire changer de place -------- */
function reajusteLightBoxSelonScreenHeight() {
	
	if ( (_client.dimension.getWindowHeight()) < $('#TB_window').height()-60 ) {
		var vheight = _client.dimension.getWindowHeight()-60;
		var vmartinTop;
		if (_client.browser.getVersion() != "6.0") {
			vmarginTop = parseInt(_client.dimension.getWindowHeight()/2-25)*-1  + 'px';
		}else {
			var vmarginTopCurrent = parseInt($('#TB_window').css('marginTop'));
			var vdifference = parseInt(($('#TB_window').height() - (_client.dimension.getWindowHeight()-5)) / 2);
			vmarginTop = vmarginTopCurrent + vdifference + 'px';
		}
		$('#TB_window').css('top','50%');  // pour qu'il soit vraiment centré
		$('#TB_window').css('marginTop', vmarginTop);
		$('#TB_ajaxContent').css('height',vheight); 
		$('#TB_ajaxContent').css('overflow-y', 'scroll');
		coloreScrollbar()
	}
}


/* ----- pour le single player, replace les |~39; et |~34; par &#39; et &#34; 
				 On a changé les caractères pour passer a la fonction javascript 
				 ( pour ne pas passer des ' et " en paramètres à la fonction javascript)
				 mais avec html_template, les &#39; et &#34; étaient vraiment transformés par
				 des ' et ". Donc a a mis des |~ à la place ----------------------------	*/

function replaceForRealCharacters(pstring) {
	var vstring = pstring; 
	pstring = pstring.replace(/\|~39;/ig, "&#39;");
	pstring = pstring.replace(/\|~34;/ig, "&#34;");
	return pstring;

}

function replaceForJavascriptCar(pstring) {
	var vstring = pstring; 

		pstring = pstring.replace(/\/"/ig, "&#34;");
	pstring = pstring.replace(/\/'/ig, "&#39;");

	return pstring;

}

/* ----- colore la scrollbar pour les lightbox, si le contenu est plus grand que l'ecran ----- */
function coloreScrollbar() {

	$('#TB_ajaxContent').css('scrollbar-face-color', '#141414');
	$('#TB_ajaxContent').css('scrollbar-highlight-color','#000000');
	$('#TB_ajaxContent').css('scrollbar-3dlight-color','#000000');
	$('#TB_ajaxContent').css('scrollbar-darkshadow-color','#000000');
	$('#TB_ajaxContent').css('scrollbar-shadow-color','#141414');
	$('#TB_ajaxContent').css('scrollbar-arrow-color','#E2E4E5');
	$('#TB_ajaxContent').css('scrollbar-track-color','#000000');

}

/* ------------ enleve le lightbox courant ------------- */
function close_lightbox() {
	tb_remove();			
}


/* ---- add le template du single player  -------- */
function templateSinglePlayer() {
// with chainable object
	canoeBcPlayer.addTemplate(
		'SA_single_player', 
		{
		 publisher: 3073751001,  // 
		 player:    9203599001,  // 
		 width:     544,         // 
		 height:    455         // 
		}
	)
}


/* --- function du template du player avec playlist d'emissions web ---- */
function templatePlayerEmissionsWeb() {
// with chainable object
	canoeBcPlayer.addTemplate(
		'SA_player_emissions_web', 
		{
		 publisher: 3073751001,  // 
		 player:    9413633001,  // 
		 width:     798,         // 
		 height:    495         // 
		}
	)
}

/* --- function du template du player des cours ---- */
function templateLesCoursPlayer() {
// with chainable object
	canoeBcPlayer.addTemplate(
		'SA_player_les_cours', 
		{
		 publisher: 3073751001,  
		 player:    10609719001,  
		 width:     555,         
		 height:    650         
		}
	)
}


/* --- function du template du player des cours de Johanne Blouin ---- */
function templateCoursJBlouinPlayer() {
// with chainable object
	canoeBcPlayer.addTemplate(
		'SA_player_cours_jblouin', 
		{
		 publisher: 3073751001,  
		 player:    11892210001, 
		 width:     555,         
		 height:    650       
		}
	)
}

/* --- function du template du player des cours de Johanne Blouin ---- */
function templateZoneVideotron() {
// with chainable object
	canoeBcPlayer.addTemplate(
		'SA_player_zone_videotron', 
		{
		 publisher: 3073751001,  
		 player:    9223652001, 
		 width:     798,         
		 height:    495      
		}
	)

		// add playlists
		.addPlaylist('performances', 9203086001   )  
		.addPlaylist('bilan', 9203087001 )  
		.addPlaylist('vote',  9230912001 )  
		.addPlaylist('sorties', 9203088001 )  
}


/* ------------ init single player video: parametres de base pour tous les videos ------ */
function initSinglePlayer() {
		player.setTemplate('SA_single_player'); // déclaré dans la fonction: templateSinglePlayer
		player.setAutostart(true);
}

/* ------------ init le player d'emissions web  ------ */
function initPlayerEmissionsWeb() {
		player.setTemplate('SA_player_emissions_web'); // déclaré dans la fonction: templatePlayerEmissionsWeb() 
		player.setAutostart(true);
}

/* ------------ init le player des cours en ligne vip - autre que ceux de Johanne Blouin  ------ */
function initLesCoursPlayer() {
		player.setTemplate('SA_player_les_cours'); // déclaré dans la fonction: templateLesCoursPlayer()
		player.setAutostart(true);
}

/* ------------ init le player des cours de chant de Johanne Blouin ------ */
function initCoursJBlouinPlayer() {
		player.setTemplate('SA_player_cours_jblouin'); // déclaré dans la fonction: templateCoursJBlouinPlayer()
		player.setAutostart(true);
}


/* ------------ init le player de zone Videotron ------ */
function initZoneVideotron(playlist) {
		player.setTemplate('SA_player_zone_videotron'); // déclaré dans la fonction: templateZoneVideotron()
		if (playlist && playlist != "")		{
			player.setPlaylist(playlist);
		}
		player.setAutostart(true);
}



/* ------------ set le video dans le player qui possede une playlist ------ */
function setVideoToPlayerPlaylist(pidVideo) {
	pidVideo = (pidVideo != null && !(isNaN(pidVideo)) ? parseInt(pidVideo) : 0 );
	if (pidVideo != 0 )	{
		// mettre le video une seconde plus tard car probleme de synchronisation
		player.ready( 
			function(p){
				p.api.videoplayer.loadVideo(pidVideo);
			}
		) 
	}

}
