var dsRTE_insertImage=function()
{  this.ExecuteCommand=function(a,b,c){
    c.slideToggle();return true};
   this.PrepareCommand=function(b,c,d,f){
       var g=c;     //console.debug(c); /*c = image */
       //console.debug(d); /* */
       //console.debug(f); /*f = cmd-dstre-image */
       $('#dsrte-image-url-ok').click(function(){
               b.frame.focus();
               d.slideUp();
              var object_content ='<img src="'+ $("#dsrte-image-url").val() +'" _moz_resizing="true"/>';
               b.doc.execCommand('inserthtml',false,object_content);//
               $("#dsrte-image-url").val('');
               });
       $('#'+b.iframe.id+'-'+c+'-ok').click(function(){
               b.frame.focus();
               $.ajaxFileUpload( 
                   {  url:f.attr('path'),
                      secureuri:false,
                      fileElementId:b.iframe.id+'-'+g+'-file',
                      dataType:'json',
                      success:function(a,s){
                         if(a.error){
                           alert(a.error)
                         }
                         else
                         {
                           b.frame.focus();
                           $('#'+c).val('');
                           d.slideUp();
                           //imgTag = a.path+'/'+encodeURIComponent(a.file) + '"' + " width=200 height=100  ";
                           b.doc.execCommand('insertimage',false,a.path+'/'+encodeURIComponent(a.file))
                            
                          }
                      },
                      error:function(a,s,e){  alert(e+': '+a.responseText)  }
                   })
       });
       return true
   }

};

editor.RegisterPlugin(new dsRTE_insertImage(),'image');
