

jQuery.extend({
	callModal : function(html, height, width, containerClass){
		$('<div class="'+containerClass+'">'+html+'</div>').modal({
			containerCss: {
			    height: height,
			    width: width,
			    backgroundColor: '#414636',
			    border: '3px solid #ccc'
			}
			, overlayCss: {
			    backgroundColor: '#414636',
			    cursor: 'wait'
			}
			, onOpen: function (dialog) {
				dialog.overlay.fadeIn('slow', function () {
					dialog.container.slideDown('slow', function () {
						dialog.data.fadeIn('slow');
					});
				});
			}
			, onClose: function (dialog) {
				dialog.data.fadeOut(200, function () {
				    dialog.container.slideUp(200, function () {
				      dialog.overlay.fadeOut(200, function () {
				        $.modal.close(); // must call this!
				      });
				    });
				});
			}
		});
	}
});



$(document).ready(function() {
	$('.unBonPlan:not(:first)').slideUp(0);
	$('.unBonPlan:first').addClass('current').next().addClass('next');
	$.rollNews();
	

	$("#menus div ul ul").hide();
    $("#menus div ul ul ul").show(); //sous-sous-menus
    $("#menus div ul li a").click(function(){
        $(this).parent().parent().children("li").find("ul.montre").slideToggle("").removeClass("montre").addClass("matched");
        $(this).parent().children("ul").not(".matched").addClass("montre").slideToggle("slow");
        $(this).parent().parent().children("li").find("ul.matched").removeClass("matched");
        if ($(this).attr("href") == "#") {
            return false;
        }
    });
	
	
 	//envoyer a un ami :
 	$('#btnEnvoiLink').click(function() {
 		$('#envoiLinkInputAmi').val($('#envoiLinkInputAmiDebut').val());
 		$('#envoiLinkInputContainer').slideDown('slow'); 		
 		$('#envoiLinkInputSubmit').click(function() {
 			$.get(
 				'/envoie-a-un-ami.php'
 				, $.param($('#envoiLinkContainer .send'))
 				, function(response) { 					
 					$('#envoiLinkInputContainer .result').html(response);		
 				}
 				, 'html'
 			)
 		}); 		
 		$('#envoiLinkInputButtonMoreAmi').click(function() { 			
 			$('.envoiLinkInputAmi:first').clone().insertAfter(".envoiLinkInputAmi:last");
 			$(".envoiLinkInputAmi:last").before('<br />');
 		});
 		
 		$('#envoiLinkInputButtonClose').click(function() { 			
 			$('#envoiLinkInputContainer').slideUp('slow'); 	
 		});
 	});

	
})

 	

jQuery.extend({rollNews : function(){
	
	if ($('.unBonPlan.next').length == 0) {
		$('.unBonPlan:first').addClass('next');
	}
	if ($('.unBonPlan.current').length == 0) {
		$('.unBonPlan:last').addClass('current');
	}
	$('.unBonPlan.current').slideUp(300, function() {
		$(this).removeClass('current')
		$('.unBonPlan.next').slideDown(600, function() {
			$(this).addClass('current').removeClass('next').next().addClass('next');;
			setTimeout($.rollNews, 2000);
		})
	})
	
}});



function memoMenuIdArbo(id) {
	$.get("/menuId2Session.php",{menuId: id },
        function success(data){ // Au succès on renvoie le résultat de la requête
        	//alert(data); // Affichage
    });
}