var SL_FileTypeLinks = new Class({

	//implements
	Implements: [Options],	

	//options
	options: {
	items:  null,					//Array of elements to scan
	autoStart: true				//autostart flag
	},

	//initialization
	initialize: function(options) {
		
		this.setOptions(options);
		if(this.options.autoStart == true)	this.start();
	
	},

	//startup method
	start: function() {
		
		//thanks to David Walsh for this little tip to avoid using 'bind'
		var self = this;
		
		self.options.items.each(function(el, i){
			//f.y.i.  el = the element, i = the index
			var theHref = el.get('href');
			
			// get the extension from the href
			var hrefArray = theHref.split('.');
			var extension = hrefArray[hrefArray.length - 1];
			extension = extension.toUpperCase();
			
			
			//get link text, and append extension
			var theTxt = el.get('text');
			var newTxt = theTxt + " (." + extension + ")";
			el.set('text', newTxt);
		
		 });
		
		
		
	},
	
	
	parseTwitterNames: function (theText) {
		
		var oldText = theText; 
		//newText = oldText.replace(/[(<=^|\s)]+[@]+([\w]+)/g, function(u) {  //this screws up with parentheses near items...grrr
		newText = oldText.replace(/[<=^|\s]+[@]+([\w]+)/g, function(u) {	//now doesn't handle usernames inside parentheses									  
			u = u.trim();
			var username = u.replace("@","");
			var newLink = ' <a href="http:\/\/www.twitter.com\/'+username+'" target=\"_blank\">@'+username+'<\/a>';
			return newLink;
		});
		
		return newText;
		
	},
	
	
	parseTwitterHashes: function (theText) {
		
		var oldText = theText; 
		newText = oldText.replace(/[<=^|\s]+[#]+([\w]+)/g, function(h) {
			h = h.trim();
			var hashtag = h.replace("#","");
			var newLink = ' <a href="http:\/\/www.hashtags.org\/tag\/'+hashtag+'" target=\"_blank\">'+h+'<\/a>';
			return newLink;
		});
		
		return newText;
		
	},
	
	setLink : function(el, server) {
		var h = el.get('href');
		if( h.indexOf('http') >= 0 && h.indexOf(server.getLocation() ) < 0 ) {
			el.set('target', '_blank');
			if(this.options.externalLinkClass) el.set('class', this.options.externalLinkClass);
		}					
		return el;
	},
	
	setLocation : function() {
		var s = ( this.options.currentServer !== '' ) ? this.options.currentServer : document.location.host;
		return {
			getLocation : function() { return s; }
		}
	}



});
