//<![CDATA[

/*
	name : com.site.externallinks
	author : gregory tomlinson
	///////////////////////////
	///////////////////////////		
	dependencies : mootools 1.2
	///////////////////////////
	///////////////////////////

*/

if( typeof com == "undefined" ) var com = {};
if( typeof com.site == "undefined" ) com.site = {};

com.site.externallinks = new Class({

	Implements: [Options, Events],

	options : {
		currentServer : '',
		extLnkClass : 'external',
		autoRun : true,
		onComplete : $empty
	},
	
	server : '',
	
	initialize : function (options)
	{
		this.setOptions(options);
		if(this.options.autoRun) this.run();
	},
	
	run : function() {
		this.setServer();
		this.convertLinks();
	},
	
	setServer : function(  ) {
		this.server = ( this.options.currentServer != '' ) ? this.options.currentServer : document.location.host;
	},
	
	convertLinks : function() {
		var b = $$('body')[0], lnks = b.getElements('a');
		lnks.each( function(item) {
			var h = item.get('href')
			if( h.indexOf('http') >= 0 && h.indexOf( this.server ) < 0 ) {
				item.set('target', '_blank');
				if( this.options.extLnkClass != '' )item.set('class', this.options.extLnkClass )
			}
		}, this );
		
		this.fireEvent( 'complete', { "statusText" : "ok", options : this.options } );
	}

});

//]]>