/* Player Video */

/*rajout110907*/
$(document).ready(function () { 
	
		if( $("a.popinVideo2") )
		{
		  	$("a.popinVideo2").click(function() {
					showmasque2();
					setTimeout('$("#layerVideo2").show()',500);
					
					myHref = this.href;
					$("#layerVideo2").load(myHref, function(){initVideo2(myHref);});
					return false;
			});
		}
	});
	/*fin rajout*/
	
	
	$(document).ready(function () { 
		
		if( $("a.popinVideo") )
		{
		  	$("a.popinVideo").click(function() {
					showMasque2();
					setTimeout('$("#layerVideo").show()',500)
					myHref = this.href;
						$("#layerVideo").load(myHref, function(){initVideo(myHref);});
									
						
					return false;
			});
		}
	});
		
	/*
	function showMasque(){
		$("#conteneurNiv1").after('<div id="masque"></div><div id="layerVideo"></div>');
		var pageH = $("#conteneurNiv1").height();
		var margH = 55;
		masqueHeight = pageH + margH;
		$("#masque").height(masqueHeight + "px");
		
		 //$("#masque").fadeIn("slow",function(){
		 //  $("#layerVideo").show();
		 //});
		 $("#masque").animate({opacity: 'show'}, "normal");
	}
	*/
	
	/*rajout110907*/
	/*c'est celle lÃ  qui sert a priori*/
	function showmasque2(){
		$("#mainContent").before('<div id="layerVideo2"></div><div id="masque"></div>');
		var margH = 100;
		var pageH = $("#contentBodyFooter").height();
		masqueHeight = pageH + margH;
		
		/*console.log("pageH = "+pageH);
		console.log("masqueHeight = "+masqueHeight);
		console.log($("#conteneurNiv1"))*/
		
		$("#masque").css("height",masqueHeight + "px");
		$("#masque").show();
		//$("#masque").animate({opacity: 'show'}, "normal");
	}
	/*fin rajout*/
	
	function initVideo(myHref){
		initCloseVideo();
		//getPathFlv(myHref);
	}
	/*rajout110907*/
	function initVideo2(myHref){
		initCloseVideo2();
		//getPathFlv(myHref);
	}
	/*fin rajout*/
	
	function initCloseVideo(){
		$("a#closePopin").click(function(){
			CloseVideo();
		});

		$("#masque").click(function(){
			CloseVideo();
		});
	}
	
	
	/*rajout110907*/
	function initCloseVideo2(){
		
		var viewportHeight = getWindowHeight(); 
		var tmpViewportHeight = (viewportHeight - $("#layerVideo2").height())/2;
		var posLayerVid = ss_getCurrentYPos() + tmpViewportHeight;
		$("#layerVideo2").css("top",posLayerVid+"px");
		
		$("a#closePopin2").click(function(){
			CloseVideo2();
		});

		$("a#closePopin1").click(function(){
			CloseVideo();
		});
		
		$("#masque").click(function(){
			CloseVideo2();
		});
	}
	/*fin de rajout*/
	
	function CloseVideo(){
		$("#masque").hide();
		$("#layerVideo").hide();
		initFlashMovie();
		$("#masque").remove();
		$("#layerVideo").remove();
		
	}
	/*rajout110907*/
	function CloseVideo2(){
		$("#masque").hide();
		$("#layerVideo2").hide();
		initFlashMovie();
		$("#masque").remove();
		$("#layerVideo2").remove();
		
	}
	
	function getPathFlv(myHref){
		mypathFlv = myHref.split('?');
		mypathFlv = mypathFlv[1];
		mypathFlv = mypathFlv.substring(5);
		console.log(mypathFlv);
	}	
	
	function initFlashMovie() {
		  var flashMovie;
	            if (document.getElementById) {
	                flashMovie = document.getElementById("myPlayerMovie");
	                //flashMovie.stopSound();
	            }
	            
        }
        
function ss_getCurrentYPos() {
		if (document.body && document.body.scrollTop) {
			return document.body.scrollTop*1;
		}
		if (document.documentElement && document.documentElement.scrollTop) {
			return document.documentElement.scrollTop*1;
		}
		if (window.pageYOffset) {
			return window.pageYOffset*1;
		}
		return 0;
	}
	
function getWindowHeight() {

    var windowHeight=0;

    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }

    else {

     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;

    }

    else {

     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;

      }

     }

    }

    return windowHeight;

}

/* fin Comportement Nav Left */


/* Ajout crade Christophe oct.2008 */

function loadMovie(video){
   	so = new SWFObject("/FRONT/LAGARDERE_CORPORATE/swf/popin/player.swf", "flashID", "640", "480", "8", "#000000");
   	so.addVariable("video", "");
   	so.addVariable("color", "#0000FF");
   	so.addVariable("wmode", "transparent");
   	so.write("myContent");
 }

function loadPopin(externalLink){
				
		// document height for the mask
		//myHeight = document.body.offsetHeight+'px';
		// myHeight = crossBrowserWindowHeight()+'px';
		
		if($.browser.msie){ 
			$("select").css("visibility","hidden");	// virer les selects pour IE
			$('body #masque, body #popinContainer').remove(); // gros bug aberrant IE qui comprend pas $('#popinContainer, #masque').remove();
		}	
		
		// container and mask
		$("body").append('<div id="masque"></div><div id="popinContainer"><a href="#" id="closeButton">Fermer</a><div id="popinContentTop"></div><div id="popinContent"><p>Chargement en cours...</p></div></div>');
		$("#masque").show();
		//$("#masque").css("height",myHeight);
		
		var myVideo = externalLink.split('popin.php?')[1];
		
		
		
		// external HTML load
		jQuery('#popinContainer #popinContent').load(externalLink + " #newPopinStuff",function(){
				
				loadMovie(myVideo);
				
				// Close buttons
				$('#closeButton, #masque').click(function(){
	
					$('#popinContainer, #masque').remove();
					
					if($.browser.msie){ $("select").css("visibility","visible"); }	// remettre les selects pour IE
					return false;
					
				});
				
		});

	}


$(document).ready(function () {

	$('a[@href*=popin.php]').click(function(){
			
			loadPopin($(this).attr('href'));
			
			$(this).blur();
			return false;
			
		});

});