jQuery(document).ready(function($) {
	jQuery(document).click(function(){
		jQuery('.qtip.ui-tooltip').qtip('hide');
	});

	createTooltips();
});

function createTooltips() {
	jQuery('*[title]').qtip({
		style: { classes: 'ui-tooltip-light ui-tooltip-shadow ui-tooltip-rounded' },
		
		position: { at: 'bottom center', effect: false, viewport: jQuery(window) },
		
		show: { solo: true },
		hide: {
			delay: 500,
			fixed: true
		},
		
		content: {      
			text: function(api) {         
				var title = jQuery(this).attr('title');

				if(title.match(/^#\w/gi) != null) {
					return $(title).html();
				}
				else if(title.match(/^(http:\/\/|\/)/gi) != null) {
					return jQuery.ajax({ url: title, async: false }).responseText;
				} else {
					return title;
				}
			}
		}
   });
}
