//ajax par jquery
jQuery(document).ready(function(){

	getVisage(1);
	getProgramme(1);
    getEcouter(1);
	jQuery('#go').click(function(){
		getProgramme('1');
	});
    jQuery('#go2').click(function(){
		getEcouter('1');
	});
});




function load(id){

	jQuery('#'+id).empty();
	jQuery('#'+id).html('<img src="/photo/images_default/ajax-loader.gif">');
}

function getVisage(p){
	jQuery("#visage").fadeOut(200, function() {load('visage');jQuery("#visage").fadeIn(200);});
	//setTimeout("load('visage')", 200);
	//jQuery("#visage").fadeIn(200);

	jQuery.ajax({
	   type: "POST",
	   dataType: "html",
	   data: "page="+p+"&type=1",
	   url: "/zp/templates/phototheque/JX_voir.php",
	   error:function(msg){
	     alert( "Error !: " + msg );
	   },
	   success:function(data){
	   	//affiche le contenu du fichier dans le conteneur
		jQuery("#visage").empty();
		jQuery("#visage").fadeIn(200)
		jQuery("#visage").append(data);


		init_ibox();
	}});

}



function getEcouter(p){
	jQuery("#ecouter").fadeOut(200);
	setTimeout("load('ecouter')", 200);
	jQuery("#ecouter").fadeIn(200);

	jQuery.ajax({
	   type: "POST",
	   dataType: "html",
	   data: "page="+p+"&type=1&idP="+jQuery('#idP2').val(),
	   url: "/zp/templates/phototheque/JX_ecouter.php",
	   error:function(msg){
	     alert( "Error !: " + msg );
	   },
	   success:function(data){
	   	//affiche le contenu du fichier dans le conteneur
		jQuery("#ecouter").empty();
		jQuery("#ecouter").fadeIn(200)
		jQuery("#ecouter").append(data);


		init_ibox();
	}});

}


function getProgramme(p){
	jQuery("#programme").fadeOut(200);
	setTimeout("load('programme')", 200);
	jQuery("#programme").fadeIn(200);

	jQuery.ajax({
	   type: "POST",
	   dataType: "html",
	   data: "page="+p+"&type=2&idP="+jQuery('#idP').val(),
	   url: "/zp/templates/phototheque/JX_voir.php",
	   error:function(msg){
	     alert( "Error !: " + msg );
	   },
	   success:function(data){
	   	//affiche le contenu du fichier dans le conteneur
		jQuery("#programme").empty();
		jQuery("#programme").fadeIn(200)
		jQuery("#programme").append(data);


		init_ibox();
	}});

}

function displayPhoto(){
	srcVal = jQuery('#srcPhoto').val();

	jQuery("#iPhoto").attr("src",srcVal);;

}

function displayFLV() {
	try {
		flv('/photo/images_default/player.jpg', jQuery("#val_flv").attr('value'));
	} catch(err) {}
}

function displayAudio(){
    jQuery("#iAudio")

}

function displaytexte(){
    jQuery("#itexte").empty();

    	jQuery.ajax({
	   type: "POST",
	   dataType: "html",
	   data: "page=0&id="+jQuery('#idVerbatim').val(),
	   url: "/zp/templates/phototheque/JX_verbatim.php",
	   error:function(msg){
	     alert( "Error !: " + msg );
	   },
	   success:function(data){
	   	//affiche le contenu du fichier dans le conteneur
		jQuery("#itexte").empty();
		jQuery("#itexte").fadeIn(200)
		jQuery("#itexte").append(data);
       }});



}

function downloadDoc(prefix, doc_url) {
	if(doc_url != '') window.location = 'http://'+ prefix + doc_url;
	return false;
}

function getPDFList() {
	jQuery.ajax({
		type: "POST",
		dataType: "html",
		data: "class=bul_pdf&method=getPdfList",
		url: "/ajax/request.php",
		beforeSend: function() {
			jQuery("#pdf_list").html('<p><img src="/templates/publicsenat/images/loading.gif" alt="Loading ..." /></p>');
		},
		error:function(msg){ },
		success:function(data){ jQuery("#pdf_list").html(data); init_ibox(); }
	});
}

function regenerePDF() {
	new Ajax.Request(
		"/ajax/request.php" ,
		{
			method: 'post'
		,   parameters: "class=bul_pdf&method=getPdfList&params[force]=1"
		,   onLoading: function() {
				$("pdf_list").innerHTML = '<p><img src="/templates/default/images/loading.gif" alt="Loading ..." /></p>';
			}
		,   onComplete: function(req) { $("pdf_list").innerHTML = 'Les PDF sont regénérés'; }
		}
	);
}

