default_tiny = function( sId )
{
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		editor_selector : sId,
		button_tile_map : true,
		plugins : 'inlinepopups, fullscreen, paste,table',
		theme_advanced_buttons1 : "mybutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist",
		theme_advanced_buttons2 : "undo,redo,link,unlink,separator,pastetext,pasteword,selectall,separator,fullscreen,tablecontrols",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		paste_auto_cleanup_on_paste : true,
		cleanup_on_startup : true,
		theme_advanced_font_sizes : "10px=10px,12px=12px,14px=14px,16px=16px,18px=18px,20px=20px,24px=24px,36px=36px,48px=48px",

		setup : function(ed)
				{
					ed.setProgressState(1);
		
					ed.onSetContent.add(function(ed, cm) {
						ed.save();
					});
					
					ed.onChange.add(function(ed)
					{
						ed.save();
					});
					
					ed.onPostRender.add( 
							
						function(ed)
						{
							ed.setProgressState(0);
							
							ed.onPostRender.add(fitEditor);
						}
						
					);
				}
	});
};

fitEditor = function(ed)
{
	// fix up the height & width
	$( '#' + ed.id + '_tbl' ).width('100%');
	
	//console.log( parseInt($( '#' + ed.id + '_tbl' ).css('height').replace(/px/,'')));
	
	//console.log( parseInt($( '#' + ed.id + '_tbl tr.mceFirst td.mceToolbar' ).height()));
	
	var oParent    = $('#' + ed.id ).parent(0);
	var oIfrParent = $('#' + ed.id + '_ifr' ).parent(0);
	// fix up the height & width
	$( '#' + ed.id + '_tbl' ).width('100%');
	
	var iDiff = 0; 
	
	if ( undefined != oIfrParent.css('borderTopWidth') )
	{
		iDiff += parseInt(oIfrParent.css('borderTopWidth').replace(/px/,''));
	}

	if ( undefined != oIfrParent.css('borderBottomWidth') )
	{
		iDiff += parseInt(oIfrParent.css('borderBottomWidth').replace(/px/,''));
	}
	
	var iTableHeight = oParent.height() - iDiff;
	
	var iIfrHeight = iTableHeight - $( '#' + ed.id + '_tbl tr.mceFirst td.mceToolbar' ).outerHeight();
	
	$( '#' + ed.id + '_ifr' ).height( iIfrHeight );

};

readonly_tiny = function( sId )
{
	tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        editor_selector : sId,
        readonly : true,
		setup : function(ed)
		{
			ed.setProgressState(1);
			
			ed.onPostRender.add( 
					
				function(ed)
				{
					ed.setProgressState(0);
					
					ed.onPostRender.add(fitEditor);
				}
			);
		}        
	});
};

tiny_preloading = function(ed)
{
	var oParent = $($('#' + ed.id ).attr('parentNode'));
	
	iHeight = oParent.height();
	iWidth 	= oParent.width();
	sLeft 	= oParent.css('left');
	
	$('#' + ed.id ).before('<div class="loadinfo" style="display:block;text-align:center;position:absolute;background-color:#FFFFFF;z-index:5;width:100%;px;height:' + iHeight + 'px;line-height:' + iHeight + 'px;left:'+sLeft+';dispay:none" id="' + ed.id + '_loading"></div>');

	/*$('#' + ed.id + '_loading').fadeIn(0, function()
		{
			$(this).delay(1000).fadeOut(
					2000, function(){ $(this).remove();}
			);
		}
	);*/
};

tiny_postloading = function(ed)
{
	$('#' + ed.id + '_loading').delay(2000).show(1000,function()
			{ 
				fitEditor(ed);
				$(this).fadeOut(1000, function(){ $(this).remove();});
			});
};
