	loadStyleSheet('/css/video_inpage.css');
	
	function playVideoInPage(vid, channel, bcid) {

		// Stop the eventual flash video
		try {window.document.flashobj.SetVariable("cmd","stop");$('flashobj').SetVariable("cmd","stop");}
		catch(er) {}
    window.onbeforeunload=function(e){
      try{
			$('embedVideo').width=1;
			$('embedVideo').height=1;
			embedVideo.controls.stop();
		  }catch(er) {}
		  try{
			document.embedVideo.DoStop();
		  }catch(er) {}
    
    }
		mainPlayer = new tsrkit('mainPlayer');
		// MainPlayer.videoTarget = 'playerContainer';
		mainPlayer.videoTarget = 'playerDynamicContent';
		mainPlayer.channel = channel;
  
		mainPlayer.init(function() {
			// If bcid is provided, load from xobix via xml, otherwise load from Solr
			/*if (bcid) var newRequest = mainPlayer.loadFromXML('index.html?siteSect=500200&bcid=' + bcid + '&vid=' + vid);
			else*/ var newRequest = mainPlayer.searchOnSolr({'role':'video','xobix_video_id':vid});
			newRequest.rCallback = function() {

				var play = function() {

					var mediaIndex = mainPlayer.selectFormat(vid);
					// If a media is found
					if (mediaIndex !== false) {
						
						var v = mainPlayer.videos[vid];
						
						// If the user has configured to play the video in external program, record stats and redirect to the file
						if (mainPlayer.user.alternativePlay) {
							recordVideoStat(v, mediaIndex);
							self.location = v.media[mediaIndex].mUrl
							return;
						
						// Otherwise, create the inpage popup
						} else {
							createPlayerHTML(v, channel, mainPlayer.selectFormat(vid), function() {
								mainPlayer.playVideo(vid);
							});
						}
					}
					
					// Otherwise, redirect to the video page
					//UPDATE:17.01.2008
					/*
					else 
          {
            if(popup)
              self.opener.location.href='index.html?siteSect=500000&amp;bcid='+bcid+'#vid='+vid;
            else
              self.location = 'index.html?siteSect=500000&bcid=' +bcid + '#vid=' + vid;
          }*/
				}

				if ($('playerInPage')) removePlayerHTML(play);
				else play();

			};

			// Somehow, if not called with a small delay, IE6 doesn't execute the loaded script, so...
			window.setTimeout(function(){newRequest.launch();},1);

		});
		return false;
	}
  //Not used yet, because close button is disable.
	function removePlayerHTML(callback) {
		// For sure all this could be made A LOT simplier
		// but somehow in IE7, the windows media won't disappear
		// so I had to use some hack to hide it before closing the box

		try{
			$('embedVideo').width=1;
			$('embedVideo').height=1;
			embedVideo.controls.stop();
		}catch(er) {}

		try{
			document.embedVideo.DoStop();
		}catch(er) {}

		window.setTimeout(function() {
			$('playerDynamicContent').innerHTML = '';
		}, 10);

		window.setTimeout(function() {

			new Effect.Appear($('playerInPage'), {
				duration:1,
				to:0,
				queue: 'end',
				afterFinish: function() {
					document.body.removeChild($('playerInPage'));
					if ('function' == typeof callback) callback();
				}
			});
		}, 20);

		/*new Effect.Appear($('bg-shader'), {
			duration:.5,
			to:0,
			queue: 'end',
			afterFinish: function() {document.body.removeChild($('bg-shader'));}
		});*/

		return false;
	}

	function createPlayerHTML(video, channel, mediaIndex, callback) {

		if (!video) alert('Suite à un problème technique, cette vidéo n\'est pas disponible.');

		tWidth = parseInt(video.media[mediaIndex].mWidth);
		tHeight = parseInt(video.media[mediaIndex].mHeight);
		tCodec = video.media[mediaIndex].mCodec;
		
		if (tWidth < 200) tWidth = 320

		// Only some width are supported (background images)
		if (tWidth != 720 && tWidth != 480 && tWidth != 320 && tWidth != 192) tWidth = (tWidth > 480 ? 720 : 480);

		/* The shader is disabled, but just uncomment each line that contains "shade" to get it back
		var elShader = document.createElement('div');
		elShader.id = 'bg-shader';
		elShader.style.display = 'none';

		// Hide the player on click on the background
		Event.observe(elShader, 'click', removePlayerHTML);
		document.body.appendChild(elShader);
		*/

		var elContainer = document.createElement('div');
		elContainer.id = 'playerInPage';
		px = (tWidth+58)/2;
		py = (tHeight+240)/2;
		
		//UPDATE : popup 17.01.2008, pour que popup ajuste sa taille
		window.resizeTo(tWidth+65,tHeight+470);//540,
		// elContainer.style.marginLeft = '-' + px + 'px';
		//elContainer.style.marginTop = '-' + py + 'px';	
		
		elContainer.style.width = tWidth+58 + 'px';
	
		// UPDATE popup : 17.01.2008
		elContainer.style.display = 'block';
		// Event.observe(elContainer, 'mousedown', dragWindow);
		
		// Witch gecko, the windows media gets white when it's fixed position, so make it absolute
		/*if ((tCodec == 'windowsMedia') && navigator.userAgent.toLowerCase().indexOf('gecko') > 0) {
			elContainer.style.position = 'absolute';
			elContainer.style.marginTop = (window.pageYOffset - py) + 'px';		
		};*/
		
		var elContent = document.createElement('div');
		elContent.id = 'playerContent';

		var elHeader = document.createElement('div');
		elHeader.className = 'header';
    
    /* UPDATE popup : 17.01.2008 
		var elClose = document.createElement('img');
		elClose.className = 'closeLink';
		if (channel == 'info' || channel == 'sport')
			elClose.src = '/images/interactif/video_2007/video-inpage-close-red.gif';
		else
			elClose.src = '/images/interactif/video_2007/video-inpage-close.gif';
		Event.observe(elClose, 'click', removePlayerHTML);
		elContent.appendChild(elClose);
		*/

		var elLogo = document.createElement('img');
		elLogo.className = 'logo';
		if (channel == 'info' || channel == 'sport')
			elLogo.src = '/images/interactif/video_2007/video-inpage-logo-tsr' + channel + '.gif';
		else
			elLogo.src = '/images/interactif/video_2007/video-inpage-logo-tsr.gif';
		elContent.appendChild(elLogo);
		elHeader.innerHTML = '<b>' + video.xobix_program_name + '</b> - ' + (video.broadcast_date ? parseDateSolrToHuman(video.broadcast_date, 'notime') : video.parsed_broadcast_date);
		elContent.appendChild(elHeader);

		var elDynContent = document.createElement('div');
		elDynContent.id = 'playerDynamicContent';
		//UPDATE popup : 17.01.2008 
		//elDynContent.style.height = tHeight+30 + 'px';
		
		elDynContent.innerHTML = '&nbsp;';

		elContent.appendChild(elDynContent);

		var elTitle = document.createElement('div');
		elTitle.id = 'playerTitle';
		
		
		elTitle.innerHTML = video.title + ' <nobr>[ ' +  video.duration+' min.]</nobr>';
		elContent.appendChild(elTitle);

		if (tWidth < 720) {
			var elVideoLink = document.createElement('a');
			elVideoLink.id = 'linkToVideo';
			if (channel == 'info' || channel == 'sport') elVideoLink.className = 'gray';
			//elVideoLink.href = 'index.html?siteSect=500000&bcid=' + video.xobix_broadcast_id + '#vid=' + video.id;
			// UPDATE popup : 17.01.2008 
			elVideoLink.href = '#';
      elVideoLink.onclick = function(){
        self.opener.focus();
        self.opener.location.href='index.html?siteSect=500000&bcid=' + video.xobix_broadcast_id + '#vid=' + video.id;
      };
			elVideoLink.innerHTML = 'Ouvrir cette vid&eacute;o sur la page vid&eacute;o <span>&gt;&gt;</span>';
			elContent.appendChild(elVideoLink);
		}

		// Fix for MSIE6
		ext = 'png';
		if (navigator.userAgent.indexOf('MSIE 6') > 0) {

			/*elShader.style.width = document.body.offsetWidth + 100;
			elShader.style.height = document.body.offsetHeight + 100;
			elShader.style.position = 'absolute';*/
			elContainer.style.position = 'absolute';
			window.scrollTo(0,0);
			ext = 'gif';
		}

		if (navigator.userAgent.toLowerCase().indexOf('safari') > 0) {
			elContainer.style.position = 'absolute';
			window.scrollTo(0,0);
		}

		// Set the right image for the background
		// UPDATE popup : 17.01.2008 
		//elContainer.style.backgroundImage = 'url(/images/interactif/video_2007/video-inpage-bottom-' + tWidth + '.' + ext + ')';
		//elContent.style.backgroundImage = 'url(/images/interactif/video_2007/video-inpage-top-' + tWidth + '.' + ext + ')';

		elContainer.appendChild(elContent);

		document.body.appendChild(elContainer);
		
		// new Draggable(elContainer, {starteffect:null});
    // UPDATE popup : 17.01.2008 la fonction n'est plus appelée dans les effets, alors on le fait ici 
    callback();
    
		var dur = 0.8;
    
		/*new Effect.Appear(elShader, {
			duration:dur,
			to:0.3,
			queue: 'end'
		});*/
    
    // UPDATE popup : 17.01.2008
    /*
		new Effect.Appear(elContainer, {
			duration:dur,
			queue: 'end'
		});

		new Effect.Morph(elDynContent, {
		  style:'min-height:'+(tHeight+30)+'px;',
		  duration:dur,
		  afterFinish: callback,
		  queue: 'end'
		});*/
	}

	/* Drag & drop functions */
/*
	var ddie=document.all;
	var ddnn6=document.getElementById&&!document.all;

	var isdrag=false;
	var ddx, ddy, tx, ty, px, py;
	var dobj;

	function dragWindow(e) {
	  dobj = ddnn6 ? this : event.srcElement;

    isdrag = true;
    tx = parseInt(dobj.offsetLeft);
    ty = parseInt(dobj.offsetTop);
    ddx = ddnn6 ? e.clientX : event.clientX;
    ddy = ddnn6 ? e.clientY : event.clientY;
    document.onmousemove = movemouse;
    dobj.onmouseup = function() {

    	isdrag = false;
    	document.onmousemove = function(){return false;};
    };
    return false;
	}

function movemouse(e) {
  if (isdrag) {
    dobj.style.left = (ddnn6 ? tx + px + e.clientX - ddx : tx + px + event.clientX - ddx) + 'px';
    dobj.style.top  = (ddnn6 ? ty + py + e.clientY - ddy : ty + py + event.clientY - ddy) + 'px';
  }
  return false;
}
*/