/**
 * Chargement de la Phototèque (Appel depuis page.common.js)
 * - Affichage des images de l'hippodrome si sélectionné
 * - Affichage des images "generiques" dans le cas contraire
 */
function loadPhototeque()
{
	if ($("#phototheque_td"))
	{
		setTimeout(function() {$("#phototheque_td").empty; phototeque_ajax_call();} , 50);
	}
}

/**
 * Variables de la phototèque
 */
var aPhotothequeImages = new Array();
var iPhotothequeWidth = 0;
var iPhotothequeHeight = 0;

/**
 * Appel du script PHP en Ajax pour la récuperation des images
 */
function phototeque_ajax_call()
{
	// Largeur de la phototèque
	iPhotothequeWidth = $('#phototheque_td').width();
	
	// Hauteur de la phototèque
	iPhotothequeHeight = $('#phototheque_td').height();
	
	if ((iPhotothequeWidth == 0) || (iPhotothequeHeight == 0))
		return;
	
	// Padding en trot
	var padding_left = parseInt($('#phototheque_td').css('padding-left'));
	var padding_right = parseInt($('#phototheque_td').css('padding-right'));
	var padding_top = parseInt($('#phototheque_td').css('padding-top'));
	var padding_bottom = parseInt($('#phototheque_td').css('padding-bottom'));

	//iPhotothequeWidth = iPhotothequeWidth - padding_left - padding_right;
	//iPhotothequeHeight = iPhotothequeHeight - padding_top - padding_bottom;
	
	if (typeof(hippodrome_id) != 'undefined')
	{	
		// Requête AJAX
	    $.ajax({
	    	// Fichier cible php :
	    	url : "ajax/ajax.phototheque.php",
	    	// Type de requête
	    	type : "GET",
	    	// Type de données renvoyées : JSON
	    	dataType : "json",
	    	// Paramètres :
	    	data : {hippodrome_id: hippodrome_id, size: (iPhotothequeWidth + '_' + iPhotothequeHeight)},
	    	// Callback :    	
	    	success : phototheque_ajax_callback
	    });
	}
	else
	{
		// Requête AJAX
	    $.ajax({
	    	// Fichier cible php :
	    	url : "ajax/ajax.phototheque.php",
	    	// Type de requête
	    	type : "GET",
	    	// Type de données renvoyées : JSON
	    	dataType : "json",
	    	// Paramètres :
	    	data : {size: (iPhotothequeWidth + '_' + iPhotothequeHeight)},
	    	// Callback :    	
	    	success : phototheque_ajax_callback
	    });
	}
}

/**
 * Retour du script PHP en ajax pour la récuperation des images
 * @param oJson
 */
function phototheque_ajax_callback(oJson)
{
	$('#phototheque_td').empty();
	
	// Ventilation des données dans le tableau
	aPhotothequeImages = new Array();
	
	for (i in oJson)
		aPhotothequeImages.push(oJson[i]);
	
	if (aPhotothequeImages.length > 0)
	{	
		var html = "";
		
		// Création des paragraphes defilants via innerfade en jQuery
		for (i in aPhotothequeImages)
			html += '<img src="' + aPhotothequeImages[i].url + '" alt="" style="width: ' + iPhotothequeWidth + 'px; height: ' + iPhotothequeHeight + 'px; " />';
		
		$('#phototheque_td').html(html);
		
		// Fondu entre les paragraphes des arrivées
		$('#phototheque_td').innerfade({
			animationtype: 'fade',
			speed: 1000,
			timeout: 5000,
			containerheight: iPhotothequeHeight + 'px',
			type: 'random'
		}); 
	}
}
