/* Copyright (c) 2011 Cihan UYGUN (cihanuygun AT gmail DOT com || http://www.cihanuygun.com)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * See http://kelvinluck.com/assets/jquery/jScrollPane/
 * $Id: jquery.SetExternal.js v1 28.10.2011 07:05:14 cihanuygun $
 */

/*  
	Author : elmalma | marka iletişim hizmetleri
	Author URL: http://www.elmalma.com/
	Description: SetExternal JS File
	Tags: elmalma

	Copyright: (c) 2009-2011 Elmalma.
*/



$.expr[':'].external = function(obj){
	return !obj.href.match(/^mailto\:/) && !obj.href.match(/^ftp\:/) && !obj.href.match(/^magnet\:/) && !obj.href.match(/^$/)
			&& (obj.hostname != location.hostname);
};

/*$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
};*/

jQuery.fn.setExternal = function() {
    var args = arguments[0] || {};
    var autoExternal = args.autoExternal;
    var externalRelation = args.externalRelation;
    var mySelector = jQuery(this);

	if (jQuery("a",mySelector).lenght == 0) return false;

	jQuery('a[rel="'+externalRelation+'"]',mySelector).click(function(){
		var target = jQuery(this).attr("href");
		return !window.open(target);
	})
	
	if (autoExternal)
	{
		jQuery("a:external",mySelector).each(function(){
			jQuery(this).click(function(){
				var target = $(this).attr("href");
				return !window.open(target);
			})
		}).addClass("external");
	}
}
