/*******************************
 * Fonctions js d'affichage dela popup de bienvenue (pour les sponsors).
 * 
 * Nécéssite :
 *  - jquery.js
 *  - popups.js
 */
var Bienvenue = function() {
	
	/**
	 * Ouvre la popup de bienvenue.
	 * @param string idPopup identifiant de la balise div
	 * 			devant afficher le contenu de la popup.  
	 */
	var ouvrir = function(idPopup) {
		$('#' + idPopup).css('display', 'block');
		Popups.ouvrirPopup(null, idPopup);
		
		$.ajax({
			url: 'ws/bienvenue.php?idPopup=' + idPopup,
			success: function(html) {
			affContenu(idPopup, html);
				$('#' + idPopup).html(html);
			},
			error: function(xhr, status, error) {
				alert(status + ' ' + error);
			},
			cache: false
		});
	};

	/**
	 * Ferme la popup de bienvenue.
	 * @param string idPopup identifiant passé à ouvrir()
	 */
	var affContenu = function(idPopup, html) {
	    
		$('#' + idPopup).html(html);
		
		setTimeout('Bienvenue.affLigne(0)', 200);
	};
	
	var affLigne = function(noLigne) {
		
    	$('#bienvenue-ligne-div-' + noLigne).stop().animate(
            {width: String(13 + noLigne * 5) + 'em'},
            {queue: false,
            duration: 600,
            easing: 'easeOutExpo'
        });

    	if (noLigne < 5) {
    		setTimeout('Bienvenue.affLigne(' + String(noLigne + 1) + ')', 150);
    	}
	};
	
	/**
	 * Ferme la popup de bienvenue.
	 * @param string idPopup identifiant passé à ouvrir()
	 */
	var fermer = function(idPopup) {
		Popups.fermerPopup(idPopup);
	};
	
	return {
		ouvrir: ouvrir,
		fermer: fermer,
		affLigne: affLigne
	};
	
}();