/* Plugin för att visa innehåll i en tinymce editor.
   Ange vilket formulär det ska postas till, alla data i querystring kommer att postas till sparafunktionen.
  */
  

(function ($) {
  $.fn.tinyMceDialog2 = function(settings) {
    return this.each(function() {
      $(this).click(function() {

         //Init values
         var $Editordialog = $('div id="TinyEditor"></div>');
         
         var windowTitle = $(this).attr('title');
         var url = $(this).attr('href');
         //var tinyMceInitString = {};
         
         //Set default values and extend settings if user has supplied settings.
         $.extend({
               dialogHeight : 1200,
               dialogWidth : 500,
               editorType : 'Large'
            }, settings);


         //Tinymce init
         if (settings.editorType == 'Large') {
            var tinyMceInit = {
                  // Location of TinyMCE script
                  script_url : "jscripts/tiny_mce/tiny_mce.js",
                  language: "sv",
                  mode: "textareas",
                  skin: "cirkuit",
                  theme: "advanced",
                  plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,autosave,imagemanager",

                  // Theme options
                  theme_advanced_buttons1: "save,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,formatselect,forecolor,styleselect",
                  theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,search,replace,undo,redo,link,unlink,image,insertimage,code,fullscreen,print,fontsizeselect",
                  theme_advanced_buttons3: "tablecontrols,hr,removeformat,charmap,media",
                  theme_advanced_toolbar_location: "top",
                  theme_advanced_toolbar_align: "left",
                  theme_advanced_statusbar_location: "bottom",
                  theme_advanced_resizing: false,
                  theme_advanced_styles: "Brun ruta=box, Blå ruta=boxBlue",
                  theme_advanced_blockformats: "H1=h1, H2=h2, H3=h3, H4=h4, H5=h5",
                  external_link_list_url: "jscripts/link_list.js",

                  height: settings.dialogHeight,
                  width: settings.dialogWidth,

                  content_css: "/kunder/ulvohotell/includes/css/style.css",
                  theme_advanced_font_sizes: "10px,11px,12px,13px,14px,16px,18px,20px"
               };
         } 
         if (settings.editorType == 'Small') {
            var tinyMceInit = {
               language: "sv",
               mode: "textareas",
               skin: "cirkuit",
               theme: "advanced",
               plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,autosave,imagemanager",

               // Theme options
               theme_advanced_buttons1: "bold,italic,underline,strikethrough,insertimage,code,link,unlink",
               theme_advanced_buttons2: "",
               theme_advanced_buttons3: "",
               theme_advanced_toolbar_location: "top",
               theme_advanced_toolbar_align: "left",
               theme_advanced_statusbar_location: "bottom",
               theme_advanced_resizing: false,

               height: settings.dialogHeight,
               width: settings.dialogWidth,

               content_css: "http://www.agrenshuset.se/kunder/ulvohotell/includes/css/style.css"
            };
         }
         
         $Editordialog.dialog({
            bgiframe:true,
            modal:true,
            autoOpen:false,
            open:function(event, id) {
                tinyMCE.init(tinyMceInit);
            },
            close:function(event, id) {
                //tinyMCE.triggerSave();
                var i, t = tinyMCE.editors;
                for (i in t){
                    if (t.hasOwnProperty(i)){
                        t[i].remove();
                    }
                }
            }
         });
         
         $('body').append($Editordialog);
         
         $Editordialog.load(url);
         
         $Editordialog.dialog('open');

         return false;
      });
      
    });
  };
})(jQuery);
