class syntaxhighlighter {
	static save($textarea)
	{
		var editor_textarea = document.getElementById($textarea.attr('id')),
			editor_div = editor_textarea !== null ? editor_textarea.nextSibling : '';

		if (editor_div != '' && $(editor_div).hasClass('ace_editor'))
		{
			var editor = ace.edit(editor_div),
				code = editor.getSession().getValue();

			$textarea.val(code);
		}
	}

	static saveAll(settings)
	{
		jQuery("#" + settings.windowId + " .ace_editor").each(function(){
			var editor = ace.edit(this),
				code = editor.getSession().getValue();

			$(this).prev('textarea').val(code);
		});
	}

	static loadAutosave($textarea)
	{
		var editor_textarea = document.getElementById($textarea.attr('id')),
			editor_div = editor_textarea !== null ? editor_textarea.nextSibling : '';

		if (editor_div != '' && $(editor_div).hasClass('ace_editor'))
		{
			var editor = ace.edit(editor_div);
			editor.getSession().setValue($textarea.text());
		}
	}

	static remove($parent)
	{
		$parent.find('.ace_editor').remove();
	}

	static addCompleter(sqlTables)
	{
		var langTools = ace.require('ace/ext/language_tools');

		// create a completer object with a required callback function:
		var sqlTablesCompleter = {
			getCompletions: function(editor, session, pos, prefix, callback) {
				callback(null, sqlTables.map(function(table) {
					return {
						value: table,
						meta: 'Table'
					};
				}));
			}
		};
		// bind to langTools
		langTools.addCompleter(sqlTablesCompleter);
	}
}