(function( $ ){
// ***

// ========================
// jstrNavigator CLASS
// ========================
function jstrNavigator(id){
   // class properties
   this.id = id;
   this.stack = new Array();

   // class methods
   this.push = function(obj) {this.stack.push(obj);};
   this.pop = function(obj) {this.stack.pop();};
   this.expand = function() {
      var navigator = '';
      for(var i=0; i<this.stack.length; i++) {
         var value = this.stack[i];
         var position = this.stack.length - i - 1;
         var link;
         if(position>0) {
            help_attr = value.help==undefined ? '':' jstr-help="'+value.help+'"';
            link = '<a jstr-href="'+value.link+'"'+help_attr+' pop="'+position+'" class="navigator">'+value.label+'</a>';
         } 
         else 
            link = '<span class="navigator">'+value.label+'</span>';
	    navigator += (i>0?' > ':'')+link;
      };
      $('#'+this.id+' div.index').html(navigator);
   };
}

// ========================
// jSiter OBJECT
// ========================
jQuery.jSiter = {

// =========================================================
// TYPES handling
// =========================================================
   isString: function(obj) { return typeof(obj) == 'string'; },
   isNumber: function(obj) { return typeof(obj) == 'number'; },
   isBoolean: function(obj) { return typeof(obj) == 'boolean'; },
   isFunction: function(obj) { return typeof(obj) == 'function'; },
   isObject: function(obj) { return typeof(obj) == 'object' || this.isFunction(obj); },

   isArray: function(obj) { return this.isObject(obj) && obj instanceof Array; },
   isDate: function(obj) { return this.isObject(obj) && obj instanceof Date; },
   isError: function(obj) { return this.isObject(obj) && obj instanceof Error; },

   isUndefined: function(obj) { return typeof(obj) == 'undefined'; },
   isNull: function(obj) { return obj === null; },
   isNone: function(obj) { return this.isUndefined(obj) || this.isNull(obj); },
   isSet: function(obj) { return !this.isNone(obj); },

   isTrue: function(obj) { return this.isSet(obj) && !!obj; },
   isFalse: function(obj) { return this.isSet(obj) && !obj; },

// =========================================================
// URL handling
// =========================================================
   getBaseURL: function(){
      return $('base').attr('href');
   },
   
   getURL: function(rurl){
      if(rurl.length>0 && rurl.charAt(0)=='/')
         rurl = rurl.substr(1);
   
      return this.getBaseURL()+rurl;
   },

// =========================================================
// ATTRIBUTES handling
// =========================================================
   
   // ......................
   // setAttribute FUNCTIONs
   // ======================
   setAttribute:
       function(ascope, aname, avalue){
          if(avalue==undefined)
             if(typeof(aname)=='object')
                 return this.setAttributeInSpace(ascope, '', 'jstr:json', jQuery.toJSON(aname));
             else return false;
          else
               return this.setAttributeInSpace(ascope, '', aname, avalue);
       },

   setAttributeInSpace:
       function(ascope, aspace, aname, avalue){
          if(avalue==undefined)
             if(typeof(aname)=='object')
                return this.setAttributeInSpace(ascope, '', 'jstr:json', jQuery.toJSON(aname));
             else return false;
          
          $.ajax({
            type: "POST",
            url: $.jSiter.getURL("core.setAttribute.api"),
            async: false,
            data: {scope:ascope, space:aspace, name:aname, value:avalue},
            dataType: 'json',
            success: function(jsondata){
               if(jsondata.execution == "success"){
                       return true;
               }
               else {
                  return false;
               }
            }
          });
      },
      
   // Request   
   setRequestAttribute:
      function(aname, avalue){
         return this.setRequestAttributeInSpace('', aname, avalue);
      },

   setRequestAttributeInSpace:
      function(aspace, aname, avalue){
         return this.setAttributeInSpace("request", aspace, aname, avalue);
      },
    
   // Session   
   setSessionAttribute:
         function(aname, avalue){
            return this.setSessionAttributeInSpace('', aname, avalue);
         },
      
   setSessionAttributeInSpace: 
      function(aspace, aname, avalue){
         return this.setAttributeInSpace("session", aspace, aname, avalue);
      },

   // User
   setUserAttribute:
      function(aname, avalue){
         return this.setUserAttributeInSpace('', aname, avalue);
      }, 
      
   setUserAttributeInSpace: 
      function(aspace, aname, avalue){
         return this.setAttributeInSpace("user", aspace, aname, avalue);
      },

   // Application
   setApplicationAttribute:
      function(aname, avalue){
         return this.setApplicationAttributeInSpace('', aname, avalue);
      }, 
      
   setApplicationAttributeInSpace: 
      function(aspace, aname, avalue){
         return this.setAttributeInSpace("application", aspace, aname, avalue);
      },

   // .........................
   // removeAttribute FUNCTIONs
   // =========================
   removeAttribute:
       function(ascope, aname){
           return this.removeAttributeInSpace(ascope, '', aname);
      },

   removeAttributeInSpace:
      function(ascope, aspace, aname){
         $.ajax({
            type: "POST",
            url: $.jSiter.getURL("core.removeAttribute.api"),
            async: false,
            data: {scope:ascope, space:aspace, name:aname},
            success: function(jsondata){
               data = jQuery.parseJSON(jsondata);
               if(data.execution == "success"){
                  return true;
               }
               else {
                  return false;
               }
            }
         });
      },

   removeSpace:
      function(ascope, aspace){ 
         $.ajax({
            type: "POST",
            url: $.jSiter.getURL("core.removeSpace.api"),
            async: false,
            data: {scope:ascope, space:aspace},
            success: function(jsondata){
               data = jQuery.parseJSON(jsondata);
               if(data.execution == "success"){
                  return true;
               }
               else {
                  return false;
               }
            }
         });
      },

   // Request   
   removeRequestAttribute:
      function(aname){
          return this.removeRequestAttributeInSpace('', aname);
       },

   removeRequestAttributeInSpace:
      function(aspace, aname){
          return this.removeAttribute("request", aspace, aname);
       },   

   // Session   
   removeSessionAttribute:
      function(aname){
          return this.removeSessionAttributeInSpace('', aname);
       },

   removeSessionAttributeInSpace:
      function(aspace, aname){
          return this.removeAttribute("session", aspace, aname);
       },      
   
   // User   
   removeUserAttribute:
      function(aname){
          return this.removeUserAttributeInSpace('', aname);
       },

   removeUserAttributeInSpace:
      function(aspace, aname){
          return this.removeAttribute("user", aspace, aname);
       },   

   // Application   
   removeApplicationAttribute:
      function(aname){
         return this.removeApplicationAttributeInSpace('', aname);
      },

   removeApplicationAttributeInSpace:
      function(aspace, aname){
         return this.removeAttribute("application", aspace, aname);
      },  

   // ......................
   // getAttribute FUNCTIONs
   // ======================
   getAttribute: 
      function(ascope, aname, adef){
          if(adef==undefined)
             return this.getAttributeInSpace(ascope, '', aname);
          else
             return this.getAttributeInSpace(ascope, '', aname, adef);
       },

   getAttributeInSpace: 
       function(ascope, aspace, aname, adef){
          
          if(adef==undefined)
             pars = {scope:ascope, space:aspace, name:aname};
          else
             pars = {scope:ascope, space:aspace, name:aname, defvalue:adef};
          
          var ret_value = "undefined";
          $.ajax({
            type: "POST",
            url: $.jSiter.getURL("core.getAttribute.api"),
            async: false,
            data: pars,
            dataType: 'json',
            success: function(jsondata){
               if(jsondata.execution == "success"){
                      ret_value = jsondata.value;
               }
            }
          });
          return ret_value;
      },   

   getAttributesInSpace:
      function(ascope, aspace){
         var ret_values = "undefined";
         $.ajax({
           type: "POST",
           url: $.jSiter.getURL("core.getAttributes.api"),
           async: false,
           data:{ scope:ascope, space:aspace },
           dataType: 'json',
           success: function(jsondata){
            if(jsondata.execution == "success"){
                   ret_value = jsondata.values;
            }
          }
         });
         return ret_values;
      },

    // Request
   getRequestAttribute: 
      function(aname){
         return this.getRequestAttributeInSpace('', aname);
      },   
      
   getRequestAttributeInSpace: 
      function(aspace, aname){
         return this.getAttributeInSpace("request", aspace, aname);
      },

   // Session
   getSessionAttribute: 
      function(aname){
         return this.getSessionAttributeInSpace('', aname);
      },

   getSessionAttributeInSpace: 
      function(aspace, aname){
         return this.getAttributeInSpace("session", aspace, aname);
      },

   // User
   getUserAttribute: 
      function(aname){
         return this.getUserAttributeInSpace('', aname);
      },

   getUserAttributeInSpace: 
      function(aspace, aname){
         return this.getAttributeInSpace("user", aspace, aname);
      },

   // Application
   getApplicationAttribute: 
      function(aname){
         return this.getApplicationAttributeInSpace('', aname);
      },

   getApplicationAttributeInSpace:
      function(aspace, aname){
         return this.getAttributeInSpace("application", aspace, aname);
      },

   // .........................   
   // appendAttribute FUNCTIONs
   // =========================
   appendAttribute: 
       function(ascope, aname, avalue){
           return this.appendAttributeInSpace(ascope, '', aname, avalue);
       },
      
   appendAttributeInSpace:
       function(ascope, aspace, aname, avalue){
          $.ajax({
            type: "POST",
            url: $.jSiter.getURL("core.appendAttribute.api"),
            async: false,
            data: {scope:ascope, space:aspace, name:aname, value:avalue},
            success: function(jsondata){
               data = jQuery.parseJSON(jsondata);
               if(data.execution == "success"){
                       return true;
               }
               else {
                  return false;
               }
            }
          });
      },

   // Request   
   appendRequestAttribute:
      function(aname, avalue){
         return this.setRequestAttributeInSpace('', aname, avalue);
      },

   appendRequestAttributeInSpace:
      function(aspace, aname, avalue){
         return this.appendAttribute("request", aspace, aname, avalue);
      },
    
   // Session   
   appendSessionAttribute:
      function(aname, avalue){
         return this.appendSessionAttributeInSpace('', aname, avalue);
         },
      
   appendSessionAttributeInSpace: 
      function(aspace, aname, avalue){
            return this.appendAttribute("session", aspace, aname, avalue);
         },

   // User
   appendUserAttribute:
       function(aname, avalue){
            return this.appendUserAttributeInSpace('', aname, avalue);
         }, 
      
    appendUserAttributeInSpace: 
       function(aspace, aname, avalue){
            return this.appendAttribute("user", aspace, aname, avalue);
         },

   // Application
   appendApplicationAttribute:
      function(aname, avalue){
            return this.appendApplicationAttributeInSpace('', aname, avalue);
         }, 

   appendApplicationAttributeInSpace: 
      function(aspace, aname, avalue){
            return this.appendAttribute("application", aspace, aname, avalue);
         },

   // ..................... 
   // isAttribute FUNCTIONs
   // =====================
   isAttribute:
      function(ascope, aname){
            if(getAttribute(ascope, aname)==undefined) return false;
            return true;
         },   

   isAttributeInSpace:
      function(ascope, aspace, aname){
            if(getAttributeInSpace(ascope, aspace, aname)==undefined) return false;
            return true;
         },

   isSessionAttribute:
      function(aname){
            if(getSessionAttribute(ascope, aname)==undefined) return false;
            return true;
         },   

   isSessionAttributeInSpace:
      function(aspace, aname){
            if(getSessionAttributeInSpace(aspace, aname)==undefined) return false;
            return true;
         },

   isRequestAttribute:
      function(aname){
            if(getRequestAttribute(ascope, aname)==undefined) return false;
            return true;
         },   
         
   isRequestAttributeInSpace:
      function(aspace, aname){
            if(getRequestAttributeInSpace(aspace, aname)==undefined) return false;
            return true;
         },

   isUserAttribute:
      function(aname){
            if(getUserAttribute(ascope, aname)==undefined) return false;
            return true;
         },   

   isUserAttributeInSpace:
      function(aspace, aname){
            if(getUserAttributeInSpace(aspace, aname)==undefined) return false;
            return true;
         },   
         

   isApplicationAttribute:
      function(aname){
            if(getApplicationAttribute(ascope, aname)==undefined) return false;
            return true;
         },

   isApplicationAttributeInSpace:
      function(aspace, aname){
            if(getApplicationAttributeInSpace(aspace, aname)==undefined) return false;
            return true;
         },   

   // Clipboard set/is in/get/remove/reset
   // ====================================
   setInClipboard: 
      function(aname, avalue){
         if(avalue==undefined){
            avalue = aname;
            aname = 'standard';
         }
         return this.setAttributeInSpace("session", "jsiter.clipboard", aname, avalue);
      },

   isInClipboard: 
      function(aname){
         return this.isAttributeInSpace("session", "jsiter.clipboard", aname);
      },

   getInClipboard: 
      function(aname, adef){
         if(aname==undefined){ 
            aname = 'standard';
         }
         return this.getAttributeInSpace("session", "jsiter.clipboard", aname, adef);
      },
      
   appendInClipboard: 
      function(aname, avalue){
         if(avalue==undefined){
            avalue = aname;
            aname = 'standard';
         }
         return this.appendAttributeInSpace("session", "jsiter.clipboard", aname, avalue);
      },

   removeInClipboard: 
      function(aname){
         return this.removeAttributeInSpace("session", "jsiter.clipboard", aname);
      },

   resetClipboard: 
      function(){
         return this.removeSpace("session", "jsiter.clipboard");
      },

   getClipboard:
      function(){
         clipboard = this.getAttributesInSpace("session", "jsiter.clipboard");
         msg = "";  
         for (var i in clipboard) msg = msg+clipboard[i];
         return msg;
      },

// =========================================================
// TIMER handling
// =========================================================
   timer: null,
   timerObject: null,

// =========================================================
// EDIT RESOURCES handling
// =========================================================
   quickEditEnabled: false,
   editorId: 1,

// =========================================================
// NAVIGATORS handling
// =========================================================
   navigators: new Array(),

   getNavigator: function(id) {
      this.navigators[id] = new jstrNavigator(id);
      return this.navigators[id];
   },

   pushInNavigator: function(obj){
      id = $(obj).closest('div.jstrNavigator').attr('id');
      nav = this.navigators[id];
      href = $(obj).attr('jstr-href');
      label = $(obj).attr('jstr-label');
      help = $(obj).attr('jstr-help');
      if(label==undefined) 
         label = $(obj).html();
      nav.push({label:label, link:href, help:help});
      $('#'+id+' div.body').jSiter('loadBlockCode', href, {help:help});
      nav.expand();
   },

   loadInNavigator: function(event){
      id = $(this).closest('div.jstrNavigator').attr('id');
      nav = $.jSiter.navigators[id];
      href = $(this).attr('jstr-href');
      help = $(this).attr('jstr-help');
      pop = $(this).attr('pop');

      $('#'+id+' div.body').jSiter('loadBlockCode', href, {help:help});
      for(var i=0; i<pop; i++) {
         nav.pop();
      }  
      nav.expand();
   },

// =========================================================
// STATUS BAR handling
// =========================================================
   statusBarNotify:
      function(msg){
         $('#statusBar').remove();
      },

   statusBarWait:
      function(){
         var div = $('<div id="statusBar"><img src="./jsiter/root/h_images/loading.gif" alt="loading" /></div>');
         $(div).css({position:'absolute',top:'10px',left:'10px'});
         $(div).appendTo('body');
      },

   statusBarSetAlertNotification:
      function(msg){
      },

   statusBarSetSuccessNotification:
      function(msg){
      },

   statusBarSetErrorNotification:
      function(msg){
      },

// =========================================================
// ANCHORS handling
// =========================================================
   clickOnAnchor:
      function () { 
         var href = $(this).attr('jstr-href');

         if(href.indexOf('http://') === 0){
            window.open(href)
            return;
         }

         target_type = $(this).attr('jstr-target-type');

         if(target_type=='close')
            return $.jSiter.loadBlockCodeInCloseTarget(this);
         else if(target_type=='navigator')
            return $.jSiter.pushInNavigator(this);
         else if(target_type=='popup') {
            title = $(this).attr('title');
            width = Number($(this).attr('jstr-width'));
            return $.jSiter.popup($(this).attr('jstr-href'), {title: title, width: width});
         }

         type   = $(this).attr('jstr-href-type');
         target = $(this).attr('jstr-target-selector');
         script = $(this).attr('jstr-script');
         help   = $(this).attr('jstr-help');
         pars   = $(this).attr('jstr-pars');
         cmid   = $(this).attr('jstr-container-mid');
         cpid   = $(this).attr('jstr-container-pid');
         cauth  = $(this).attr('jstr-container-author');

         if(href==undefined) 
            return;

         // Parameters setting
         if(pars==undefined) 
            pars = {};
         else
            pars = eval('('+pars+')');
         if(!jQuery.jSiter.isObject(pars))
            pars = {};

         // Load
         if(type=='page')
            $.jSiter.loadMaster(href); 
         else if((type=='bc'|| type=='blockcode') && target!=undefined) {
            $(target).jSiter('loadBlockCode', href, {wrap:true, help:help});
         }
         else if(type=='modlet' || type=='modtag') {
            splitted = href.split(':');
            $.extend(pars, {type:'module', mid:splitted[0], code:splitted[1], wrap:true, help:help, cmid:cmid, cpid:cpid, cauth:cauth});
            $(target).jSiter('loadTag', pars);
         }
         else if(type=='resource' || type=='restag') {
            resource = $(this).attr('jstr-resource');
            mode = $(this).attr('jstr-href-mode');
            $.extend(pars, {type:'resource', resource:resource, mode:mode, href:href, wrap:true, help:help, cmid:cmid, cpid:cpid, cauth:cauth});
            $(target).jSiter('loadTag', pars);
         }
         else if(type=='core' || type=='coretag') {
            $.extend(pars, {type:'core', code:href, wrap:true, help:help, cmid:cmid, cpid:cpid, cauth:cauth});
            $(target).jSiter('loadTag', pars);
         }

         if(script!=undefined) 
            eval(script);
      },

   // .......................
   loadBlockCodeInCloseTarget: function(obj){
      href_mode = $(obj).attr('jstr-href-mode');
      href_type = $(obj).attr('jstr-href-type');
      href      = $(obj).attr('jstr-href');
      target    = $(obj).attr('jstr-target-selector');
      clazz     = $(obj).attr('jstr-target-class');
      title     = $(obj).attr('jstr-title');

      if(target!=undefined) {
          $target = $(target);
      }
      else {
          $target = $('div.closeTarget');
      }
      if($target==undefined) {
          alert('Target undefined');
          return;
      }

      if($target.attr('status')=='on') {
          $target.fadeOut('slow');
          $target.html('');
      }

      if(clazz==undefined) 
          clazz = ' class="jstrCloseAnchor"';
      else 
          clazz = ' class="jstrCloseAnchor '+clazz+'"';

      $body_element = $('<div class=\"body\"/>');

      if(href_type=='blockcode')
         $body_element.jSiter('loadBlockCode', href);
      else if(href_type=='resource') {
         var pars = {type:'resource', mode:href_mode, resource:$(obj).attr('jstr-resource'), href:href};

         $body_element.jSiter('loadTag', pars);
      }

      $wrapper_element = $('<div'+clazz+' />').jSiter('addCloseButton', title==undefined?'':title);
      $body_element.appendTo($wrapper_element);
      
      $target.hide().append($wrapper_element);
      //$target.find('div.body').jSiter('loadBlockCode', href);

      $target.fadeIn(300).attr('status','on');
   },

// =========================================================
// HELP handling
// =========================================================
   setHelp: // event handler
      function() {
         reference = $(this).attr('jstr-target-reference');
         if(reference==undefined || reference=='')
            reference = 'body';
         text = $(this).attr('jstr-text');

         $target = $(reference+' div.jstrHelpTarget');
         if($target==undefined)
            $target = $(reference+' div.helpTarget');

         if($target==undefined) {
            alert('Target help area not defined!');
            return;
         }   
        
         splitted = text.split(":", 2);
         if(splitted[0]=='text')
             $target.html(splitted[1]).fadeIn('slow');
         else 
             $target.jSiter('loadBlockCode', splitted[1]).fadeIn('slow');
      },

   loadHelp: 
      function(pars) { 
         if(pars!=undefined && !$.jSiter.isObject(pars))
            return;

         parameters = {reference:'body', text:'text:empty help'};
         $.extend(parameters, pars);

         $target = $(parameters.reference).find('*.jstrHelpTarget');
         splitted = parameters.text.split(":", 2);
         if(splitted[0]=='text')
            $target.html(splitted[1]).fadeIn('slow');
         else 
            $target.jSiter('loadBlockCode', splitted[1]).fadeIn('slow');
      },

// =========================================================
// ESCAPE/UNESCAPE HTML
// =========================================================
   unescapeHTML:   
      function(html) {
         return $("<div />").html(html).text();
      },

   escapeHTML:
      function escapeHTML(html) {
         return $("<div />").text(html).html();
      },

// =========================================================
// TOOLBAR TEXTAREA EDITING
// =========================================================
   toolbarTextareaEditCommand:   
      function(textarea, command) {

         if(command=='bold'){
            var text = this._tbec_getText(textarea);
            tadd = "<strong>" + text + "</strong>";
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='italicize'){
            var text = this._tbec_getText(textarea);
            tadd = '<em>' + text + '</em>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='underline'){
            var text = this._tbec_getText(textarea);
            tadd = '<u>' + text + '</u>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='paragraph'){
            var text = this._tbec_getText(textarea);
            tadd = '<p>' + text + '</p>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='ul'){
            var text = this._tbec_getText(textarea);
            tadd = '<ul>' + text + '</ul>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='li'){
            var text = this._tbec_getText(textarea);
            tadd = '<li>' + text + '</li>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='span'){
            var text = this._tbec_getText(textarea);
            tadd = '<span>' + text + '</span>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='div'){
            var text = this._tbec_getText(textarea);
            tadd = '<div>' + text + '</div>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='left'){
            var text = this._tbec_getText(textarea);
            tadd = '<div class="jstrAlignLeft">' + text + '</div>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='center'){
            var text = this._tbec_getText(textarea);
            tadd = '<div class="jstrAlignCenter">' + text + '</div>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='right'){
            var text = this._tbec_getText(textarea);
            tadd = '<div class="jstrAlignRight">' + text + '</div>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='justify'){
            var text = this._tbec_getText(textarea);
            tadd = '<div class="jstrAlignJustify">' + text + '</div>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='hr'){
            var text = this._tbec_getText(textarea);
            tadd = text + '<hr />';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='link'){
            var text = this._tbec_getText(textarea);
            tadd = '<a href="">' + text + '</a>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='jstrlink'){
            var text = this._tbec_getText(textarea);
            tadd = '<jstr:a href="">' + text + '</jstr:a>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='blockcode'){
            var text = this._tbec_getText(textarea);
            tadd = '<jstr:bc src="' + text + '"/>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='image'){
            var text = this._tbec_getText(textarea);
            tadd = '<jstr:img src="' + text + '"/>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='file'){
            var text = this._tbec_getText(textarea);
            tadd = '<jstr:file src="' + text + '"/>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='menu'){
            var text = this._tbec_getText(textarea);
            tadd = '<jstr:menu src="' + text + '"/>';
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='getclipboard'){
            tadd = this.getInClipboard();
            this._tbec_addText(tadd, textarea);
         }
         else if(command=='setclipboard'){
            var text = this._tbec_getText(textarea);
            tadd = this.setInClipboard(text);
         }
         else if(command=='appendclipboard'){
            var text = this._tbec_getText(textarea);
            tadd = this.appendInClipboard(text);
         }
      },

   _tbec_getText:
      function(tarea) {
         if(tarea == null) return "";
         if(tarea.type != "textarea") return "";
         if (tarea.createTextRange && tarea.caretPos) {
            return tarea.caretPos.text;
         } else if (typeof tarea.selectionStart != 'undefined'){
            return tarea.value.substr(tarea.selectionStart,tarea.selectionEnd-tarea.selectionStart);
         }
         return '';
      },

   _tbec_addText:
   function(text, tarea) {
      var crtScrollTop;
      var crtScrollLeft;
      try {
        if (typeof tarea.scrollTop != 'undefined') {
            crtScrollTop = tarea.scrollTop;
            crtScrollLeft = tarea.scrollLeft;
        }
      } catch (e) {};

      if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
        start = tarea.selectionStart;
        end = tarea.selectionEnd;
        tarea.value = tarea.value.substr(0,tarea.selectionStart)
        + text+ tarea.value.substr(tarea.selectionEnd);
        tarea.focus();
        tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
        tarea.selectionEnd = start + text.length;
      } else {
        if (tarea.createTextRange && tarea.caretPos) {
            var caretPos = tarea.caretPos;
            caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
        }
        else {
            tarea.value += text;
        }
        tarea.focus(caretPos);
      };
      try {
        var tarea = document.PostTopic.Message;
        if (typeof tarea.scrollTop != 'undefined') {
            tarea.scrollTop = crtScrollTop;
            tarea.scrollLeft = crtScrollLeft;
        }
      } catch (e) {}; 
   },

   tbec_storeCaret:
   function(ftext) {
      if (ftext.createTextRange) {
         ftext.caretPos = document.selection.createRange().duplicate();
      }
   },

// =========================================================
// PAGE handling
// =========================================================
   loadMaster: 
      function (master){
         window.location.href = $.jSiter.getURL(master);
      },

// =========================================================
// API handling
// =========================================================
   executeAPI:
      function(api, parameters, callback) {
         url = $.jSiter.getURL(api);
         retdata = null;
           
         // handling parameters
         if(parameters!=undefined) {
            if(this.isFunction(parameters)) 
               callback = parameters;
            else if(!this.isObject(parameters)) 
               parameters = {};
         }
         else 
            parameters = {};
         
         if(callback == undefined)
            callback = function(data){
               retdata = data;
            };

         $.ajax({
             type    : "POST",
             url     : url,
             async   : false,
             dataType: 'json', 
             data    : parameters,
             beforeSend : function (thisXHR) { 
                $.jSiter.statusBarWait();
             }, 
             complete : function () { 
                $.jSiter.statusBarNotify();
             }, 
             success : callback,
             error   : function(error){
                alert(error);
             }
         });
         return retdata;
      },

// =========================================================
// API AND RELOAD handling
// =========================================================
   executeAPIAndReload:
      function(obj, api, parameters, callback) {
         retdata = this.executeAPI(api, parameters, callback);
         $(obj).jSiter('superReload');

         return retdata;
      },

// =========================================================
// POPUP handling - depends: jquery-ui-1.8.1.custom.min.js
// =========================================================
   popup: function(bcsrc, parameters) {
      url = $.jSiter.getURL("core.expandBlockcodeTag.api");
         
      pars = {
         width: 500,
         bcsrc: bcsrc,   
         autoOpen: false,
         modal: false,
         'jstr:newtarget': true,
         'jstr:popup' :true
      };
      jQuery.extend(pars, parameters);
         
      $.ajax({
         type: 'POST',
         url: url,
         async: false,
         data: pars,
         dataType: 'json',
         success: function(retjsonobj){
            if(retjsonobj.execution == 'success'){
               $div = $('<div></div>');
               $div.jSiter('injectCode', retjsonobj);
               var $dialog = $div.dialog(pars).dialog('open');
               $div.jSiter('codeInitialization');
            }   
         }
      });
   },

// =========================================================
// QUICK-EDIT handling
// =========================================================
   quickEdit: function(event) {
         if(event.which!=3)
            return;

         $(this).addClass('jstrInEdit');
            
         event.stopPropagation();
         counter = 1;
         editor_id = $(this).attr('jstr-reload-id');
         if(editor_id==undefined) { 
            editor_id = $.jSiter.editorId += 1;
            $(this).attr('jstr-reload-id',''+$.jSiter.editorId);
         }
         user_editable = $(this).hasClass('jstrUserEditable');
         inner_text = '<li'+(user_editable?' class=\"jstrUserEditable\"':' class=\"jstrUserNotEditable\"')+' jstr-reload-id-target=\"'+editor_id+'\">'+$(this).attr('jstr-editable-src')+'</li>';
         
         $(this).parents('*.jstrEditable').each(function(index) {
            edit = $(this).attr('jstr-editable-src');
            user_editable = $(this).hasClass('jstrUserEditable');
            if(edit!=undefined) {
                  counter += 1;
                  editor_id = $(this).attr('jstr-reload-id');
                  if(editor_id==undefined) { 
                     editor_id = $.jSiter.editorId += 1;
                     $(this).attr('jstr-reload-id',''+$.jSiter.editorId);
                  }
                  inner_text += '<li'+(user_editable?' class=\"jstrUserEditable\"':' class=\"jstrUserNotEditable\"')+' jstr-reload-id-target=\"'+editor_id+'\">'+edit+'</li>';
            }
         });

         if(counter > 0)
            inner_text = '<ul>'+inner_text+'</ul>';

         $edit_menu = $('<div class=\"jstrQuickEditList\">'+inner_text+'</div>')
                      .css({'position':'absolute', 'top': event.pageY-2, 'left':event.pageX-2})
                      .bind('mouseleave', function() {$(this).remove();});
         $edit_menu.find('li.jstrUserEditable')
                      .bind('click', $.jSiter.loadQuickEditor );

         $('body').prepend($edit_menu);

         return false;
      },

   loadQuickEditor: function() {  // EVENT handler
         var reload_id = $(this).attr('jstr-reload-id-target');
         var $obj = $('*[jstr-reload-id='+reload_id+']');
         var src = $obj.attr('jstr-editable-src');
         var src_splitted = src.split(";",3);
         var resource_name = src_splitted[0];
         
         parameters = {
            'jstr:namespace':$obj.attr('jstr-namespace'),
            reload_id       :reload_id,
            src             :$obj.attr('jstr-editable-src'),
            cmid            :$obj.attr('jstr-container-mid'),
            cpid            :$obj.attr('jstr-container-pid'),
            cauth           :$obj.attr('jstr-container-author')
         };
         var retjsonobj = $.jSiter.executeAPI('resource.quickEditResource.api', parameters);
         if(retjsonobj.execution=='success') {
            dialog_pars = {
               width : retjsonobj.width,
               height: retjsonobj.height,
               modal : false,
               title : resource_name,
               close : function(ev, ui) { $(this).remove(); }
            };

            $('<div></div>').jSiter('injectCode', retjsonobj).dialog(dialog_pars).dialog('open');
            if(retjsonobj.script!=undefined && retjsonobj.script!='')
               eval(retjsonobj.script);
         }
         else 
            alert(retjsonobj.message);
      },

   quickEditStatus: function(newStatus) {
         if(newStatus==undefined) {
            newStatus = this.getSessionAttribute('quickedit')=='true';
         } 
         if(newStatus) {
            quickEditEnabled = true;
            $('body').find('*.jstrEditable').die('contextmenu',$.jSiter.quickEdit)
                                            .live('contextmenu',$.jSiter.quickEdit);
         }
         else {
            quickEditEnabled = false;
            $('body').find('*.jstrEditable').die('contextmenu',$.jSiter.quickEdit);
         }
      }



};


// .............................................
// .............................................
// jSiter PLUG-IN
// =============================================

// METHODS
// =======
var methods = {
    // init
    // ====
    init: function( ) { 
       $(this).jSiter('codeInitialization');
       $(this).jSiter('eventInitialization');
       $.jSiter.quickEditStatus();
    },

    // codeInitialization
    // ==================
    codeInitialization: function( ) {  return this.each(function() {
           $(this).find('*.jstrClose').jSiter('closeCommand');
           $(this).find('*.jstrOpenClose').jSiter('openCloseCommand');
           $(this).find('textarea.jstrEditTextarea').jSiter('editTextarea');
           $(this).find('div.jstrMenuTabs').jSiter('tabs');
           $(this).find('input.jstrFileUpload').jSiter('fileUploadStyle');

           $(this).find('option[selected=selected]').attr('selected', 'selected');
    });
    },

    // eventInitialization
    // ===================
    eventInitialization: function( ) {  return this.each(function() {
           // ANCHOR
           $(this).find('*.jstrAnchor, *.anchor')
                  .die('click.jSiter')
                  .live('click.jSiter',function(e) {e.preventDefault();})
                  .live('click.jSiter',$.jSiter.clickOnAnchor);

           // NAVIGATOR 
           $(this).find('a.jstrNavigator, a.navigator')
                  .die('click.jSiter')
                  .live('click.jSiter',$.jSiter.loadInNavigator);

           // HELP
           $(this).find('a.jstrHelpLink, *.jstrHelp')
                  .die('click.jSiter')
                  .live('click.jSiter',$.jSiter.setHelp);

           // MENU
           $(this).find('div.jstrGenericMenu div.jstrMenuItem')
                  .live('mouseenter',function(event){
                      if($(this).next('div.jstrMenu').length>0) { 
                         $(this).next('div.jstrMenu').fadeIn("fast"); 
                         $(this).next('div.jstrMenu').bind('mouseenter',function(event){
                            $(this).attr('status', 'on'); 
                         });
                         $(this).next('div.jstrMenu').bind('mouseleave',function(event){
                            $(this).attr('status', 'off');
                            $(this).fadeOut("fast");
                         });
                      }
                   })
                   .live('mouseleave',function(event){
                       if($(this).next('div.jstrMenu').length>0) { 
                          (function($menu) 
                          {
                             setTimeout(function() {
                                 if($menu.attr('status')=='off') $menu.fadeOut("fast");
                             }, 500);
                          }
                          )($(this).next('div.jstrMenu'));
                       }
                   });

    });
    },

    // ============================
    // 'onDemandExecution' FUNCTION
    // ............................
    onDemandExecution: function() { return this.each(function() {
       eval($(this).attr('ondemand-script'));
    });
    },

    // =====================
    // 'injectCode' FUNCTION
    // .....................
    injectCode: function(jsonpars, action) { return this.each(function() {
         if(!$.jSiter.isObject(jsonpars))
            return;

         // Initialize replace function
         if($.jSiter.isNone(action)) {
             action = 'html';
         }
         else if($.jSiter.isBoolean(action)) {
             action = action?'replaceWith':'html';
         }

         if(!$.jSiter.isString(action))
            return;

         // loading external CSS
         if(!$.jSiter.isNone(jsonpars.external_css))
            for(k=0;k<jsonpars.external_css.length;k++) {
               $('<link rel="stylesheet" type="text/css" href="'+jsonpars.external_css[k]+'" >').appendTo("head");
            }

         // loading external JS
         if(!$.jSiter.isNone(jsonpars.external_js))
            for(k=0;k<jsonpars.external_js.length;k++) {
               $.getScript(jsonpars.external_js[k]);
            }

         // replace/insert HTML
         if(!$.jSiter.isNone(jsonpars.text)) {
            if(action=='html')
               $(this).html(jsonpars.text);
            else if(action=='replaceWith') {
               $(this).replaceWith(jsonpars.text);
               $('body').jSiter('codeInitialization'); // provvisorio
            } 
            else if(action=='after') {
               $(this).after(jsonpars.text);
               $('body').jSiter('codeInitialization'); // provvisorio
            }
            // initialization of injected code  
            $(this).jSiter('codeInitialization');
         }

         // load HELP
         if(!$.jSiter.isNone(jsonpars.help_text)) {
            $.jSiter.loadHelp({reference:jsonpars.help_reference, text:jsonpars.help_text});
         }

         // executing script
         if(!$.jSiter.isNone(jsonpars.script))
            eval(jsonpars.script);
    });
    },

    // ========================
    // 'loadBlockCode' FUNCTION
    // ........................
    loadBlockCode: function(bcsrc, parameters) { return this.each(function() {
       url = $.jSiter.getURL("core.expandBlockcodeTag.api");

       if(typeof(bcsrc)=='object') 
          parameters = bcsrc;

       if (bcsrc == undefined || typeof(bcsrc)=='object') {
          bcsrc = $(this).attr('jstr:bcsrc');
          if(bcsrc==undefined) return;
       }

       pars = { 
          bcsrc: bcsrc,
          namespace: $(this).attr('jstr:namespace') 
       };

       if(typeof(parameters)=='object') {
          $.extend(pars, parameters);
       }

       local_this = $(this);
       $.jSiter.executeAPI('core.expandBlockcodeTag.api', pars, function(retjsonobj){
             if(retjsonobj.execution == "success"){
                $(local_this).jSiter('injectCode', retjsonobj);
             }   
          });
    });
    },

    // ==================
    // 'loadTag' FUNCTION
    // ..................
    loadTag: function(parameters) { return this.each(function() {
       if(parameters==undefined) 
          return;
       if(!$.jSiter.isString(parameters.type))
          return;
       else if(parameters.type!='resource' && parameters.type!='module' && parameters.type!='core')
          return;

       type = parameters.type.charAt(0).toUpperCase() + parameters.type.slice(1);

       if (!('jstr:namespace' in parameters)) {
          namespace = $(this).attr('jstr:namespace');
          if(namespace!=undefined)
             $.extend(parameters, {'jstr:namespace':namespace});
       }

       local_this = $(this);
       $.jSiter.executeAPI('core.expand'+type+'Tag.api', parameters, function(retjsonobj){
             if(retjsonobj.execution=='success') {
                $(local_this).jSiter('injectCode', retjsonobj);
             }
          });
    });
    },

    // ======================
    // 'reload' FUNCTION
    // ......................
    reload: function(parameters) { return this.each(function() {
       if($(this).attr('jstr-reload')!=undefined) {

          var reload = $(this).attr('jstr-reload');
             if("api:"==reload.substring(0, 4)) {
                var api = reload.substring(4);
                var pars = {
                   'jstr:namespace':$(this).attr('jstr-namespace'),
                   wrap            :false
                };
                var tag_pars = eval('('+$(this).attr('jstr-parameters')+')');
                $.extend(pars, tag_pars);
                $.extend(pars, parameters);
                var retdata = $.jSiter.executeAPI(api, pars);
                $(this).jSiter('injectCode', retdata, false);
             }
             if("blockcode:"==reload.substring(0, 10)) {
                var src = reload.substring(10);
                var p = src.split(";",2);
                var pars = {
                   'jstr:namespace':''+$(this).attr('jstr-namespace'),
                   bcsrc           :p[0],
                   cmid            :$(this).attr('jstr-container-mid'),
                   cpid            :$(this).attr('jstr-container-pid'),
                   cauth           :$(this).attr('jstr-container-author'),
                   wrap            :false
                };
                jQuery.extend(pars, parameters);

                var retdata = jQuery.jSiter.executeAPI("core.expandBlockcodeTag.api", pars);
                $(this).jSiter('injectCode', retdata, false);
             }
             if("module:"==reload.substring(0, 7)) {
                var module = reload.substring(7);
                var p = module.split(";",2);
                var modpars = p[0].split(",");
                var pars = {
                   'jstr:namespace':$(this).attr('jstr-namespace'),
                   mid             :modpars[0],
                   code            :modpars[1],
                   cmid            :$(this).attr('jstr-container-mid'),
                   cpid            :$(this).attr('jstr-container-pid'),
                   cauth           :$(this).attr('jstr-container-author'),
                   wrap            :false
                };
                jQuery.extend(pars, parameters);

                var retdata = jQuery.jSiter.executeAPI("core.expandModuleTag.api", pars);
                $(this).jSiter('injectCode', retdata, false);
             }
             if("resource:"==reload.substring(0, 9)) {
                var resource = reload.substring(9);
                var p = resource.split(";",2);
                var respars = p[0].split(",", 3);
                var pars = {
                   'jstr:namespace':$(this).attr('jstr-namespace'),
                   resource        :respars[0],
                   mode            :respars[1],
                   href            :respars[2],
                   reload_pars     :$(this).attr('jstr-reload-pars'),
                   reload_id       :$(this).attr('jstr-reload-id'),
                   cmid            :$(this).attr('jstr-container-mid'),
                   cpid            :$(this).attr('jstr-container-pid'),
                   cauth           :$(this).attr('jstr-container-author'),
                   wrap            :false,
                   inline          :$(this).attr('jstr-inline')
                };
                jQuery.extend(pars, parameters);

                var retdata = jQuery.jSiter.executeAPI("core.expandResourceTag.api", pars);
                $(this).jSiter('injectCode', retdata, pars.mode!='code');
             }
             if("core:"==reload.substring(0, 5)) {
                var code = reload.substring(5);
                var pars = {
                   'jstr:namespace':$(this).attr('jstr-namespace'),
                   code            :code,
                   wrap            :false
                };
                // Aggiunta degli attributi del tag  
                var attrs = $(this)[0].attributes;
                for(var i=0;i<attrs.length;i++) {
                   pars[attrs[i].nodeName] = attrs[i].nodeValue;
                }

                jQuery.extend(pars, parameters);
                var retdata = jQuery.jSiter.executeAPI("core.expandCoreTag.api", pars);
                $(this).jSiter('injectCode', retdata, false);
             }

        }
    });
    },

    // ======================
    // 'superReload' FUNCTION
    // ......................
    superReload: function(parameters) { return this.each(function() {
        $(this).parents('div').each(function(index) {
            if($(this).attr('jstr-reload')!=undefined) {
                $(this).jSiter('reload', parameters);
                return false;
            }
        });
    });
    },

    // ===============
    // 'menu' FUNCTION
    // ...............
    _menu: function(){ return this.each(function(){

        $(this).find('div.jstrMenuItem').bind('mouseenter',function(event){
              if($(this).next('div.jstrMenu').length>0) { 
                 $(this).next('div.jstrMenu').fadeIn("fast"); 
                 $(this).next('div.jstrMenu').bind('mouseenter',function(event){
                    $(this).attr('status', 'on'); 
                 });
                 $(this).next('div.jstrMenu').bind('mouseleave',function(event){
                    $(this).attr('status', 'off');
                    $(this).fadeOut("fast");
                 });
              }
           })
           .bind('mouseleave',function(event){
              if($(this).next('div.jstrMenu').length>0) { 
                 (function($menu) {
                    setTimeout(function() {
                       if($menu.attr('status')=='off') $menu.fadeOut("fast");
                    }, 500);
                 })($(this).next('div.jstrMenu'));
              }
           });
    });
    },

    // ===============
    // 'tabs' FUNCTION
    // ...............
    tabs: function(){ return this.each(function(){
             rid = $(this).attr('jstr-rid');
             namespace = $(this).attr('jstr-namespace');

             $(this).tabs({
		fxFade : true,
		fxSpeed: 'fast',
		onClick: function(anchor) {},
		onHide : function(anchor) {},

		onShow : function(anchor) {
		    anchor = anchor + '';
		    index  = anchor.indexOf('#', 0);
		    anchor = anchor.substring(index);
		    tnum   = $('div.jstrMenuTabs a[href*='+anchor+']').attr('tnum');
		    $.jSiter.setSessionAttributeInSpace(namespace, 'activeTab_r'+rid, tnum);
		}
             });   
    });
    },


    // **********************
    // ********************
    // ******************
    // new functions here
    // ******************
    // ********************
    // **********************

    // alert
    // =====
    alert: function( ) { return this.each(function() {
       alert('hello world!');
    });
    },

    // alertMessage
    // ============
    alertMessage: function( message ) { return this.each(function() {
       alert(message);
    });
    },

    // addCloseButton
    // ==============
    addCloseButton: function(title) { return this.each(function() {
       $div = $('<div class="jstrCloseDiv"><div><img src="./jsiter/root/h_images/close_icon.png" alt="close_icon" jstr:src=image:close_icon /></div><div>'+title+'</div></div>');
       $div.bind('click', function() {
          $(this).parent().fadeOut(300, function() {
             $(this).remove();
          });
       });
       $(this).prepend($div).css('display','block');   
    });
    },

    // closeCommand
    // ============
    closeCommand: function() { return this.each(function() {
       $command = $('<div class="closeCommand"><img src="./jsiter/root/h_images/close_icon.png" /></div>');
       $command.bind('click',function(){$(this).closest('div.jstrClose').fadeOut();});
       $(this).wrapInner('<div class="body" />').prepend($command);   
    });
    },

    // openCloseCommand
    // ================
    openCloseCommand: function() { return this.each(function() {
          if($(this).attr('jstr-expanded')!=undefined) return;

          status = $(this).attr('jstr-status');
          $(this).wrapInner('<div class="body'+((status=='close')?' jstrDisplayNone':'')+'" />');   

          $element = 
             $('<div class="title jstrPointer" />')
             .data('status', status)
             .click(function() {
                if($(this).data('status')=='close') {
                   $(this).next('div.body').removeClass('jstrDisplayNone');
                   $(this).find('div.text').html($(this).closest('div.jstrOpenClose').attr('jstr-close-title'));
                   $(this).data('status','open');
                   $(this).find('div.image').removeClass('close').addClass('open');
                }   
                else {
                   $(this).next('div.body').addClass('jstrDisplayNone');
                   $(this).find('div.text').html($(this).closest('div.jstrOpenClose').attr('jstr-open-title'));
                   $(this).data('status','close');
                   $(this).find('div.image').removeClass('open').addClass('close');
                }
             })
             .html('<div class="image '+status+'" /><div class="text">'+(status=='close'?$(this).attr('jstr-open-title'):$(this).attr('jstr-close-title'))+'</div>');
          $(this).prepend($element);
          $(this).attr('jstr-expanded', 'true');
          $(this).addClass('jstrOpenClose');
    });
    },

    // editTextarea
    // ============
    editTextarea: function() { return this.each(function() {
       $textarea = $(this); 
       
       $commands = $('<div class="editCommands"></div>');
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_bold.gif" jstr-action="bold" />');
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_italicize.gif" jstr-action="italicize" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_link.gif" jstr-action="link" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_div.gif" jstr-action="div" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_span.gif" jstr-action="span" />');
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_left.gif" jstr-action="left" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_center.gif" jstr-action="center" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_right.gif" jstr-action="right" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_justify.gif" jstr-action="justify" />');
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_paragraph.gif" jstr-action="paragraph" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_ul.gif" jstr-action="ul" />');
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_li.gif" jstr-action="li" />'); 

       $commands.append('<img src="./jsiter/root/h_images/icon_editor_separator.png" />'); 

       $commands.append('<img src="./jsiter/root/h_images/icon_editor_jstrlink.gif" jstr-action="jstrlink" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_blockcode.gif" jstr-action="blockcode" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_image.gif" jstr-action="image" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_file.gif" jstr-action="file" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_menu.gif" jstr-action="menu" />'); 

       $commands.append('<img src="./jsiter/root/h_images/icon_editor_separator.png" />'); 

       $commands.append('<img src="./jsiter/root/h_images/icon_editor_get_clipboard.gif" title="get from clipboard" jstr-action="getclipboard" />'); 
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_set_clipboard.gif" title="clear and set in clipboard" jstr-action="setclipboard" />');
       $commands.append('<img src="./jsiter/root/h_images/icon_editor_append_clipboard.gif" title="append in clipboard" jstr-action="appendclipboard" />'); 

       $($commands).find('img').bind('click.jsiter',function(){  jQuery.jSiter.toolbarTextareaEditCommand($textarea.context, $(this).attr('jstr-action'));   });

       $(this).wrap('<div class="jstrEditTextarea" />');   
       $commands.insertBefore($(this));
    });
    },

    // =======================
    // 'keyupDelayed' FUNCTION
    // .......................
    keyupDelayed: function(func, delay) { return this.each(function() {
       $(this).bind('keyup', function(event) {
          if(jQuery.jSiter.timer!=null) 
             clearTimeout(jQuery.jSiter.timer);
          jQuery.jSiter.timerObject = this;
          jQuery.jSiter.timer = setTimeout(function(){func(jQuery.jSiter.timerObject);}, delay);
       });
    });
    },

    // ==========================
    // 'fileUploadStyle' FUNCTION
    // ..........................
    fileUploadStyle: function(title) { return this.each(function() {
       $input = $(this);
       if($input.attr('setup')=='on') return;

       $input.attr('setup','on');

       // Bind change event
       $(this).bind('change',function(){
          $(this).closest('div.jstrFileUploadArea').find('div.file').html($(this).val());
       });

       $filedescr = $('<div class="file"></div>');
       $button = $('<div class="button"></div>');
       $loader = $('<div class="loader"></div>').prepend($filedescr).prepend($button); 
       $(this).wrap('<div class="jstrFileUploadArea"></div>').parent().prepend($loader);   
    });
    }

}; // END OF METHODS



// PLUGIN settings
// ===============
$.fn.jSiter = function( method ) {
    
   // Method calling logic
   if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
   } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
   } else {
      $.error( 'Method ' +  method + ' does not exist on <jQuery.jSiter> plugin' );
   }    
  
};

$(document).ready(function(){
   $(document).jSiter();
});


// ***
})( jQuery );

