//jquery-editor.js
$(function() {

    $.fn.editor = function() {

       $(this).each(function() {

			var id = $(this).attr('id');
			
			$(this).attr('contenteditable','true');			
			
			$(this).before('<div id="'+id+'Toolbox" class="toolbox"><a id="bold" href="#" style="font-weight:bold;">B</a><a id="italic" href="#" style="font-style:italic;">I</a><a id="underline" href="#" style="text-decoration:underline;">U</a><a id="strikethrough" href="#" style="text-decoration:line-through;">abc</a><a id="insertorderedlist" href="#">1.-</a><a id="insertunorderedlist" href="#">&bull;-</a><a id="createlink" href="#">&lt;link&gt;</a><a id="insertimage" href="#">&lt;img&gt;</a><a id="removeformat" href="#">&lt;clear&gt;</a><div class="clear"></div></div>');	

            $('#' + id + 'Toolbox a').live('click', function(e) {
                e.preventDefault();

                var command = $(this).attr('id');

                if (command == 'createlink' || command == 'insertimage') {
                    var url = prompt('Url адрес:', 'http://');
                    document.execCommand(command, false, url);
                }
                else {
                    document.execCommand(command, false, true);
                }
            });
        });
    };
});
