
	jQuery.init = function(options){
		$("#"+options.textEditorId).hide();
		Frame = document.createElement('iframe');
		$(Frame).attr('id','VshareEditor');
	        
		if (Frame.addEventListener){
			Frame.addEventListener("load",function(e){this.contentWindow.document.designMode = "on";}, false);
	    } else if (Frame.attachEvent){
	    	Frame.attachEvent("load", function(e){this.contentWindow.document.designMode = "on";});
	    }
	        
	    jQuery.fn.editorMenu = function(){
	    	var htmlTags = {
	    			'B':'bold',
		        	'U':'underline',
		        	'I':'italic',
		        	'A':'a'
		    };
		    var tags = '';

		    $.each(htmlTags, function(key, value) { 
		    	tags += "<a rel='xxx' href='javascript:void(0);' id='"+ value +"'><img src='"+baseurl+"/templates/images/"+value+".png' border='0' alt='"+ key +"'/></a>&nbsp;";  
		    });

		    var head = $('<div id="editorMenu"></div>')
		    $('body #'+options.appendId).append(head);
		    $('body #editorMenu').append(tags);
		    $('body #editorMenu').css({'width':options.width,'padding':'1px'});
	    }
 
	    $('body #'+options.appendId).editorMenu();
	    $('body #'+options.appendId).append(Frame);
        $("#VshareEditor").css({'width':options.width,'height':options.height});

        jQuery.execCommand = function(x,y){
        	document.getElementById('VshareEditor').contentWindow.document.execCommand("useCSS", false, !(false)); 
            document.getElementById('VshareEditor').contentDocument.execCommand(x, false, y);
            $.fetch();
            document.getElementById('VshareEditor').focus(); 
               	
        };

        jQuery.fetch = function(){
        	var  content = document.getElementById('VshareEditor').contentWindow.document.body.innerHTML;
            $("#" + options.textEditorId).html(content);
        }
	        
	    $('[rel=xxx]').each(function() {
	    	$(this).click(function(){
	    		var id = $(this).attr('id');

                if (id == 'a') {
                	var href = prompt("Enter the URL", "http://");
                    if (href != null){ 
                    	$.execCommand('createlink',href,href);
                    }
                }
                else {
                	$(this).toggleClass('editorMenuActive');
                    $.execCommand(id);
                }
                    
            });
        });
	    
	}

