(function ($) {
	var GLOSSARY_SOURCE = '/advisers/in-the-know/glossary/';

	$(function () {
		var glossary = {};
		var container = $('#main_text, .main_text');

		if (container.size() > 0) {
			container = container.eq(0);
			if (container.parents('.no_glossary').size() == 0) {
				$.get(GLOSSARY_SOURCE, null, function (responseText, textStatus) {
					var glossarySource = $(responseText).find('#glossary');
					glossarySource.find('.definition').each(function () {
						var item = $(this);
						var title = item.find('h4');
						var def = title.nextAll();

						glossary[title.text()] = {'definition': def.text()};

						// var id = item.attr('id');
						// if (typeof(id) != 'undefined' && id != '') {
						// 	glossary[title.text()]['url'] = GLOSSARY_SOURCE + '#' + id;
						// }
					});

					container.glossary(glossary);
					$('.glossary_term').qtip({
						position: {
							target: 'mouse'
						}
					});
				});
			}
		}
	});
})(jQuery);
