// ----------------------------------------------------------------------------
// markItUp!
// ----------------------------------------------------------------------------
// Copyright (C) 2008 Jay Salvat
// http://markitup.jaysalvat.com/
// ----------------------------------------------------------------------------
// Html tags
// http://en.wikipedia.org/wiki/html
// ----------------------------------------------------------------------------
// Basic set. Feel free to add more tags
// ----------------------------------------------------------------------------
mySettings = {	
	onShiftEnter:  	{keepDefault:false, replaceWith:'<br />\n'},
	onCtrlEnter:  	{keepDefault:false, openWith:'\n<p>', closeWith:'</p>'},
	onTab:    		{keepDefault:false, replaceWith:'    '},
	previewAutoRefresh: true,
	markupSet:  [ 	
    {name:'Paragraphe', openWith:'<p(!( class="[![Class]!]")!)>', closeWith:'</p>'  },
    {name:'Titre 3', key:'3', openWith:'<h3(!( class="[![Class]!]")!)>', closeWith:'</h3>', placeHolder:'Votre titre...' },
    {name:'Titre 4', key:'4', openWith:'<h4(!( class="[![Class]!]")!)>', closeWith:'</h4>', placeHolder:'Votre titre...' },
    {name:'Titre 5', key:'5', openWith:'<h5(!( class="[![Class]!]")!)>', closeWith:'</h5>', placeHolder:'Votre titre...' },
    {name:'Titre 6', key:'6', openWith:'<h6(!( class="[![Class]!]")!)>', closeWith:'</h6>', placeHolder:'Votre titre...' },
    {separator:'---------------' },
		{name:'Gras', key:'B', openWith:'(!(<strong>|!|<b>)!)', closeWith:'(!(</strong>|!|</b>)!)' },
		{name:'Italique', key:'I', openWith:'(!(<em>|!|<i>)!)', closeWith:'(!(</em>|!|</i>)!)'  },
		{name:'Effacer la mise en forme', className:'clean', replaceWith:function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") } },
		{separator:'---------------' },
    {name:'Ul', openWith:'<ul>\n', closeWith:'</ul>\n' },
    {name:'Ol', openWith:'<ol>\n', closeWith:'</ol>\n' },
    {name:'Li', openWith:'<li>', closeWith:'</li>' },
		{separator:'---------------' },
		{name:'URL Image', replaceWith:'<img src="[![Source:!:http://]!]" alt="[![Texte alternatif]!]" />' },
    {name:'Galerie', 
         className:'pictures', 
         beforeInsert:function() { 
                $('<iframe src="/img/library/"></iframe>').modal();
            } 
        },
		{name:'Lien', openWith:'<a href="[![Lien:!:http://]!]"(!( title="[![Titre]!]")!)>', closeWith:'</a>', placeHolder:'Texte du lien' },
    {name:'Couleurs', className:'colors', dropMenu: [
            {name:'Yellow',  replaceWith:'#FCE94F',     className:"col1-1" },
            {name:'Yellow',  replaceWith:'#EDD400',     className:"col1-2" },
            {name:'Yellow',  replaceWith:'#C4A000',     className:"col1-3" },
            {name:'Orange',  replaceWith:'#FCAF3E',     className:"col2-1" },
            {name:'Orange',  replaceWith:'#F57900',     className:"col2-2" },
            {name:'Orange',  replaceWith:'#CE5C00',     className:"col2-3" },
            {name:'Brown',   replaceWith:'#E9B96E',     className:"col3-1" },
            {name:'Brown',   replaceWith:'#C17D11',     className:"col3-2" },
            {name:'Brown',   replaceWith:'#8F5902',     className:"col3-3" },
            {name:'Green',   replaceWith:'#8AE234',     className:"col4-1" },
            {name:'Green',   replaceWith:'#73D216',     className:"col4-2" },
            {name:'Green',   replaceWith:'#4E9A06',     className:"col4-3" },
            {name:'Blue',    replaceWith:'#729FCF',     className:"col5-1" },
            {name:'Blue',    replaceWith:'#3465A4',     className:"col5-2" },
            {name:'Blue',    replaceWith:'#204A87',     className:"col5-3" },
            {name:'Purple',  replaceWith:'#AD7FA8',     className:"col6-1" },
            {name:'Purple',  replaceWith:'#75507B',     className:"col6-2" },
            {name:'Purple',  replaceWith:'#5C3566',     className:"col6-3" },
            {name:'Red',     replaceWith:'#EF2929',     className:"col7-1" },
            {name:'Red',     replaceWith:'#CC0000',     className:"col7-2" },
            {name:'Red',     replaceWith:'#A40000',     className:"col7-3" },
            {name:'Gray',    replaceWith:'#FFFFFF',     className:"col8-1" },
            {name:'Gray',    replaceWith:'#D3D7CF',     className:"col8-2" },
            {name:'Gray',    replaceWith:'#BABDB6',     className:"col8-3" },
            {name:'Gray',    replaceWith:'#888A85',     className:"col9-1" },
            {name:'Gray',    replaceWith:'#555753',     className:"col9-2" },
            {name:'Gray',    replaceWith:'#000000',     className:"col9-3" }
            ]
    },
		{separator:'---------------' },
    {name:'Encoder Html Special Chars',
         className:"encodechars", 
         replaceWith:function(markItUp) { 
            c = document.createElement('div');
            c.appendChild(document.createTextNode(markItUp.selection));
            return c.innerHTML; 
         }
        },
    {name:'Html Tidy Repair', className:'htmlTidyRepair', replaceWith:function(markItUp) { return miu.tidyRepair(markItUp) } },
		{name:'Aperçu', className:'preview',  call:'preview'}
	]
}


// mIu nameSpace to avoid conflict.
miu = {
    tidyRepair: function(markItUp) {
        var tidy;
        if (markItUp.selection !== "") {
            $.ajax({
                async:   false,
                type:    "POST",
                url:     markItUp.root+"utils/htmltidy/repair.php",
                data:    "selection="+encodeURIComponent(markItUp.selection),
                success:function(content) {
                    tidy = content;    
                }
            });
        } else {
            $.ajax({
                async:   true,
                type:    "POST",
                url:     markItUp.root+"utils/htmltidy/repair.php",
                data:    "data="+encodeURIComponent(markItUp.textarea.value),
                success:function(content) {
                    tidy = content;    
                    markItUp.textarea.value = tidy;
                }
            });
        }    
        return tidy;
    },
    
    tidyReport: function(markItUp) {
        $.ajax({
            async:    false,
            type:     "POST",
            url:      markItUp.root+"utils/htmltidy/report.php",
            data:     "data="+encodeURIComponent(markItUp.textarea.value),
            success:function(content) {
                win = window.open("", "htmlTidyReport","width=600, height=400, resizable=yes, scrollbars=yes");
                win.document.open();
                win.document.write(content);
                win.document.close();
                win.focus();
            }
        });
    }
}

