(function($){
	$.popup = function(params){
		if($('#popup-overlay').length){
				$.popup.hide;				
		}
		
		var options = { 
			width	  	: '420',
			height	  	: '300',
		  	id        	: 'popup-box',
			title		: 'Numero de tel',
			close		: true,
      		scrollBar 	: false, 
      		content		: '',
			buttons	: {}
		};
		
		$.extend(true, options, params);
		
		
		
		
		   var _popupTitle     = (options.title) ? '<h3>'+ params.title + '</h3>' : '';
		       _popupTitle    += (options.close) ? '<a id="popup-close" href="javascript:void(0)" >close</a>' : '';
		
		   var _buttonHtml     = '';
		
		$.each(options.buttons,function(name,obj){		
			// Generating the markup for the buttons:			
			v += '<a href="#" class="button '+obj['class']+'"><span>'+name+'</span></a>';			
			if(!obj.action){
				obj.action = function(){};
			}
		});
		if('' != _buttonHtml) _buttonHtml = '<div id="popup-buttons">',_buttonHtml,'</div>';
		     
		var markup = [
			'<div id="popup-overlay" >',
			'<div id="',options.id,'" class="popup-box clearfix">',
			'<div id="popup-title">',_popupTitle,'</div>',
			'<div id="popup-content">',options.content,'</div>',
			,_buttonHtml,'</div></div>'
		].join('');
		
		$(markup).hide().appendTo('body').fadeIn(function(){$(this).show()});

    // on centre la popup   
      $('.popup-box').css({
          marginLeft: - Math.ceil(options.width / 2) + 'px',       
          width: options.width + 'px'
      });   
      $('.popup-box').css({
          marginTop: - Math.ceil(options.height / 2) + 'px',       
          height: options.height + 'px'
       });
      
   	
    //gestion des actions des boutons    
		var _buttons = $('#popup-buttons .button'),
			i = 0;
		$.each(options.buttons,function(name,obj){
			_buttons.eq(i++).click(function(){			
				obj.action();
				$.popup.hide();
				return false;
			});
		}); 
		
		// param�trage du contenu
		$('#popup-content').css('overflow', options.scrollBar ? 'auto' : 'hidden')
						   .height(options.height-$('#popup-title').outerHeight(true)- $('#popup-buttons').outerHeight(true));
		if(options.scrollBar){
			$('#popup-buttons').css('border-top','1px solid #f7f4ef');
		}
		
     $("#popup-close").click(function(){ 
    	 $.popup.hide();	
     }); 
	}
	$.popup.hide = function(){
		$('#popup-overlay').fadeOut(function(){
			$(this).remove();
		});
	}
})(jQuery);

