/* MODIFIED ON JULY 2009 */
//Show the video with the path url
var showVideo = function(url, url_large){
   /* Flash */   
   var flashvars = {};
   flashvars.swfPath = pathRessources + "/flash/playerVideo/swf/"; //Path of swf files
   flashvars.flv_url = url; //Path of the flv file, calculated from the swf path
   flashvars.video_large = url_large;

   var params = {};
   params.menu = "false";
	params.allowscriptaccess = "always";
   params.wmode = "transparent";
   var attributes = {};
   attributes.id = "playerVideo";
	var swf = pathRessources + "/flash/playerVideo/swf/loaderVideo.swf";
	var swfInstall = pathRessources + "/flash/swf/expressInstall.swf";
   swfobject.embedSWF(swf, "playerVideo", "322", "202", "9.0.0", swfInstall, flashvars, params, attributes);
  /* END Flash */	
}

var playVideo = function(){
   $("#layerVideoLarge").fadeOut();
   $("a.playVideo").click(function(){
      $("#layerVideo").css("visibility", "visible"); //Show the layer that contains the video player
      $("#layerVideo").fadeIn(); //fade in effect
      var theHref = $(this).attr("href");
      var flv = getParam(theHref, "url");
      var flv_large = getParam(theHref, "url_large");
		var idText = getParam(theHref, "divTextId");
		//Changer text pour autres videos
		if(idText){
			$(".videoInfos").hide();
			$("#"+idText).show();
			$(".goToPdtSheet").hide();
			$("#"+idText+"Fiche").show();
		}
      showVideo(flv, flv_large); //Show the video that the path is passed in the href of the link
		$("#btPlayVideo").css("visibility", "hidden");
      return false;
   });
}

var playVideoLarge = function(url_large, tempsTotal, tempsPassed, volumeSon, playingOrNot){

	$("#layerVideoLarge").css("visibility", "visible"); //Show the layer that contains the video player
   $("#layerVideoLarge").fadeIn(); //fade in effect      
   showVideoLarge(url_large, tempsTotal, tempsPassed, volumeSon, playingOrNot);
}

//Show the large video
var showVideoLarge = function(url_large, tempsTotal, tempsPassed, volumeSon, playingOrNot){

	/* Flash */   
    var flashvars = {};
	flashvars.swfPath = pathRessources +"/flash/playerVideo/swf/"; //Path of swf files
   //Path of the flv file, calculated from the swf path, flv_name is sent by the small video player
	flashvars.flv_name = url_large; //swfobject.getQueryParamValue("flv_name");

	flashvars.tempsTotal = tempsTotal;
	flashvars.temps = tempsPassed;
	flashvars.volumeSon = volumeSon;
	flashvars.PlayingOrNot = playingOrNot;
	var params = {};
	params.allowscriptaccess = "always";
	//params.wmode = "transparent";
	var attributes = {};
	attributes.id = "playerVideoLarge";
	var swf = pathRessources + "/flash/playerVideo/swf/loaderVideoGrand.swf";
	var swfInstall = pathRessources + "/flash/swf/expressInstall.swf";
	swfobject.embedSWF(swf, "playerVideoLarge", "788", "480", "9.0.0", swfInstall, flashvars, params, attributes);
   /* END Flash */
}

var initVideoLarge = function(){
	var divVideoLarge = '<div id="layerVideoLarge" class="layerVideoLarge"><div class="layerVideoLargeContent">';
	divVideoLarge += '<p><a class="closeVideoLarge" href="javascript:;"><img src="' + pathRessources + '/img/common/bt-fermer.gif" width="59" height="14" alt="" /></a></p>';
	divVideoLarge += '<div id="playerVideoLarge"><a href="#">';
	divVideoLarge += '';
	divVideoLarge += '</a></div></div></div>';
	$("body").append(divVideoLarge);
	  
   $("#layerVideoLarge").fadeOut();
}

var initShowVideoLarge = function(){
	
	$("a.playVideoLarge").click(function(){
	   $("#layerVideoLarge").css("visibility", "visible"); //Show the layer that contains the video player
      $("#layerVideoLarge").fadeIn(); //fade in effect
      var theHref = $(this).attr("href");
      var flv_large = getParam(theHref, "url_large");
      showVideoLargeNoZoom(flv_large); //Show the video that the path is passed in the href of the link
      return false;
   });
}

//Show the large video
var showVideoLargeNoZoom = function(url_large){
	
	/* Flash */   
   var flashvars = {};
	flashvars.swfPath = pathRessources + "/flash/playerVideo/swf/"; //Path of swf files
   //Path of the flv file, calculated from the swf path, flv_name is sent by the small video player
	flashvars.flv_url = url_large; //swfobject.getQueryParamValue("flv_name");

	var params = {};
	var attributes = {};
	attributes.id = "playerVideoLarge";	
	var swf = pathRessources + "/flash/playerVideo/swf/loaderVideoGrandSeul.swf";
	var swfInstall = pathRessources + "/flash/swf/expressInstall.swf";
	swfobject.embedSWF(swf, "playerVideoLarge", "788", "480", "9.0.0", swfInstall, flashvars, params, attributes);
   /* END Flash */
}

var getParam = function(params, variable) {
    params = params.replace("#?", "");
    var vars = params.split("&");    
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    } 
}


var initCloseVideo = function(){
   //Hide the layer that contains the video player
   $("a.closeVideo").click(function(){
		closeVideo();
      return false;
   });
}

var closeVideo = function(){
	$("#playerVideo").remove();
	$("#layerVideo").append('<span id="playerVideo"></span>');
	$("#layerVideo").fadeOut();
	if($("#btPlayVideo").is("p")){
		$("#btPlayVideo").css("visibility", "visible");
	}
	if($(".videoInfos").is("div")){
		$(".videoInfos").hide();
		$("#videoTextMain").show();
		$(".goToPdtSheet").hide();
		$("#ficheLinkMain").show();
	}
}

var closeVideoLarge = function(){
   //Hide the layer that contains the video player
   $("a.closeVideoLarge").click(function(){
		// ask the time passed from the beginning
		/*var temps = 0;
		var volumeSon = 0;
		var playingorNot = 0;
		var obj = swfobject.getObjectById("playerVideoLarge");
		if (obj)
		{
			playingorNot = obj.getPlayingOrNot();
			temps = obj.demandeTempsPassed();
			volumeSon = obj.volumeSonGrandeVideo();
			
		}
	
	
	  	 //Hide the layer that contains the video player
		$("#playerVideoLarge").remove();
		$("#layerVideoLarge").append('<div id="playerVideoLarge"></div>');
	
	
		var obji = swfobject.getObjectById("playerVideo");
		if (obji)
		{
			obji.setPlayingOrNot(playingorNot);
			obji.avecLeVolumeSon(volumeSon);
			obji.aPartirDuTempsJavascript(temps);
		}*/		
		$("#playerVideoLarge").remove();
		$("#layerVideoLarge").append('<div id="playerVideoLarge"></div>');
		$("#layerVideoLarge").fadeOut();
		closeVideo();
	   return false;
   });
}

var closeVideoLargeFromFlash = function(){
	// ask the time passed from the beginning
	var temps = 0;
	var volumeSon = 0;
	var playingorNot = 0;
	var obj = swfobject.getObjectById("playerVideoLarge");
	if (obj)
	{
		playingorNot = obj.getPlayingOrNot();
		temps = obj.demandeTempsPassed();
		volumeSon = obj.volumeSonGrandeVideo();
		
		//alert('on recoit du grand, le playing or not : '+playingorNot);
	}
  	 //Hide the layer that contains the video player
	$("#playerVideoLarge").remove();
	$("#layerVideoLarge").append('<div id="playerVideoLarge"></div>');

	// modif Guillz
	//var obji = swfobject.id("playerVideo");
	var obji = swfobject.getObjectById("playerVideo");
	if (obji)
	{
		obji.setPlayingOrNot(playingorNot);
		obji.avecLeVolumeSon(volumeSon);
		obji.aPartirDuTempsJavascript(temps);
		
		//alert('on envoit dans le petit, le playing or not : '+playingorNot);
		
	}
	$("#layerVideoLarge").fadeOut();
    //  return false;
}

/* onload */
$(document).ready(function(){
   playVideo();
	initShowVideoLarge();
	initVideoLarge();
   initCloseVideo();
	closeVideoLarge();
});
/* END onload */

/* END MODIFIED ON JULY 2009 */
