// Parse DOM and find links which are tagged as external and bind popups to them
Makena.ExtLinks = {

	loc: '', // href for clicked link
	init: function() {
		// selector to find external links by rel attribute
		$('a[rel="external"]').click(function() {
			loc = $(this).attr('href'); // store the href so it can be accessed inside callback function
			$.prompt("You are now leaving the Makena&trade; site.", {
				buttons: { Ok: true, Cancel: false },
				prefix: 'cleanblue',
				promptspeed:'fast',
				callback:Makena.ExtLinks.cb // once the popup is closed by a button click, decide how to handle the event
			});
			return false;
		});
	},

	cb: function(btnVal, promptMsg, formVals) {
		// if it was confirmed that it's ok to leave the site, set the location of the browser to the stored location from the link
		if (btnVal) { location.href = loc; }
	}
};

// when the html is finished downloading and the browser has rendered the dom elements, parse the dom for external links
$(document).ready(function() {
	Makena.ExtLinks.init();
});

