function xtext_tooltip_process(parent){
	($type(parent) == 'element' || $type(parent) == 'document'
		? parent.getElements
		: $$
	)('.xtext-tooltip').each(function(tooltip){
		if(tooltip.hasClass('xtext-tooltip-ready')){
			return;
		}
		var ss = tooltip.get('title').split(/\s*::\s*/);
		if(ss.length > 1){
			tooltip.store('tip:title', ss.shift());
		}
		tooltip.store('tip:text', ss.join('<br>'));
		new Tips(tooltip, {
			fixed: true,
			hideDelay: 50,
			showDelay: 50
		});
		tooltip.addClass('xtext-tooltip-ready');
	});
}

function xtext_tooltip_insert(textarea){
	var title = $('xtext_tooltip_title').get('value');
	var text = $('xtext_tooltip_text').get('value').replace(/\r?\n/g, " :: ");
	lsPanel.putTagAround(
		textarea
		,'tooltip'
		+(title === '' ? '' : ' title="'+title.h2c()+'"')
		+' text="'+text.h2c()+'"'
		,'tooltip'
	);
	xtext_close_popup('tooltip');
}

function xtext_tooltip_init(panel_rules){
	xtext_add_panel_button(
		panel_rules,
		'xtext_open_popup("tooltip")',
		'tag/tooltip/tooltip-panel-icon.png',
		xtext_lang_get('xtext_tooltip_panel_title'),
		'tooltip'
	);
}

