/**
 * jExternalLink
 * @author Tenderfeel
 * @ver 1.0
 * @HOME http://tenderfeel.xsrv.jp/
 * 
 * @Need:jQuery ver1.2.6 upper
 * 
 * ---MIT License--------------------------------------------
 * Copyright (c) 2008 Tenderfeel all rights reserved.
 * 以下に定める条件に従い、本ソフトウェアおよび関連文書の
 * ファイル（以下「ソフトウェア」）の複製を取得するすべての
 * 人に対し、ソフトウェアを無制限に扱うことを無償で許可します。
 * これには、ソフトウェアの複製を使用、複写、変更、結合、
 * 掲載、頒布、サブライセンス、および/または販売する権利、
 * およびソフトウェアを提供する相手に同じことを許可する権利も無制限に含まれます。
 * 
 * 上記の著作権表示および本許諾表示を、
 * ソフトウェアのすべての複製または重要な部分に記載するものとします。
 * 
 * ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、
 * 何らの保証もなく提供されます。ここでいう保証とは、商品性、
 * 特定の目的への適合性、および権利非侵害についての保証も含みますが、
 * それに限定されるものではありません。作者または著作権者は、
 * 契約行為、不法行為、またはそれ以外であろうと、
 * ソフトウェアに起因または関連し、あるいはソフトウェアの使用
 * またはその他の扱いによって生じる一切の請求、損害、
 * その他の義務について何らの責任も負わないものとします。 
 * ----------------------------------------------------------
 */
(function(jQuery) { 
	jQuery.fn.jExternalLink = function(options){
		
		//オプションとデフォルト値
		var options = jQuery.extend({
		   open:"blank",
			elements:"a",
			iconSrc:'http://sv58.wadax.ne.jp/~tamatur-bali-com/wordpress/wp-content/plugins/AutoExternalLink-jquery/external.gif',
			iconW:"12",
			iconH:"11",
			iconAlt: "",
			linkTitle:"リンクを新しいウインドウで開く",
			excludeStr:["tamatur-bali.com","http://sv58.wadax.ne.jp/","www.deliciousdays.com","accuweather.com"],
			includeClass:"newwin",
			escapeTag:[]
		}, options);
		
		return this.each(function(){
			
			var anchors = jQuery(this).find(options.elements);
			
			anchors.each(function(){
				var href = jQuery(this).attr("href");
				var child = jQuery(this).children("img");
				var flag = 0;
				
				for(j = 0; j <options.excludeStr.length; j++){
				
					if(href.indexOf(options.excludeStr[j]) !== -1 || href == "#" || href==""){
						flag++;
					}
				}
				
				for(n = 0; n <options.escapeTag.length; n++){
					if($(this).parent().filter(options.escapeTag[n])[0]!=null) flag++;
				}
				
				if(jQuery(this).hasClass(options.includeClass) == true ) flag = 0;
				
				
				if(flag == 0){
					if(child.length !== 0){
						if(options.open == "js")
							jQuery(this).attr('onclick','window.open(this.href,\'\',\'status=yes,scrollbars=yes,directories=yes,menubar=yes,resizable=yes,toolbar=yes\'); return false;');				
						else
							jQuery(this).attr("target","_blank");
					}else{
						if(options.open == "js")
							var ANC = jQuery("<a href=\""+href+"\" class=\"newWin\" title=\""+options.linkTitle+"\" onclick=\"'window.open(this.href,\'\',\'status=yes,scrollbars=yes,directories=yes,menubar=yes,resizable=yes,toolbar=yes\'); return false;'\"></a>");
						else
							var ANC = jQuery("<a href=\""+href+"\" class=\"newWin\" title=\""+options.linkTitle+"\" target=\"_blank\"></a>");
					
						ANC.html('<img src="'+options.iconSrc+'" width="'+options.iconW+'" height="'+options.iconH+'" alt="'+options.iconAlt+'" />');
						jQuery(this).after(ANC);
					}
				}
						
			});
			
		});
		
	};
})(jQuery);

jQuery.noConflict();
jQuery(document).ready(function(){
	jQuery("#content").jExternalLink();
	jQuery("#sidebar").jExternalLink();
});