$(document).ready(function(){

    $("#videotheque .slider_tmp a").click(function(){

		if($("#videotheque .playerFlash iframe").length) {
			$("#videotheque .playerFlash iframe").remove();
			$("#videotheque .playerFlash br").remove();
			$("#videotheque .playerFlash a").remove();
			$("#videotheque .playerFlash i").remove();
		}
    	if ($(".embed-"+$(this).attr("id")).val()==0) {
    		$("#videotheque .playerFlash object").show();
    		$("#lecteur_60000").html("");
	        var player = $("#flvplayer");
	        var width = player.attr("width");
	        var height = player.attr("height");

	        var flashvars_60000 = {};
			var params_60000 = {
					quality: "high",
					bgcolor: "#000000",
					allowScriptAccess: "always",
					allowFullScreen: "true",
					wmode: "transparent",				flashvars: "fichier="+this.href
				};
			var attributes_60000 = {};
	        flashObject($("#player_adr").val(), "lecteur_60000", 320, 240, "8", false, flashvars_60000, params_60000, attributes_60000);
	        $("#videotheque .playerFlash object").show();






    	} else {


    		setMotionVideo($(this).attr("id"));
    	}
    	var player = $("#flvplayer");
        var width = player.attr("width");
        var height = player.attr("height");





        var tsp = new Date().getTime();



        $("#titreVideo").text($(this).attr("title"));

        var idvideo = $(this).attr("id").substr(6);
        var language_pos = unescape( $(this).attr("href") ).indexOf("/(language)/", 0);

        var language_code = unescape( $(this).attr("href") ).substr( language_pos+12, 6 );
        // requete ajax pour recup la description longue de la video
        $.get($.ez.ezurl + "/layout/set/video_desc?object_id="+idvideo+"&language_code="+language_code, function(data){
            $("#descVideoAjax").html(data);
        });

        this.blur();
        return false;
    });
    if($("#videotheque .playerFlash iframe").length) {
    	$("#videotheque .playerFlash object").hide();

    }

    $("#phototheque .slider a").click(function(){

        $("#photoContent").attr("src",this.href);
        $("#photoContent").removeAttr("width");
        $("#photoContent").removeAttr("height");

        $("#titrePhoto").text($(this).attr("title"));

        var idphoto = $(this).attr("id").substr(6);
        var language_pos = unescape( $(this).attr("href") ).indexOf("/(language)/", 0);
        var language_code = unescape( $(this).attr("href") ).substr( language_pos+12, 6 );
        // requete ajax pour recup la description longue de la video
        $.get($.ez.ezurl + "/layout/set/photo_desc?object_id="+idphoto, function(data){
            $("#descPhotoAjax").html(data);
        });

        this.blur();
        return false;
    });

});

function setMotionVideo(numID) {

	$("#videotheque .playerFlash object").hide();
	$("#videotheque .playerFlash").prepend($(".youmotion-"+numID).html());
	$("#videotheque .playerFlash iframe").attr('height','240');
	$("#videotheque .playerFlash iframe").attr('width','320');

}

function chargeFlashVideo(href){




    if ($(".youmotion-video-"+$("#first_motionvideo_id").val()+" iframe").length) {
    	setMotionVideo("video-"+$("#first_motionvideo_id").val());
    } else {
    	$("#video-"+$("#first_motionvideo_id").val()).click();
    	$("#videotheque .playerFlash object").show();
    }
};

