﻿

(function($){
 	$.fn.extend({ 
        /***********
         * POPUP
         ***********/
 		popup: function(options) {
 		    
 		    var defaults = {
 		        width: 700,
 		        height: 500,
 		        name: 'popup'
 		    };
 		    
 		    var options = $.extend(defaults, options);
 		    
    		return this.each(function() {
			    
				var o = options;
			    
			    $(this).click(function() {
	                var popup = window.open(
	                    $(this).attr("href"),
	                    o.name,
	                    'width=' + o.width + ',height=' + o.height + ',scrollbars=yes,resizable=yes'
	                );
	                popup.focus();
	                return false;
	            });
    		});
    	}
    	,
        /***********
         * LIEN OUVRANT DANS OPENER DE LA POPUP
         ***********/
    	lienOpener: function(options) {
    	    		    
 		    var defaults = {
 		        autoclose: true
 		    };
 		    
 		    var options = $.extend(defaults, options);
    		return this.each(function() {
			    $(this).click(function() {
			        var w = window.opener;
			        while (w.opener) {
			            w = w.opener;
			        }
			        if (w) {
			            window.opener.location.href = $(this).attr("href");
			            window.opener.focus();
			            if (options.autoclose) {
			                window.close();
			            }
			            return false;
			        }
	            });
    		});

    	}
	});
})(jQuery);
