var xinha_plugins =
[
	//'CharacterMap',
	'ContextMenu',
	'FullScreen',
	//'ListType',
	//'SpellChecker',
	//'Stylist',
	//'SuperClean',
	'TableOperations'
];


var xinha_editors = [];

function xinha_init()
{
	var ids = new Array();

	var textareaCollection = document.getElementsByTagName("textarea");

	for(var i = 0; i < textareaCollection.length; i++)
	{
		if(textareaCollection.item(i).className.match(/^xinha\-/))
		{
			if(textareaCollection.item(i).id.length == 0)
			{
				textareaCollection.item(i).id = textareaCollection.item(i).name;
			}

			ids.push(textareaCollection.item(i).id);
		}
	}

	if(ids.length < 1)
	{
		return;
	}

	xinha_editors = eval("['" + ids.join("','") + "']");

	if(!HTMLArea.loadPlugins(xinha_plugins, xinha_init)) return;

	var xinha_config = new HTMLArea.Config();

	xinha_editors = HTMLArea.makeEditors(xinha_editors, xinha_config, xinha_plugins);

	for(var i in xinha_editors)
	{
		xinha_editors[i].config.width = '600px';
		xinha_editors[i].config.flowToolbars = true;
		xinha_editors[i].config.height = '300px';

		xinha_editors[i].config.toolbar =
		[
			["popupeditor"],
			["separator","formatblock","fontname","fontsize","bold","italic","underline","strikethrough"],
			["separator","forecolor","hilitecolor","textindicator"],
			["separator","subscript","superscript"],
			["separator","justifyleft","justifycenter","justifyright","justifyfull"],
			["separator","insertorderedlist","insertunorderedlist","outdent","indent"],
			["separator","inserthorizontalrule","createlink","insertimage","inserttable"],
			["separator","undo","redo"/* @myfw-changes: ,"selectall","print"*/], 
			/* @myfw-changes: (HTMLArea.is_gecko ? [] : ["cut","copy","paste","overwrite","saveas"]),*/
			["separator","killword","clearfonts","removeformat","toggleborders"/* @myfw-changes: ,"splitblock", "lefttoright", "righttoleft"*/],
			["separator","htmlmode"/* @myfw-changes: ,"showhelp","about"*/]
		];

	}

	HTMLArea.startEditors(xinha_editors);
}

addOnLoadHandler(xinha_init);


/*
var _editor_url;
var _editor_lang;
var _editor_skin;

var ___xinhaAlreadyInitialized = false;

function xinhaConfigure(url, language, skin)
{
	_editor_url = url;
	_editor_lang = language;
	_editor_skin = skin;
}

function xinhaLoad()
{
	if(___xinhaAlreadyInitialized)
	{
		return false;
	}

	HTMLArea.loadPlugin("TableOperations");
	HTMLArea.loadPlugin("FullScreen");
	HTMLArea.loadPlugin("ContextMenu");

	var loader = function()
	{
		var textareaCollection = document.getElementsByTagName("textarea");

		for(var i = 0; i < textareaCollection.length; i++)
		{
			if(textareaCollection.item(i).className.match(/^xinha\-/))
			{
				if(textareaCollection.item(i).id.length == 0)
				{
					textareaCollection.item(i).id = textareaCollection.item(i).name;
				}

				var editor = new HTMLArea(document.getElementById(textareaCollection.item(i).id));
				editor.registerPlugin(FullScreen);
				editor.registerPlugin(ContextMenu);
				editor.registerPlugin(TableOperations);

				editor.generate();
				editor.config.width  = '500px';
				editor.config.height = '400px';
			}
		}
	}
	addOnLoadHandler(loader);

	___xinhaAlreadyInitialized = true;
}
*/
