/* FavoriteIcon v1.1 - 5 May 09 (http://blog.liviuholhos.com/javascript/add-a-favicon-near-external-links-with-jquery)
 * Author : Liviu Holhos (http://www.liviuholhos.com/) */
(function($){
	$.fn.favoriteIcon = function(options) {
		var defaults = {
			iconClass    : 'favoriteIcon',
			insertMethod : 'appendTo',
			iconSearched : 'external.png'
		};
		var options = $.extend(defaults, options);
	
		$(this).filter(function(){
			return this.hostname && this.hostname !== location.hostname;
		}).each(function() {
			var link = jQuery(this);
			var faviconURL = link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1')+'/'+options.iconSearched;
			var faviconIMG = jQuery('<img class="'+options.iconClass+'" src="/images/external.png" />')[options.insertMethod](link);
			var extImg = new Image();
			extImg.src = faviconURL;
			if (extImg.complete)
				faviconIMG.attr('src', faviconURL);
			else
				extImg.onload = function() { faviconIMG.attr('src', faviconURL); };
		});
	
	}
	
		$.fn.favoriteIconz = function(options) {
		var defaults = {
			iconClass    : 'favoriteIconz',
			insertMethod : 'appendTo',
			iconSearched : 'pdficon_small.gif'
		};
		var options = $.extend(defaults, options);
	
		$(this).filter(function(){
			return this.hostname && this.hostname !== location;
		}).each(function() {
			var link = jQuery(this);
			var faviconzURL = link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1')+'/'+options.iconSearched;
			var faviconzIMG = jQuery('<img class="'+options.iconClass+'" src="/images/pdficon_small.gif" />')[options.insertMethod](link);
			var extImg = new Image();
			extImg.src = faviconzURL;
			if (extImg.complete)
				faviconzIMG.attr('src', faviconzURL);
			else
				extImg.onload = function() { faviconzIMG.attr('src', faviconzURL); };
		});
	}


		$.fn.favoriteIcondcccd = function(options) {
		var defaults = {
			iconClass    : 'favoriteIcondcccd',
			insertMethod : 'appendTo',
			iconSearched : 'dcccdicon.gif'
		};
		var options = $.extend(defaults, options);
	
		$(this).filter(function(){
			return this.hostname && this.hostname !== location;
		}).each(function() {
			var link = jQuery(this);
			var favicondcccdURL = link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1')+'/'+options.iconSearched;
			var favicondcccdIMG = jQuery('<img class="'+options.iconClass+'" src="/images/dcccdicon.gif" />')[options.insertMethod](link);
			var extImg = new Image();
			extImg.src = favicondcccdURL;
			if (extImg.complete)
				favicondcccdIMG.attr('src', favicondcccdURL);
			else
				extImg.onload = function() { favicondcccdIMG.attr('src', favicondcccdURL); };
		});
	}

})(jQuery);
