/**
 * @author Arnaud Métral <arnaud.metral@evonux.com>
 * @version 1.0
 * @copyright Evonux 2009
 *
 * Evonux.Wysiwyg.js
 *
 */

Evonux.Wysiwyg = {}



/**
 * Save all Wysiwyg buffers
 */
Evonux.Wysiwyg.save = function ()
{
    tinyMCE.triggerSave ();
}


/**
 * Init all wysiwyg textareas
 */
Evonux.Wysiwyg.init = function ()
{
	tinyMCE.init (
	{
	    /* Interface configuration */
	    document_base_url: U_ROOT + '/',
	    mode : "textareas",
	    editor_selector : "simple",
	    theme : "simple",
	    language : "fr",
	    content_css : U_ROOT + "/css/main.css",

	    /* Display */
	    width: "665",
	    height: "200"
	});
 
	tinyMCE.init(
	{
	    /* Interface configuration */
	    dialog_type: 'modal',
	    document_base_url: U_ROOT + '/',
	    mode : "textareas",
            editor_selector : "advanced",
            theme : "advanced",
            language : "fr",
            content_css : U_ROOT + "/css/main.css",

	    /* Display */
	    width: "665",
	    height: "400",

	    /* Cleanup */
	    cleanup_on_startup : true,
	    cleanup: true,

	    /* Plugins */
            plugins : "inlinepopups,contextmenu,save,advlink,advimage,style,layer,table,advhr,advimage,advlink,emotions,iespell,insertdatetime,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,nonbreaking,xhtmlxtras,template",
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,|,image,link,unlink,template",
            theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,unlink,anchor,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor,|,visualchars",
            theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
	    theme_advanced_blockformats : "p,div,h1,h2,h3,h4",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",		
            theme_advanced_resizing : true,
            extended_valid_elements : "iframe[src|width|height|name|align],a[name|class|href|target|title|onclick],img[id|class|src|border|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],input[type|name|value|class|size|maxlength|onclick],object[width,height],param[name,value],embed[src,type,allowfullscreen,width,height]",
		theme_advanced_styles : "Alignement gauche=img-left;Alignement droite=img-right;Cadre gauche=frame-left;Cadre droite=frame-right;Grille de photos=grid;Cellule (vide)=void;Cellule (grande)=big;Cellule (miniature)=small;Attention=warning;Puce numero on=num-on;Puce numero off=num-off;Separateur=sep",

	    /* Advanced plugins */
	    external_link_list_url : U_ROOT + "/?module=tools&action=getWebpagesList&dyn=1",
            external_image_list_url : U_ROOT + "/?module=tools&action=getFilesList&dyn=1",
            template_external_list_url : U_ROOT + "/?module=tools&action=getTemplatesList&dyn=1",

            // URLs behavior
            relative_urls: false,
            convert_urls: false,
            document_base_url : U_ROOT + "/",
            remove_script_host: true
       });	
}

/**
 * Load WYSIWYG components
 */
Evonux.Wysiwyg.load = function ()
{
    $$('textarea.wysiwyg').each (function (el)
	{
	    tinyMCE.execCommand('mceAddControl', false, el.id);
	});
}

/**
 * Unload WYSIWYG components
 */
Evonux.Wysiwyg.unload = function ()
{
    $$('textarea.wysiwyg').each (function (el)
	{
	    tinyMCE.execCommand('mceRemoveControl', false, el.id);
	});
}

