/****************************************************
 * ExternalLink - jQuery plugin
 *
 *	http://www.zen-in-progress.com/post/externallink-plugin-jquery
 *
 * Copyright (c) 2009 BAREAU Stéphane
 *
 *  Inspired by:
 *     Babylon Design from Samuel Le Morvan (http://www.babylon-design.com/share/faviconize/)
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 ****************************************************/
 (function($) {
  // plugin definition
  $.fn.externalLink = function(options) {
    var opts = $.extend({}, $.fn.externalLink.defaults, options);
    
    return this.each(function(i,elt) {      
      $this = $(this);
      $this = $this.filter("[href^=\"http\"]");

      $this = $this.not("[href*=\""+document.domain+"\"]");
      $this = $this.not("[href*=\""+'canam-steeljoist.ws'+"\"]");
      $this = $this.not("[href*=\""+'canam-steeljoists.ws'+"\"]");
      $this = $this.not("[href*=\""+'canam-poutrelle.ws'+"\"]");
      $this = $this.not("[href*=\""+'canamgroup.ws'+"\"]");
      $this = $this.not("[href*=\""+'canaminternational.ws'+"\"]");
      $this = $this.not("[href*=\""+'goodcoztech.ws'+"\"]");
      $this = $this.not("[href*=\""+'hambro-floors.ws'+"\"]");
      $this = $this.not("[href*=\""+'hambro-planchers.ws'+"\"]");
      $this = $this.not("[href*=\""+'structalbridges.ws'+"\"]");
      $this = $this.not("[href*=\""+'structalcharpente.ws'+"\"]");
      $this = $this.not("[href*=\""+'structalponts.ws'+"\"]");
      $this = $this.not("[href*=\""+'structalstructure.ws'+"\"]");
      $this = $this.not("[href*=\""+'technyx.ws'+"\"]");
      $this = $this.not("[href*=\""+'vertispace-mezzanines.ws'+"\"]");
      $this = $this.not("[href*=\""+'groupecanam.ws'+"\"]");
      $this = $this.not("[href*=\""+'buildmaster.com'+"\"]");
      $this = $this.not("[href*=\""+'canam.ws'+"\"]");
	
      var pictures=$this.has("img");
      pictures.each(function(){$(this).attr('target','_blank');});

      $this = $this.not(":has(img)");
      $this.each(function()
      {
	if (opts.area == 'false')
	{
	  	var a   = document.createElement('a');
        	var img = document.createElement('img');
	        $(img).attr('src',opts.default_img);
        	a.appendChild(img);
		$(this).after($(img));
	}
	$(this).attr('target','_blank');	
      });
    });
  };

  // plugin defaults
  $.fn.externalLink.defaults = {
      default_img: '/www/v4/webcom.nsf/LinkOut.png'
  };

})(jQuery);