var ExitWarning = {
	init:function() {
		// VARS
		this.url = undefined;

		// ELEMENT REFERENCES
		this.elWindow = $('div#exitWarning');
		this.elContinueBtn = $('a:eq(1)',this.elWindow);
		this.elCancelBtn = $('a:eq(0)',this.elWindow);

		// SETUP
		this.initExternalLinks();
		
		this.elContinueBtn.attr('target', '_blank');
		this.elCancelBtn.removeAttr('href');
		this.exposeAPI = this.elWindow.expose({color:"#333",api:true,closeOnClick:false,closeOnEsc:false});

		// EVENT HANDLERS
		this.elCancelBtn.click(function() { ExitWarning.hide(); });
		this.elContinueBtn.click(function() { ExitWarning.hide(); });
		
		// Give href'less links a pointer cursor on hover
		$('a').each(function(index) {
			$(this).hover(function() {
				$('body').css({cursor:'pointer'});
			}, function() {
				$('body').css({cursor:'default'});
			});
		});
	},
	initExternalLinks:function() {
		var anchors = $('a.external');

		anchors.each(function(index) {
			$(this).attr('rel', $(this).attr('href'));
			$(this).removeAttr('href');

			$(this).click(function() {
				ExitWarning.show($(this).attr('rel'));
			});
		});
	},
	show:function(url) {
		if(typeof url != 'undefined') {
			this.setURL(url);
		}
		
		this.elWindow.fadeIn();
		this.exposeAPI.load();
	},
	hide:function() {
		this.exposeAPI.close();
		this.elWindow.fadeOut();
	},
	setURL:function(url) {
		this.url = url;
		this.elContinueBtn.attr('href', this.url);
	}
};