/**
 * @author Nathan Kelly - http://www.nathan-kelly.com/
 *  my email address is my first name @nathan-kelly.com
 * @copyright 2009 Nathan Kelly
 * @package nk-external-links
 * @version 1.0.0
 * @url http://projects.nathan-kelly.com/
 * @dependencies 
 * 	prototype.js 1.6.0.2+ (http://www.prototypejs.org/)
 *	scriptaculous.js 1.8.1+ (http://script.aculo.us/)
 * @license
 *	Creative Commons Attribution 2.5 Australia License
 *	http://creativecommons.org/licenses/by/2.5/au/
 */

var ExternalLinks = Class.create({
	
	initialize: function() {	
		
		var links = $$('a');
		
		for (var i=0; i<links.length; i++) {
			
			if ( String(links[i].getAttribute('rel')) == 'external' ) {
				
				Element.observe(links[i], 'click', (function(e) {
					
					window.location = links[i].href;
					
					Event.stop(e);
					
				}).bindAsEventListener(this));
				
				
			} else if ( String(links[i].getAttribute('rel')) == 'popdown' ) {
				
				this.popDown(links[i]);
				
			}
			
		}
		
	},

	popDown: function(link) {
		
		Element.observe(link, 'click', (function(e) {

			var mum = window.opener;
			
			self.close();
			
			mum.location = link.href;
			
			Event.stop(e);
			
		}).bindAsEventListener(this));
		
	}	
	
});

document.observe('dom:loaded', function () { new ExternalLinks(); });
