
tinyMCE.init({
	mode: 'none',
	/* #9731 - added width back in to stop issue where hidden editors where only appearing 100px wide */
	width: '98%',
	theme : 'advanced',
	plugins : 'simplepaste',
	paste_as_plain_text: false,
	
	entity_encoding : 'raw',
	theme_advanced_buttons1 : 'bold,italic,underline,separator,bullist,numlist,separator,outdent,indent,separator,undo,redo',
	theme_advanced_buttons2 : '',
	theme_advanced_buttons3 : '',
	
	theme_advanced_toolbar_location : 'top',
	theme_advanced_statusbar_location: 'bottom',
	theme_advanced_path : false,
	theme_advanced_resizing : true,
	//This doesnt seem to work and needs to be looked at (their API)
	theme_advanced_resizing_min_height : 40,
	theme_advanced_resize_horizontal : false,

	onchange_callback: 'LHS.MCE.myCustomOnChangeHandler',
	init_instance_callback: 'LHS.MCE.myCustomInitInstance'
});

LHS.MCE = {
	myCustomOnChangeHandler: function(inst) {
		inst.getElement().value = inst.getContent();
	},
	// Taken from http://tinymce.moxiecode.com/forum/viewtopic.php?id=10548
	// This will allow us to specify focus/blur events properly
	myCustomInitInstance: function( editor )
	{
		tinymce.dom.Event.add( editor.getWin(), 'blur', function( e )
		{
			LHS.MCE.myCustomOnChangeHandler( editor );
		} );
	},
	loadTinyMCE: function (element) {
		// Check if the editor has already been loaded
		if (! tinymce.EditorManager.editors[element.id]) {
			tinyMCE.execCommand('mceAddControl', true, element.id);
			var fireOnThis = $(element.id+'_bold');
			if (fireOnThis && fireOnThis.up('.popupContainer')) {
				if( document.createEventObject ) {
				  fireOnThis.fireEvent('onclick');
				  fireOnThis.fireEvent('onclick');
				}
			}	
		}
	}
};
/**
 * Rather than using tinyMCE's loader i have used our own.
 * This means that the loading will work with textareas inserted from AJAX calls
 */
LHS.Loader.addLoadMethod('textarea[id].formatted', function (element) {
		// Don't load editors in the portal.
		// They will be loaded on show of the page. see MultiPageForm.js
		if (typeof LHSPortal === 'undefined' || !element.up('.formPage')) {
			LHS.MCE.loadTinyMCE(element);
		}
});
