// ----------------------------------------------------------------------------
// markItUp!
// ----------------------------------------------------------------------------
// Copyright (C) 2008 Jay Salvat
// http://markitup.jaysalvat.com/
// ----------------------------------------------------------------------------
myBbcodeSettings = {
  nameSpace:          "bbcode", // Useful to prevent multi-instances CSS conflict
	previewParserPath:  "~/bbcode_preview.php",
	previewInWindow:		"width=620, height=700, resizable=yes, scrollbars=yes",
	onEnter:						{keepDefault:false, replaceWith:'<br />\n'},
  markupSet: [
      {name:'Paryškinimas', key:'B', openWith:'[b]', closeWith:'[/b]'}, 
      {name:'Pavertimas', key:'I', openWith:'[i]', closeWith:'[/i]'}, 
      {name:'Pabraukimas', key:'U', openWith:'[u]', closeWith:'[/u]'}, 
      {separator:'---------------' },
      {name:'Nuotrauka', key:'P', replaceWith:'[img][![Url]!][/img]'}, 
      {name:'Nuoroda', key:'L', openWith:'[url=[![Url]!]]', closeWith:'[/url]', placeHolder:'Your text to link here...'},
      {separator:'---------------' },
      {name:'Spalva', openWith:'[color=[![Color]!]]', closeWith:'[/color]', dropMenu: [
          {name:'Geltona', openWith:'[color=yellow]', closeWith:'[/color]', className:"col1-1" },
          {name:'Oranžinė', openWith:'[color=orange]', closeWith:'[/color]', className:"col1-2" },
          {name:'Raudona', openWith:'[color=red]', closeWith:'[/color]', className:"col1-3" },
          {name:'Mėlyna', openWith:'[color=blue]', closeWith:'[/color]', className:"col2-1" },
          {name:'Rožinė', openWith:'[color=purple]', closeWith:'[/color]', className:"col2-2" },
          {name:'Žalia', openWith:'[color=green]', closeWith:'[/color]', className:"col2-3" },
          {name:'Balta', openWith:'[color=white]', closeWith:'[/color]', className:"col3-1" },
          {name:'Pilka', openWith:'[color=gray]', closeWith:'[/color]', className:"col3-2" },
          {name:'Juoda', openWith:'[color=black]', closeWith:'[/color]', className:"col3-3" }
      ]},
      {name:'Dydis', key:'S', openWith:'[size=[![Text size]!]]', closeWith:'[/size]', dropMenu :[
          {name:'Didelis', openWith:'[size=150]', closeWith:'[/size]' },
          {name:'Vidutinis', openWith:'[size=100]', closeWith:'[/size]' },
          {name:'Mažas', openWith:'[size=80]', closeWith:'[/size]' }
      ]},
      {separator:'---------------' },
      {name:'Išskirti sąrašą', openWith:'[list]\n', closeWith:'\n[/list]'}, 
      {name:'Numeruoti sąrašą', openWith:'[list=[![Starting number]!]]\n', closeWith:'\n[/list]'}, 
      {name:'Žymėti sąrašą', openWith:'[*] '}, 
      {separator:'---------------' },
      {name:'Kabutės', openWith:'[quote]', closeWith:'[/quote]'}, 
      {name:'Kodas', openWith:'[code]', closeWith:'[/code]'}, 
      {separator:'---------------' },
      {name:'Išvalyti', className:"clean", replaceWith:function(h) { return h.selection.replace(/\[(.*?)\]/g, "") } },
      {name:'Peržiūra', className:"preview", call:'preview' },
			{name:'Laikinai išsaugoti', className:'save', beforeInsert:function(markItUp) { miu.save(markItUp) } },
      {name:'Atstatyti išsaugotą', className:'load', beforeInsert:function(markItUp) { miu.load(markItUp) } }
   ]
}

// mIu nameSpace to avoid conflict.
miu = {
    save: function(markItUp) {
        data = markItUp.textarea.value;
        ok = confirm("Išsaugoti turinį?");
        if (!ok) {
            return false;
        }
        $.post(markItUp.root+"sets/bbcode/utils/quicksave/save.php", "data="+data, function(response) {
                if(response === "MIU:OK") {
                    alert("Išsaugota!");
                }
            }
        );
    },
	
    load: function(markItUp) {
        $.get(markItUp.root+"sets/bbcode/utils/quicksave/load.php", function(response) {
                if(response === "MIU:EMPTY") {
                    alert("Nėra išsaugoto turinio");
                } else {
                    ok = confirm("Atstatyti išsaugotą turinį?");
                    if (!ok) {
                        return false;
                    }
                    markItUp.textarea.value = response;
                    alert("Atstatyta!");
                }
            }
        );
    }      
}

