// -------------------------------------------------------------------
// markItUp!
// -------------------------------------------------------------------
// Copyright (C) 2008 Jay Salvat
// http://markitup.jaysalvat.com/
// -------------------------------------------------------------------
// Textile tags example
// http://en.wikipedia.org/wiki/Textile_(markup_language)
// http://www.textism.com/
// -------------------------------------------------------------------
// Feel free to add more tags
// -------------------------------------------------------------------

   
mySettings = {
    previewParserPath:	'/articles/parse_textile', // path to your Textile parser
    //	onShiftEnter:		{keepDefault:false, replaceWith:'\n\n'},
    onShiftEnter:		{
        keepDefault:false,
        replaceWith:'<br/>'
    },
    markupSet: [
    {
        name:'Heading 2',
        key:'2',
        openWith:'h2(!(([![Class]!]))!). ',
        placeHolder:'Your title here...',
        className:'markItUpButton2'
    },

    {
        name:'Heading 3',
        key:'3',
        openWith:'h3(!(([![Class]!]))!). ',
        placeHolder:'Your title here...',
        className:'markItUpButton3'
    },

    {
        name:'Heading 4',
        key:'4',
        openWith:'h4(!(([![Class]!]))!). ',
        placeHolder:'Your title here...',
        className:'markItUpButton4'
    },

    {
        name:'Heading 5',
        key:'5',
        openWith:'h5(!(([![Class]!]))!). ',
        placeHolder:'Your title here...',
        className:'markItUpButton5'
    },

    {
        name:'Paragraph',
        key:'P',
        openWith:'p(!(([![Class]!]))!). ',
        className:'markItUpButton7'
    },

    {
        separator:'---------------'
    },

    {
        name:'Bold',
        key:'B',
        closeWith:'*',
        openWith:'*',
        className:'markItUpButton8'
    },

    {
        name:'Italic',
        key:'I',
        closeWith:'_',
        openWith:'_',
        className:'markItUpButton9'
    },

    {
        name:'Stroke through',
        key:'S',
        closeWith:'-',
        openWith:'-',
        className:'markItUpButton10'
    },

    {
        separator:'---------------'
    },

    {
        name:'Bulleted list',
        openWith:'(!(* |!|*)!)',
        className:'markItUpButton11'
    },

    {
        name:'Numeric list',
        openWith:'(!(# |!|#)!)',
        className:'markItUpButton12'
    },

    {
        separator:'---------------'
    },

    {
        name:'Picture',
        openWith:'[[image:[![Bilde nr:]!]|[![Storrelse (f.eks: "300px"), tomt for standard]!]',
        closeWith:'[![Plassering: "<" - venstre, ">" - hoyre, "=" sentrert, tomt for standard]!]]]',
        placeHolder:'|nolink|',
//        replaceWith:'![![Source:!:http://]!]([![Alternative text]!])!',
        className:'markItUpButton13'
    },

    {
        name:'Link',
        openWith:'"',
        closeWith:'([![Title]!])":[![Link:!:http://]!]',
        placeHolder:'Your text to link here...',
        className:'markItUpButton14'
    },

    {
        separator:'---------------'
    },

    {
        name:'Quotes',
        openWith:'bq(!(([![Class]!])!)). ',
        className:'markItUpButton15'
    },

    {
        name:'Code',
        openWith:'@',
        closeWith:'@',
        className:'markItUpButton16'
    },

    {
        separator:'---------------'
    },

    {
        name:'Preview',
        call:'preview',
        className:'preview'
    },

    {
        name:'Vedlegg',
        closeWith:'[[vedlegg:[![ID vedlegg:]!]]]',
        className:'vedlegg'
    },

    {
        name:'Save',
        className:'save',
        beforeInsert:function(markItUp) {
            miu.save(markItUp)
        }
    },

    {
        name:'Load',
        className:'load',
        beforeInsert:function(markItUp) {
            miu.load(markItUp)
        }
    },

    {
        name:'Colors',
        className:'palette',
        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:'#s888A85',
            className:"col9-1"
        },

        {
            name:'Gray',
            replaceWith:'#555753',
            className:"col9-2"
        },

        {
            name:'Gray',
            replaceWith:'#000000',
            className:"col9-3"
        }
        ]
    },
    {
        name:'html2textile',
        className:'html2textile',
        beforeInsert:function(markItUp) {
            html2textile.load(markItUp)
        }
    },
    ]
}

setingress = {
    previewParserPath:	'/articles/parse_textile', // path to your Textile parser
    onShiftEnter:		{
        keepDefault:false,
        replaceWith:'<br/>'
    },
    markupSet: [
    {
        name:'Bold',
        key:'B',
        closeWith:'*',
        openWith:'*',
        className:'markItUpButton8'
    },

    {
        name:'Italic',
        key:'I',
        closeWith:'_',
        openWith:'_',
        className:'markItUpButton9'
    },

    {
        name:'Stroke through',
        key:'S',
        closeWith:'-',
        openWith:'-',
        className:'markItUpButton10'
    },

    {
        separator:'---------------'
    },


    {
        name:'Forside Bilde',
        closeWith:'[[bilde-st:[![Bilde staaende nr:]!]]] [[bilde-li:[![Bilde liggende nr:]!]]]',
        className:'bilde'
    },

    {
        name:'Vedlegg',
        closeWith:'[[vedlegg:[![ID vedlegg:]!]]]',
        className:'vedlegg'
    },

    //		{name:'Link', openWith:'"', closeWith:'([![Title]!])":[![Link:!:http://]!]', placeHolder:'Your text to link here...' },

    {
        separator:'---------------'
    },

    {
        name:'Sitat',
        openWith:'bq(!(([![Class]!])!)). ',
        className:'markItUpButton15'
    },

    {
        name:'Kode',
        openWith:'@',
        closeWith:'@',
        className:'markItUpButton16'
    },

    {
        separator:'---------------'
    },

    {
        name:'Preview',
        call:'preview',
        className:'preview'
    }
    ]
}


// html2textile

html2textile = {
    load: function(markItUp) {
        data = markItUp.textarea.value;
        data = data.replace(/&/g,'_ogtegn_')
        ok = confirm("Konverter tekst fra html til textile (redcloth)?");
        if (!ok) {
            return false;
        }
        J.post("/articles/html2textile", "data="+data, function(response) {
            if(response === "FEIL") {
                alert("Feil oppstod! Teksten innholder antagelig tegn som ikke kunne konverteres");
            //                return false;
            }
            else {
                alert("Konvertert!");
                markItUp.textarea.value = response.replace(/_ogtegn_/g,'&');
            }
        }
        );
    }
}


// mIu nameSpace to avoid conflict.
miu = {
    save: function(markItUp) {
        data = markItUp.textarea.value;
        data = data.replace(/&/g,'_ogtegn_')
        ok = confirm("Save the content?");
        if (!ok) {
            return false;
        }
        J.post("/javascripts/markitup/utils/quicksave/save.php", "data="+data, function(response) {
            if(response === "MIU:OK") {
                alert("Saved!");
            }
        }
        );
    },
	
    load: function(markItUp) {
        //        J.get(markItUp.root+"utils/quicksave/load.php", function(response) {
        J.get("/javascripts/markitup/utils/quicksave/load.php", function(response) {
            if(response === "MIU:EMPTY") {
                alert("Nothing to load");
            } else {
                ok = confirm("Load the previously saved content?");
                if (!ok) {
                    return false;
                }
                markItUp.textarea.value = response.replace(/_ogtegn_/g,'&');
                alert("Loaded!");
            }
        }
        );
    }      
}
