function showLightBox(source, container, insc, bouton)	{

	//jQuery('div#lightbox').addClass(container);
	//jQuery('div#lightbox').addClass(insc); // Ajout class qui choisit l'onglet inscription par defaut	
	
	// overwrite le z-index de la navbar pour le lightbox	
	jQuery("#navbarCanoe_container").css({ "z-index": "2999" });
	
	
	/* si cest un bouton supprimer, on change la source du lightbox vers le bon lightbox
	* Le fonctionnement des different des autres lightbox, le href est ladresse directement
	* de la page qui supprime le node choisi. On va chercher 3 parametres sur le bouton :
	* le node id, l'adresse de la page pour deleter et le contenu a afficher dans le lightbox.
	*/
	var isSupprimer = bouton.hasClass('btSupprimer');
	if(isSupprimer){
		var source = "/sites/default/themes/qhf/bidon/delete-lightbox.html";
		var target = bouton.attr('href');
		var content = bouton.attr('content');
		var node_id = bouton.attr('nid');
	}
	
	// onShow : show+make the window translucent
	var myOpen=function(hash){
			
		jQuery('#conteneurLightbox').load(source, function(data){
    		
    		if(isSupprimer){
    			jQuery("div#lightbox p.loginBlocMessage").html("Voulez-vous vraiment supprimer l\'élément :<br/><strong>"+content+"</strong>");
    			jQuery("div#lightbox form").attr('action', target);
			}
			
			functions.popLightboxLogin();
			functions.recenterLightbox();
			//jQuery('div.jqmOverlay').css({ "display": "none" });
			jQuery('div.jqmOverlay').fadeIn('medium');
		
			hash.w.fadeIn('medium',function(){ hash.o.show(); }); 
		});
	};
	jQuery('div#lightbox').jqm({onShow:myOpen}); 




	// onHide : fade the window out, remove overlay after fade.
	var myClose=function(hash) { 
		jQuery('div.jqmOverlay').fadeOut('slow'); 		
		hash.w.fadeOut('slow',function(){ 
			hash.o.remove();		
			//jQuery('div#lightbox').removeClass(container);				
			//jQuery('div#lightbox').removeClass(insc);		// Remove class qui choisit l'onglet inscription par defaut	
		});
	};	
	jQuery('div#lightbox').jqm({onHide:myClose});
	
	jQuery('div#lightbox').jqm({modal: true});
	jQuery('div#lightbox').jqmShow();
	
	
	
	return true;
}

(function($) {
	$(document).ready(function() {
		/* bind au click pour popper un lightbox */
		$("a[href][rel='lightbox']").click(function(event){

						
			showLightBox($(this).attr('href'),$(this).attr('class'),$(this).attr('id'), $(this));
			return false;
		});
		
		
		functions =  {
			/* function qui calcul les dimenssions des lightbox pour les centrer */
			recenterLightbox: function(){
				var lightboxType = $('.lightboxContent');
				var setX = Math.floor((parseInt(lightboxType.css('width'), 10) + parseInt(lightboxType.css("padding-left"), 10) + parseInt(lightboxType.css("padding-right"), 10)) / 2);
				var setY = Math.floor((parseInt(lightboxType.css('height'), 10) + parseInt(lightboxType.css("padding-top"), 10) + parseInt(lightboxType.css("padding-bottom"), 10)) / 2);
				
				$('#lightbox').css('marginLeft', '-' + setX + 'px');
				$('#lightbox').css('marginTop', '-' + setY + 'px');
			},
			/* Define les comportement du lightbox login au moment ou il est cree */
			popLightboxLogin: function(){
			
				function delayLightboxForIE(){ // Cache le lightbox et le fait rapparaitre pour empecher de voir glitcher de btn a coins ronds
					if($.browser.msie){
						$("#lightbox").css({"z-index":"-1"});
						var t = setTimeout( function() {
							$("#lightbox").css({"z-index":"3000"});
						}, 250);
					}
				}
				
				// Bind des click pour afficher les differentes vue du lightbox login
				$('#newPassword').bind('click', function(){
					delayLightboxForIE();
					$('#lightboxLogin').hide();
					$('#lightboxPassword').show();
				});
				
				$('#annulerPassword').bind('click', function(){
					delayLightboxForIE();
					$('#lightboxPassword').hide();
					$('#lightboxLogin').show();
				});
				
				//Dirige au href du lien clique : bug fix de ie d'un href dans le lightbox
				$('a.forceLocation').bind('click', function(){
					document.location.href = $(this).attr('href');
				});
				


			}
		}

	});
})(jQuery);
